41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/codec/packed.rb', line 41
def encode(buf, field)
out = field.get_value.to_s
Logger.debug{ "Encode packed #{out} on #{@length} [#{@isNum}|#{@fPad}|#{@lPad}]" }
padding = (@fPad ? "F" : "0")
if @length > 0
out = (@lPad ? out.ljust(@length,padding) : out.rjust(@length,padding))
raise TooLongDataException if out.length > @length
end
l = out.length
(@lPad ? out << padding : out.prepend(padding) )if out.length.odd?
Logger.debug{ "before packing : #{out}" }
out = [out].pack("H*")
buf << out
return l
end
|