Class: Codec::Numpck
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Packed
#decode, #decode_with_length, #encode_with_length, #get_length, #get_pck_length
Methods inherited from Base
#add_sub_codec, #decode, #decode_with_length, #encode_with_length, #eval_length, #get_length, #get_sub_codecs, #initialize
Constructor Details
This class inherits a constructor from Codec::Base
Instance Method Details
#build_field(buf, length) ⇒ Object
30 31 32 33 34 |
# File 'lib/codec/packed.rb', line 30 def build_field(buf,length) f = Field.new(@id) f.set_value(buf[0,length].unpack("H*").first.to_i) return f end |
#encode(field) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/codec/packed.rb', line 36 def encode(field) out = field.get_value.to_s if @length > 0 out = out.rjust(@length,"0") raise TooLongDataException if out.length > @length end l = out.length out.prepend("0") if out.length.odd? out = [out].pack("H*") return out end |