Class: Codec::Base
- Inherits:
-
Object
show all
- Defined in:
- lib/codec/base.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(id, length) ⇒ Base
Returns a new instance of Base.
4
5
6
7
|
# File 'lib/codec/base.rb', line 4
def initialize(id,length)
@length = length.to_i
@id = id
end
|
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
3
4
5
|
# File 'lib/codec/base.rb', line 3
def id
@id
end
|
Instance Method Details
#add_subparser(id_field, parser) ⇒ Object
39
40
41
42
43
44
45
46
|
# File 'lib/codec/base.rb', line 39
def add_subparser(id_field,parser)
if parser.nil?
raise InitializeException, "Invalid codec reference in subparser #{id_field} for codec #{@id}"
end
if @subParsers.kind_of? Hash
@subParsers[id_field] = parser
end
end
|
#build_field ⇒ Object
9
10
11
12
13
|
# File 'lib/codec/base.rb', line 9
def build_field
f = Field.new(@id)
f.set_value(@data)
return f
end
|
#decode(buf) ⇒ Object
20
21
22
23
|
# File 'lib/codec/base.rb', line 20
def decode(buf)
init_data(buf,@length)
return build_field,@remain
end
|
#decode_with_length(buf, length) ⇒ Object
15
16
17
18
|
# File 'lib/codec/base.rb', line 15
def decode_with_length(buf,length)
init_data(buf,length)
return build_field,@remain
end
|
#get_sub_parsers ⇒ Object
48
49
50
|
# File 'lib/codec/base.rb', line 48
def get_sub_parsers
return @subParsers
end
|
#init_data(buf, length) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/codec/base.rb', line 25
def init_data(buf,length)
length = 0 if length.nil?
if(length != 0)
if buf.length < length
raise BufferUnderflow, "Not enough data for parsing #{@id} (#{length}/#{buf.length})"
end
@data = buf[0,length]
@remain = buf[length,buf.length]
else
@data = buf
@remain = ""
end
end
|