Class: Rumai::IXP::Struct::Field
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
Defined Under Namespace
Modules: CounteeField, CounterField
Instance Attribute Summary collapse
-
#countee ⇒ Object
Returns the value of attribute countee.
-
#counter ⇒ Object
Returns the value of attribute counter.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.factory(format) ⇒ Object
Returns a Field class that best represents the given format.
Instance Method Summary collapse
-
#initialize(name, format = nil, counter = nil) ⇒ Field
constructor
- name
-
unique (among all fields in a struct) name for the field.
-
#load_9p(stream, field_values) ⇒ Object
Populates this object with information taken from the given 9P2000 byte stream.
-
#to_9p(field_values) ⇒ Object
Transforms this object into a string of 9P2000 bytes.
Constructor Details
#initialize(name, format = nil, counter = nil) ⇒ Field
- name
-
unique (among all fields in a struct) name for the field
- format
-
number of bytes, a class, or nil
- counter
-
field which counts the length of this field’s value
160 161 162 163 164 165 |
# File 'lib/rumai/ixp/message.rb', line 160 def initialize name, format = nil, counter = nil @name = name @format = format @countee = nil self.counter = counter end |
Instance Attribute Details
#countee ⇒ Object
Returns the value of attribute countee.
148 149 150 |
# File 'lib/rumai/ixp/message.rb', line 148 def countee @countee end |
#counter ⇒ Object
Returns the value of attribute counter.
148 149 150 |
# File 'lib/rumai/ixp/message.rb', line 148 def counter @counter end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
148 149 150 |
# File 'lib/rumai/ixp/message.rb', line 148 def format @format end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
148 149 150 |
# File 'lib/rumai/ixp/message.rb', line 148 def name @name end |
Class Method Details
.factory(format) ⇒ Object
Returns a Field class that best represents the given format.
191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/rumai/ixp/message.rb', line 191 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
#load_9p(stream, field_values) ⇒ Object
Populates this object with information taken from the given 9P2000 byte stream.
217 218 219 |
# File 'lib/rumai/ixp/message.rb', line 217 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.
209 210 211 |
# File 'lib/rumai/ixp/message.rb', line 209 def to_9p field_values value_to_9p field_values[@name] end |