Class: Racket::Misc::VT
- Inherits:
-
Object
- Object
- Racket::Misc::VT
- Defined in:
- lib/racket/misc/vt.rb
Overview
arbitrarily sized values, followed by a “rest” field.
Instance Attribute Summary collapse
-
#rest ⇒ Object
everything else.
-
#types ⇒ Object
the array of types for this VT object.
-
#value ⇒ Object
the value for this VT object.
Instance Method Summary collapse
-
#decode(data) ⇒ Object
Given
data, return the value and an array of the types as dictated by this instance. -
#decode!(data) ⇒ Object
Given
data, set thevalueandtypesarray accordingly. -
#encode ⇒ Object
Return a string suitable for use elsewhere.
-
#initialize(*args) ⇒ VT
constructor
Create a new VT which consists of a null terminated string followed by some number of arbitrarily sized values, as specified by
args. - #to_s ⇒ Object
- #to_str ⇒ Object
Constructor Details
#initialize(*args) ⇒ VT
Create a new VT which consists of a null terminated string followed by some number of arbitrarily sized values, as specified by args
44 45 46 47 48 |
# File 'lib/racket/misc/vt.rb', line 44 def initialize(*args) @lengths = args @types = [] @value = "" end |
Instance Attribute Details
#rest ⇒ Object
everything else
39 40 41 |
# File 'lib/racket/misc/vt.rb', line 39 def rest @rest end |
#types ⇒ Object
the array of types for this VT object
37 38 39 |
# File 'lib/racket/misc/vt.rb', line 37 def types @types end |
#value ⇒ Object
the value for this VT object
35 36 37 |
# File 'lib/racket/misc/vt.rb', line 35 def value @value end |
Instance Method Details
#decode(data) ⇒ Object
Given data, return the value and an array of the types as dictated by this instance
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/racket/misc/vt.rb', line 52 def decode(data) null = data.index(0x00) value = data.unpack("a#{null}")[0] data = data.slice(null+1, data.length) n = 0 types = [] @lengths.each do |l| types[n] = data.unpack("#{punpack_string(l)}")[0] data = data.slice(l, data.length) n += 1 end [value, types, data] end |
#decode!(data) ⇒ Object
Given data, set the value and types array accordingly
70 71 72 |
# File 'lib/racket/misc/vt.rb', line 70 def decode!(data) @value, @types, @rest = self.decode(data) end |
#encode ⇒ Object
Return a string suitable for use elsewhere
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/racket/misc/vt.rb', line 75 def encode s = "#{@value}\000" n = 0 @lengths.each do |l| s << [@types[n]].pack("#{punpack_string(l)}") n += 1 end s end |
#to_s ⇒ Object
86 87 88 |
# File 'lib/racket/misc/vt.rb', line 86 def to_s encode end |
#to_str ⇒ Object
90 91 92 |
# File 'lib/racket/misc/vt.rb', line 90 def to_str encode end |