Method: Codec::Bertlv#encode

Defined in:
lib/codec/tlv.rb

#encode(buf, field) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/codec/tlv.rb', line 97

def encode(buf, field)
  out = ""
  subfields = field.get_value
  unless subfields.kind_of?(Array)
    raise EncodingException, "Invalid field #{field.to_yaml} for BER Tlv encoding"
  end
  
  while subfields.size > 0
    subfield = subfields.shift
    out << tag_encode(subfield.get_id)
    # TODO : Handle value that is not String
    value = value_encode(subfield.get_value)
    out << length_encode(value.length)
    out << value
  end
  buf << out
  return out.length
end