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
A new instance of 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
Returns a new instance of Field.
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
#countee ⇒ Object
Returns the value of attribute countee.
141 142 143 |
# File 'lib/rumai/ixp/message.rb', line 141 def countee @countee end |
#counter ⇒ Object
Returns the value of attribute counter.
141 142 143 |
# File 'lib/rumai/ixp/message.rb', line 141 def counter @counter end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
141 142 143 |
# File 'lib/rumai/ixp/message.rb', line 141 def format @format end |
#name ⇒ Object (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 |