Class: Canoser::Str

Inherits:
Object
  • Object
show all
Defined in:
lib/canoser/field.rb

Class Method Summary collapse

Class Method Details

.decode(cursor) ⇒ Object



92
93
94
95
96
97
98
99
# File 'lib/canoser/field.rb', line 92

def self.decode(cursor)
  str = ""
  len = Uint32.decode(cursor)
  len.times do
    str << Uint8.decode(cursor)
  end
  str
end

.encode(value) ⇒ Object



84
85
86
87
88
89
90
# File 'lib/canoser/field.rb', line 84

def self.encode(value)
  output = ""
  bytes = value.bytes
  output << Uint32.encode(bytes.size)
  bytes.each{|x| output << Canoser::Uint8.encode(x)}
  output
end