lib/canoser/field.rb in canoser-0.1.3 vs lib/canoser/field.rb in canoser-0.2.1

- old
+ new

@@ -93,11 +93,11 @@ str = "" len = Uint32.decode(cursor) len.times do str << Uint8.decode(cursor) end - str + str end end class ArrayT @@ -108,22 +108,24 @@ @fixed_len = fixed_len end def encode(arr) output = "" - output << Uint32.encode(arr.size) unless @fixed_len + output << Uint32.encode(arr.size) arr.each{|x| output << @type.encode(x)} output end def decode(cursor) arr = [] - len = @fixed_len - len = Uint32.decode(cursor) unless @fixed_len + 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 + arr end def ==(other) return self.type == other.type && self.fixed_len == other.fixed_len end