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 collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, format = nil, counter = nil) ⇒ Field

Returns a new instance of Field.

Parameters:

  • name

    unique (among all fields in a struct) name for the field

  • format (defaults to: nil)

    number of bytes, a class, or nil

  • counter (Field) (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

#counteeObject

Returns the value of attribute countee.



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

def countee
  @countee
end

#counterObject

Returns the value of attribute counter.



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

def counter
  @counter
end

#formatObject (readonly)

Returns the value of attribute format.



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

def format
  @format
end

#nameObject (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

.factory(format) ⇒ Object

Returns a Field class that best represents the given format.



184
185
186
187
188
189
190
191
# File 'lib/rumai/ixp/message.rb', line 184

def self.factory format
  case format
  when String then StringField
  when Class then ClassField
  when 8 then Integer8Field
  else Field
  end
end

Instance Method Details

#load_9p(stream, field_values) ⇒ Object

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



204
205
206
# File 'lib/rumai/ixp/message.rb', line 204

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

#to_9p(field_values) ⇒ Object

Transforms this object into a string of 9P2000 bytes.



196
197
198
# File 'lib/rumai/ixp/message.rb', line 196

def to_9p field_values
  value_to_9p field_values[@name]
end