Class: Codec::Binary

Inherits:
Fix show all
Defined in:
lib/codec/fix.rb

Instance Method Summary collapse

Methods inherited from Fix

#check_length, #decode, #initialize

Methods inherited from Base

#add_sub_codec, #decode, #get_sub_codecs

Constructor Details

This class inherits a constructor from Codec::Fix

Instance Method Details

#build_field(buf, field, length) ⇒ Object



155
156
157
# File 'lib/codec/fix.rb', line 155

def build_field(buf, field, length)
  field.set_value(buf.slice!(0...length).unpack("H*").first.upcase)
end

#encode(buf, f) ⇒ Object



159
160
161
162
163
164
165
166
167
# File 'lib/codec/fix.rb', line 159

def encode(buf, f)
  out = [f.get_value].pack("H*")
  if @length >  0
    raise TooLongDataException if out.length > @length
    out = out.ljust(@length,0.chr)
  end
  buf << out
  return out.length
end