codec 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/codec.gemspec +1 -1
- data/lib/codec/base.rb +2 -2
- data/lib/codec/fix.rb +48 -0
- data/lib/codec/version.rb +1 -1
- data/lib/codec.rb +4 -4
- data/test/lib/codec/fix_test.rb +16 -0
- metadata +5 -2
data/codec.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.email = ["bernard.rodier@gmail.com"]
|
9
9
|
spec.description = %q{Generic Coder Decoder Tool}
|
10
10
|
spec.summary = %q{This Gem provide class that permit to instantiate Codec to parse or build any protocol}
|
11
|
-
spec.homepage = ""
|
11
|
+
spec.homepage = "https://github.com/brodier/codec"
|
12
12
|
spec.license = "MIT"
|
13
13
|
|
14
14
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
data/lib/codec/base.rb
CHANGED
@@ -12,12 +12,12 @@ module Codec
|
|
12
12
|
return f
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
15
|
+
def decode_with_length(buf,length)
|
16
16
|
init_data(buf,length)
|
17
17
|
return build_field,@remain
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
20
|
+
def decode(buf)
|
21
21
|
init_data(buf,@length)
|
22
22
|
return build_field,@remain
|
23
23
|
end
|
data/lib/codec/fix.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
module Codec
|
2
|
+
class Numbin < Base
|
3
|
+
def build_field
|
4
|
+
f = Field.new(@id)
|
5
|
+
res = 0
|
6
|
+
@data.unpack("C*").each{ |ubyte|
|
7
|
+
res *= 256
|
8
|
+
res += ubyte
|
9
|
+
}
|
10
|
+
f.set_value(res)
|
11
|
+
return f
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
class Numstr < Base
|
18
|
+
def build_field
|
19
|
+
f = Field.new(@id)
|
20
|
+
# Force conversion of ebcdic number to ascii number
|
21
|
+
if IsEbcdic(@data)
|
22
|
+
@data = Ebcdic2Ascii(@data)
|
23
|
+
end
|
24
|
+
|
25
|
+
f.set_value(@data.to_i)
|
26
|
+
return f
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class String < Base
|
31
|
+
def build_field
|
32
|
+
f = Field.new(@id)
|
33
|
+
if IsEbcdic(@data)
|
34
|
+
@data = Ebcdic2Ascii(@data)
|
35
|
+
end
|
36
|
+
f.set_value(@data)
|
37
|
+
return f
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class Binary < Base
|
42
|
+
def build_field
|
43
|
+
f = Field.new(@id)
|
44
|
+
f.set_value(@data.unpack("H*").first.upcase)
|
45
|
+
return f
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/codec/version.rb
CHANGED
data/lib/codec.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'log4r'
|
2
2
|
require 'codec/version'
|
3
|
-
require 'codec/
|
3
|
+
require 'codec/field'
|
4
4
|
require 'codec/exceptions'
|
5
5
|
require 'codec/base'
|
6
|
-
|
6
|
+
require 'codec/fix'
|
7
7
|
# require 'codec/packed'
|
8
8
|
# require 'codec/prefixed'
|
9
9
|
# require 'codec/composed'
|
@@ -21,8 +21,8 @@ module Codec
|
|
21
21
|
end
|
22
22
|
|
23
23
|
|
24
|
-
def self.register_protocol(
|
25
|
-
protocols <<
|
24
|
+
def self.register_protocol(protocol)
|
25
|
+
protocols << protocol
|
26
26
|
return protocols
|
27
27
|
end
|
28
28
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe Codec::Numbin do
|
4
|
+
subject { Codec::Numbin.new('Test',4) }
|
5
|
+
|
6
|
+
it "must be a codec" do
|
7
|
+
subject.must_be_instance_of(Codec::Numbin)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "must generate a field with computed value" do
|
11
|
+
subject.decode(["00000100"].pack("H*")).first.get_value.to_i.must_equal(256)
|
12
|
+
end
|
13
|
+
it "must generate a field with computed value" do
|
14
|
+
subject.decode(["00000100"].pack("H*")).last.size.must_equal(0)
|
15
|
+
end
|
16
|
+
end
|
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.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -60,11 +60,13 @@ files:
|
|
60
60
|
- lib/codec/base.rb
|
61
61
|
- lib/codec/exceptions.rb
|
62
62
|
- lib/codec/field.rb
|
63
|
+
- lib/codec/fix.rb
|
63
64
|
- lib/codec/protocols/core.rb
|
64
65
|
- lib/codec/version.rb
|
66
|
+
- test/lib/codec/fix_test.rb
|
65
67
|
- test/lib/codec/version_test.rb
|
66
68
|
- test/test_helper.rb
|
67
|
-
homepage:
|
69
|
+
homepage: https://github.com/brodier/codec
|
68
70
|
licenses:
|
69
71
|
- MIT
|
70
72
|
post_install_message:
|
@@ -91,5 +93,6 @@ specification_version: 3
|
|
91
93
|
summary: This Gem provide class that permit to instantiate Codec to parse or build
|
92
94
|
any protocol
|
93
95
|
test_files:
|
96
|
+
- test/lib/codec/fix_test.rb
|
94
97
|
- test/lib/codec/version_test.rb
|
95
98
|
- test/test_helper.rb
|