class Canoser::ArrayT
Attributes
fixed_len[RW]
type[RW]
Public Class Methods
new(type=Uint8, fixed_len=nil)
click to toggle source
# File lib/canoser/field.rb, line 106 def initialize(type=Uint8, fixed_len=nil) @type = type @fixed_len = fixed_len end
Public Instance Methods
==(other)
click to toggle source
# File lib/canoser/field.rb, line 130 def ==(other) return self.type == other.type && self.fixed_len == other.fixed_len end
decode(cursor)
click to toggle source
# File lib/canoser/field.rb, line 118 def decode(cursor) arr = [] len = Uint32.decode(cursor) if @fixed_len && len != @fixed_len raise ParseError.new("fix-len:#{@fixed_len} != #{len}") end len.times do arr << @type.decode(cursor) end arr end
encode(arr)
click to toggle source
# File lib/canoser/field.rb, line 111 def encode(arr) output = "" output << Uint32.encode(arr.size) arr.each{|x| output << @type.encode(x)} output end