Class: Codec::Tagged
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #decode(buffer) ⇒ Object
- #encode(field) ⇒ Object
-
#initialize(id, tag_codec) ⇒ Tagged
constructor
A new instance of Tagged.
Methods inherited from Base
#add_sub_codec, #build_field, #decode_with_length, #encode_with_length, #eval_length, #get_length, #get_sub_codecs
Constructor Details
#initialize(id, tag_codec) ⇒ Tagged
Returns a new instance of Tagged.
107 108 109 110 111 |
# File 'lib/codec/prefix.rb', line 107 def initialize(id,tag_codec) @subCodecs = {} @tag_codec = tag_codec @id = id end |
Instance Method Details
#decode(buffer) ⇒ Object
113 114 115 116 117 118 119 120 121 |
# File 'lib/codec/prefix.rb', line 113 def decode(buffer) tag,buf = @tag_codec.decode(buffer) if @subCodecs[tag.get_value.to_s].nil? raise ParsingException, "Unknown tag #{tag.get_value.to_s} for #{@id} decoder" end f,buf = @subCodecs[tag.get_value.to_s].decode(buf) f.set_id(tag.get_value.to_s) return f,buf end |
#encode(field) ⇒ Object
123 124 125 126 127 128 129 130 131 |
# File 'lib/codec/prefix.rb', line 123 def encode(field) head = Field.new(@tag_codec.id, field.get_id) out = @tag_codec.encode(head) if @subCodecs[field.get_id].nil? raise EncodingException, "Unknown tag #{field.get_id} for #{@id} encoder" end out += @subCodecs[field.get_id].encode(field) return out end |