Method: Codec::Bitmap#decode

Defined in:
lib/codec/bitmap.rb

#decode(buf, msg, length = nil) ⇒ Object

[View source]

80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/codec/bitmap.rb', line 80

def decode(buf,msg, length=nil)
  buf = buf.slice!(0...length) if length && length > 0
  field_num = 1
  # 1. read bitmap
  fields_list = decode_bitmap(buf,field_num)
  field_num += bitmap_length
  # 2. decode each field present
  while fields_list.length > 0
    # get next field number in bitmap
    field_id = fields_list.slice!(0)
    field_tag = field_id.to_s
    if @num_extended_bitmaps.include?(field_id)
      nextFields = decode_bitmap(buf,field_num)
      fields_list = fields_list + nextFields
    elsif @subCodecs[field_tag].respond_to?(:decode)
      Logger.debug "Parsing bitmap field #{field_tag}"
      f = Field.new(field_tag)
      @subCodecs[field_tag].decode(buf,f)
      msg.add_sub_field(f)
    else
     f = Field.new("ERR") 
     f.set_value(buf.unpack("H*").first)
     msg.add_sub_field(f)
      raise ParsingException.new "#{msg}\nError unknown field #{field_tag} : "
    end
  end
end