Class: Codec::Nstpck
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Packed
#decode, #encode_with_length, #get_length, #get_pck_length
Methods inherited from Base
#add_sub_codec, #build_field, #decode, #encode_with_length, #eval_length, #get_length, #get_sub_codecs, #initialize
Constructor Details
This class inherits a constructor from Codec::Base
Instance Method Details
#decode_with_length(buf, length) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/codec/packed.rb', line 84 def decode_with_length(buf,length) l = eval_length(buf,get_pck_length(length)) f = Field.new(@id) val = buf[0,l].unpack("H*").first if @length.odd? val = val[1,val.length] else val = val[1,val.length] if length.odd? end f.set_value(val) return f,buf[l,buf.length] end |
#encode(field) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/codec/packed.rb', line 97 def encode(field) out = field.get_value 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 |