Class: Rumai::IXP::Struct::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/rumai/ixp/message.rb

Overview

A field inside a Struct.

A field’s value is considered to be either:

  • array of format when counter && format.is_a? Class
  • raw byte string when counter && format.nil?

Direct Known Subclasses

ClassField, Integer8Field

Defined Under Namespace

Modules: CounteeField, CounterField

Instance Attribute Summary

Class Method Summary

Instance Method Summary

Constructor Details

- (Field) initialize(name, format = nil, counter = nil)

A new instance of Field

Parameters:

  • (among all fields in a struct) nameunique

    name for the field

  • format (defaults to: nil)

    number of bytes, a class, or nil

  • (Field) counter (defaults to: nil)

    field which counts the length of this field’s value



153
154
155
156
157
158
# File 'lib/rumai/ixp/message.rb', line 153

def initialize name, format = nil, counter = nil
  @name = name
  @format = format
  @countee = nil
  self.counter = counter
end

Instance Attribute Details

- (Object) countee

Returns the value of attribute countee



141
142
143
# File 'lib/rumai/ixp/message.rb', line 141

def countee
  @countee
end

- (Object) counter

Returns the value of attribute counter



141
142
143
# File 'lib/rumai/ixp/message.rb', line 141

def counter
  @counter
end

- (Object) format (readonly)

Returns the value of attribute format



141
142
143
# File 'lib/rumai/ixp/message.rb', line 141

def format
  @format
end

- (Object) name (readonly)

Returns the value of attribute name



141
142
143
# File 'lib/rumai/ixp/message.rb', line 141

def name
  @name
end

Class Method Details

+ (Object) factory(format)

Returns a Field class that best represents the given format.



184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/rumai/ixp/message.rb', line 184

def self.factory format
  if format == String
    StringField

  elsif format.is_a? Class
    ClassField

  elsif format == 8
    Integer8Field

  else
    Field
  end
end

Instance Method Details

- (Object) load_9p(stream, field_values)

Populates this object with information taken from the given 9P2000 byte stream.



210
211
212
# File 'lib/rumai/ixp/message.rb', line 210

def load_9p stream, field_values
  field_values[@name] = value_from_9p stream
end

- (Object) to_9p(field_values)

Transforms this object into a string of 9P2000 bytes.



202
203
204
# File 'lib/rumai/ixp/message.rb', line 202

def to_9p field_values
  value_to_9p field_values[@name]
end