codec 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -1
- data/lib/codec/field.rb +1 -0
- data/lib/codec/prefix.rb +1 -1
- data/lib/codec/version.rb +1 -1
- data/test/lib/codec/prefix_test.rb +12 -4
- metadata +1 -1
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# Codec
|
2
2
|
|
3
|
-
|
3
|
+
Codec is a toolkit to build object that can decode a stream to a generic field tree
|
4
|
+
object or encode a generic field tree object to a binary string buffer
|
5
|
+
|
6
|
+
[![Gem Version](https://badge.fury.io/rb/codec.png)](http://badge.fury.io/rb/codec)
|
4
7
|
|
5
8
|
## Installation
|
6
9
|
|
data/lib/codec/field.rb
CHANGED
data/lib/codec/prefix.rb
CHANGED
@@ -90,7 +90,7 @@ module Codec
|
|
90
90
|
content_field = field.get_sub_field(@value_codec.id)
|
91
91
|
length, content = @value_codec.encode_with_length(content_field)
|
92
92
|
head_field = field.get_sub_field(@length_codec.id)
|
93
|
-
|
93
|
+
raise EncodingException, "Missing header for encoding #{@id}" if head_field.empty?
|
94
94
|
# update length field in header
|
95
95
|
head_field.set_value(length,@path,@separator)
|
96
96
|
# encode header
|
data/lib/codec/version.rb
CHANGED
@@ -68,13 +68,16 @@ describe Codec::Headerlength do
|
|
68
68
|
@header.add_sub_codec('H_TLV',Codec::Prefixedlength.new('*',length,tlv))
|
69
69
|
@content = Codec::String.new('CONTENT',0)
|
70
70
|
len = 6
|
71
|
-
|
72
|
-
|
71
|
+
field_head = ['HEADER', [['H_TAG','AA'],['H_TLV',[['01',25],['02',len]]]]]
|
72
|
+
field_content = ['CONTENT','STRING']
|
73
|
+
field_array = [ field_head, field_content]
|
73
74
|
@field_with_length = Codec::Field.from_array('Test_Headerlength',field_array)
|
74
75
|
len = 0
|
75
|
-
|
76
|
-
|
76
|
+
field_head = ['HEADER', [['H_TAG','AA'],['H_TLV',[['01',25],['02',len]]]]]
|
77
|
+
field_array = [ field_head, field_content]
|
77
78
|
@field_without_length = Codec::Field.from_array('Test_Headerlength',field_array)
|
79
|
+
field_array = [field_content]
|
80
|
+
@field_without_head = Codec::Field.from_array('Test_Headerlength',field_array)
|
78
81
|
@buffer = ["AA06010119020106","STRING"].pack("H*A*")
|
79
82
|
end
|
80
83
|
|
@@ -95,6 +98,11 @@ describe Codec::Headerlength do
|
|
95
98
|
it "must encode buffer with composed field [header,content]" do
|
96
99
|
subject.encode(@field_without_length).must_equal(@buffer)
|
97
100
|
end
|
101
|
+
|
102
|
+
it "must raise EncodingException if missing header field" do
|
103
|
+
proc { subject.encode(@field_without_head)}.must_raise(Codec::EncodingException)
|
104
|
+
end
|
105
|
+
|
98
106
|
end
|
99
107
|
|
100
108
|
describe Codec::Tagged do
|