Class: Codec::Fix
Instance Method Summary
collapse
Methods inherited from Base
#add_sub_codec, #encode, #get_sub_codecs
Constructor Details
#initialize(length = nil) ⇒ Fix
Returns a new instance of Fix.
4
5
6
|
# File 'lib/codec/fix.rb', line 4
def initialize(length=nil)
@length = length || 0
end
|
Instance Method Details
#build_field(w, f, l) ⇒ Object
27
28
29
|
# File 'lib/codec/fix.rb', line 27
def build_field(w,f,l)
raise "Abstract Codec : build field not defined for #{self.class.name}"
end
|
#check_length(buf, length) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/codec/fix.rb', line 8
def check_length(buf,length)
raise "Length is nil" if length.nil?
if(length != 0)
if buf.length < length
raise BufferUnderflow, "Not enough data for decoding (#{length}/#{buf.length})"
end
return length
else
return buf.length
end
end
|
#decode(buf, field, length = nil) ⇒ Object
20
21
22
23
24
25
|
# File 'lib/codec/fix.rb', line 20
def decode(buf,field,length=nil)
length ||= @length
l = check_length(buf,length)
wbuf = buf.slice!(0...l)
build_field(wbuf,field,l)
end
|