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 CHANGED
@@ -1,6 +1,9 @@
1
1
  # Codec
2
2
 
3
- TODO: Write a gem description
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
@@ -2,6 +2,7 @@ module Codec
2
2
 
3
3
  class NilField
4
4
  def nil? ; return true; end
5
+ def empty? ; return true; end
5
6
  def get_id ; "" ; end
6
7
  def get_value ; "" ;end
7
8
  def get_sf_recursivly id ; return self ; end
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
- length_field = head_field.get_deep_field(@path,@separator)
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
@@ -1,3 +1,3 @@
1
1
  module Codec
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -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
- field_array = [['HEADER', [['H_TAG','AA'],['H_TLV',[['01',25],['02',len]]]]],
72
- ['CONTENT','STRING']]
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
- field_array = [['HEADER', [['H_TAG','AA'],['H_TLV',[['01',25],['02',len]]]]],
76
- ['CONTENT','STRING']]
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: