slow_blink 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/slow_blink/ext_schema_parser/lexer.c +168 -177
- data/ext/slow_blink/ext_schema_parser/lexer.h +1 -1
- data/ext/slow_blink/ext_schema_parser/parser.c +303 -306
- data/ext/slow_blink/ext_schema_parser/parser.h +11 -12
- data/ext/slow_blink/{ext_compact_encoder → message/ext_compact_encoder}/ext_compact_encoder.c +3 -1
- data/ext/slow_blink/message/ext_compact_encoder/extconf.rb +4 -0
- data/lib/slow_blink/error.rb +1 -1
- data/lib/slow_blink/message/binary.rb +19 -26
- data/lib/slow_blink/message/boolean.rb +17 -17
- data/lib/slow_blink/message/date.rb +24 -0
- data/lib/slow_blink/message/decimal.rb +34 -0
- data/lib/slow_blink/message/enumeration.rb +24 -23
- data/lib/slow_blink/message/field.rb +45 -6
- data/lib/slow_blink/message/fixed.rb +35 -25
- data/lib/slow_blink/message/floating_point.rb +16 -17
- data/lib/slow_blink/message/group.rb +242 -136
- data/lib/slow_blink/message/integer.rb +77 -51
- data/lib/slow_blink/message/model.rb +121 -85
- data/lib/slow_blink/message/sequence.rb +43 -28
- data/lib/slow_blink/message/string.rb +17 -31
- data/lib/slow_blink/message/time.rb +55 -17
- data/lib/slow_blink/message/time_of_day.rb +40 -50
- data/lib/slow_blink/schema.rb +17 -6
- data/lib/slow_blink/version.rb +1 -1
- data/rakefile +12 -7
- data/test/tc_incr_annote.rb +16 -0
- data/test/tc_inputs.rb +2 -2
- data/test/tc_model_dynamic_group.rb +105 -0
- data/test/tc_model_extension.rb +143 -0
- data/test/tc_model_static_group.rb +27 -36
- data/test/tc_model_think_blink.rb +18 -35
- metadata +12 -9
- data/ext/slow_blink/ext_compact_encoder/extconf.rb +0 -4
- /data/ext/slow_blink/{ext_compact_encoder → message/ext_compact_encoder}/compact_encoder.c +0 -0
- /data/ext/slow_blink/{ext_compact_encoder → message/ext_compact_encoder}/compact_encoder.h +0 -0
@@ -21,35 +21,36 @@ module SlowBlink::Message
|
|
21
21
|
|
22
22
|
class TIME_OF_DAY_MILLI
|
23
23
|
|
24
|
-
def self.from_compact!(input)
|
25
|
-
|
24
|
+
def self.from_compact!(input, stack)
|
25
|
+
value = input.getU32!
|
26
|
+
if value
|
27
|
+
self.new(value)
|
28
|
+
else
|
29
|
+
value
|
30
|
+
end
|
26
31
|
end
|
27
32
|
|
28
|
-
def set(value)
|
29
|
-
if value
|
30
|
-
if value
|
31
|
-
|
32
|
-
@value = value
|
33
|
-
else
|
34
|
-
raise Error.new "input out of range"
|
35
|
-
end
|
36
|
-
elsif value.kind_of? Time
|
37
|
-
@value = value.to_i
|
33
|
+
def set(value)
|
34
|
+
if value.kind_of? Integer
|
35
|
+
if value < 86400000
|
36
|
+
@value = value
|
38
37
|
else
|
39
|
-
raise
|
40
|
-
end
|
41
|
-
elsif
|
42
|
-
@value =
|
38
|
+
raise RangeError
|
39
|
+
end
|
40
|
+
elsif value.kind_of? Time
|
41
|
+
@value = value.to_i
|
43
42
|
else
|
44
|
-
raise
|
45
|
-
end
|
43
|
+
raise TypeError
|
44
|
+
end
|
46
45
|
end
|
47
46
|
|
48
47
|
def get
|
49
48
|
@value
|
50
49
|
end
|
51
50
|
|
51
|
+
# @note calls {#set}(value)
|
52
52
|
def initialize(value)
|
53
|
+
@opt = self.class.opt?
|
53
54
|
if value
|
54
55
|
set(value)
|
55
56
|
else
|
@@ -60,60 +61,49 @@ module SlowBlink::Message
|
|
60
61
|
# @private
|
61
62
|
def to_compact(out)
|
62
63
|
out.putU32(@value)
|
63
|
-
|
64
|
-
|
65
|
-
|
66
64
|
end
|
67
65
|
|
68
|
-
|
69
|
-
|
70
66
|
end
|
71
67
|
|
72
68
|
class TIME_OF_DAY_NANO
|
73
69
|
|
74
|
-
def self.from_compact!(input)
|
75
|
-
|
70
|
+
def self.from_compact!(input, stack)
|
71
|
+
value = input.getU64!
|
72
|
+
if value
|
73
|
+
self.new(value)
|
74
|
+
else
|
75
|
+
value
|
76
|
+
end
|
76
77
|
end
|
77
78
|
|
78
|
-
def set(value)
|
79
|
-
if value
|
80
|
-
if value
|
81
|
-
|
82
|
-
@value = value
|
83
|
-
else
|
84
|
-
raise Error.new "input out of range"
|
85
|
-
end
|
86
|
-
elsif value.kind_of? Time
|
87
|
-
@value = value.to_i
|
79
|
+
def set(value)
|
80
|
+
if value.kind_of? Integer
|
81
|
+
if value < 86400000000000
|
82
|
+
@value = value
|
88
83
|
else
|
89
|
-
raise
|
90
|
-
end
|
91
|
-
elsif
|
92
|
-
@value =
|
84
|
+
raise RangeError
|
85
|
+
end
|
86
|
+
elsif value.kind_of? Time
|
87
|
+
@value = value.to_i
|
93
88
|
else
|
94
|
-
raise
|
95
|
-
end
|
89
|
+
raise TypeError
|
90
|
+
end
|
96
91
|
end
|
97
92
|
|
98
93
|
def get
|
99
94
|
@value
|
100
95
|
end
|
101
|
-
|
96
|
+
|
97
|
+
# @note calls {#set}(value)
|
102
98
|
def initialize(value)
|
103
|
-
|
104
|
-
set(value)
|
105
|
-
else
|
106
|
-
@value = nil
|
107
|
-
end
|
99
|
+
set(value)
|
108
100
|
end
|
109
101
|
|
110
102
|
# @private
|
111
103
|
def to_compact(out)
|
112
|
-
out.putU64(@value)
|
104
|
+
out.putU64(@value)
|
113
105
|
end
|
114
106
|
|
115
|
-
|
116
|
-
|
117
107
|
end
|
118
108
|
|
119
109
|
end
|
data/lib/slow_blink/schema.rb
CHANGED
@@ -47,13 +47,13 @@ module SlowBlink
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
#
|
51
|
-
#
|
52
|
-
# - These groups are of interest to message code generators
|
50
|
+
# @api user
|
53
51
|
#
|
54
|
-
# @return [Hash<Group>]
|
55
|
-
attr_reader :
|
52
|
+
# @return [Hash<Group>] groups indexed by qualified name
|
53
|
+
attr_reader :groups
|
56
54
|
|
55
|
+
attr_reader :tagged
|
56
|
+
|
57
57
|
# @return [Array<Namespace>]
|
58
58
|
attr_reader :ns
|
59
59
|
|
@@ -120,6 +120,18 @@ module SlowBlink
|
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
123
|
+
# create list of all groups with qualified names
|
124
|
+
@groups = {}
|
125
|
+
@ns.each do |name, ns|
|
126
|
+
ns.groups.each do |g|
|
127
|
+
if name
|
128
|
+
@groups[g.nameWithID.name.prepend "#{name}:"] = g
|
129
|
+
else
|
130
|
+
@groups[g.nameWithID.name] = g
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
123
135
|
if error
|
124
136
|
raise
|
125
137
|
end
|
@@ -147,7 +159,6 @@ require 'slow_blink/schema_buffer'
|
|
147
159
|
require 'slow_blink/annotatable'
|
148
160
|
require 'slow_blink/namespace'
|
149
161
|
require 'slow_blink/error'
|
150
|
-
require 'slow_blink/ext_compact_encoder'
|
151
162
|
require 'slow_blink/version'
|
152
163
|
require 'slow_blink/annotation'
|
153
164
|
require 'slow_blink/incremental_annotation'
|
data/lib/slow_blink/version.rb
CHANGED
data/rakefile
CHANGED
@@ -12,28 +12,33 @@ end
|
|
12
12
|
|
13
13
|
Rake::ExtensionTask.new do |ext|
|
14
14
|
ext.name = "ext_compact_encoder"
|
15
|
-
ext.ext_dir = "ext/slow_blink/ext_compact_encoder"
|
16
|
-
ext.lib_dir = "lib/slow_blink"
|
15
|
+
ext.ext_dir = "ext/slow_blink/message/ext_compact_encoder"
|
16
|
+
ext.lib_dir = "lib/slow_blink/message"
|
17
17
|
end
|
18
18
|
|
19
|
-
desc "
|
19
|
+
desc "run contents of test folder"
|
20
20
|
Rake::TestTask.new do |t|
|
21
21
|
t.name = :test
|
22
22
|
t.libs << "lib"
|
23
23
|
t.test_files = FileList["test/**/tc_*.rb"]
|
24
24
|
end
|
25
25
|
|
26
|
-
desc "run flex-bison"
|
26
|
+
desc "run flex-bison to build new parser source"
|
27
27
|
task :flexbison do
|
28
28
|
system "flex --outfile=#{DIR_SRC}/lexer.c --header-file=#{DIR_SRC}/lexer.h #{DIR_ETC}/parser.l"
|
29
29
|
system "bison -d #{DIR_ETC}/parser.y --output=#{DIR_SRC}/parser.c --report=all --report-file=#{DIR_SRC}/report.txt"
|
30
30
|
end
|
31
31
|
|
32
|
-
|
32
|
+
desc "run the think_blink benchmark"
|
33
|
+
task :benchmark do
|
34
|
+
system "ruby -Ilib -- bench/tutorial_example.rb"
|
33
35
|
end
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
+
desc "run code in examples folder"
|
38
|
+
task :run_examples do
|
39
|
+
Dir.glob("examples/**/*.rb").each do |f|
|
40
|
+
system "ruby -Ilib -Cexamples -- #{f.sub("examples/", "")}"
|
41
|
+
end
|
37
42
|
end
|
38
43
|
|
39
44
|
task :default => :test
|
data/test/tc_incr_annote.rb
CHANGED
@@ -24,4 +24,20 @@ class TestIncrAnnote < Test::Unit::TestCase
|
|
24
24
|
|
25
25
|
include SlowBlink
|
26
26
|
|
27
|
+
def test_schema
|
28
|
+
|
29
|
+
raw = <<-eos
|
30
|
+
Thing
|
31
|
+
AnotherThing ->
|
32
|
+
string Greeting
|
33
|
+
|
34
|
+
schema <- @test="test"
|
35
|
+
eos
|
36
|
+
|
37
|
+
schema = Schema.new(SchemaBuffer.new(raw))
|
38
|
+
|
39
|
+
assert_equal(schema.annotes
|
40
|
+
|
41
|
+
end
|
42
|
+
|
27
43
|
end
|
data/test/tc_inputs.rb
CHANGED
@@ -25,8 +25,8 @@ testClass = Class.new(Test::Unit::TestCase) do
|
|
25
25
|
# run and intercept stderr output
|
26
26
|
err = capture_stderr do
|
27
27
|
|
28
|
-
SlowBlink::Schema.new(SlowBlink::SchemaBuffer.new(inputs[__method__][:buffer], filename: inputs[__method__][:fileName]))
|
29
|
-
|
28
|
+
schema = SlowBlink::Schema.new(SlowBlink::SchemaBuffer.new(inputs[__method__][:buffer], filename: inputs[__method__][:fileName]))
|
29
|
+
|
30
30
|
end
|
31
31
|
|
32
32
|
# there should have been no messages to stderr
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# Copyright (c) 2016 Cameron Harper
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
# this software and associated documentation files (the "Software"), to deal in
|
5
|
+
# the Software without restriction, including without limitation the rights to
|
6
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
7
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
8
|
+
# subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
11
|
+
# copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
15
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
16
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
|
+
|
20
|
+
require "test/unit"
|
21
|
+
require 'slow_blink'
|
22
|
+
|
23
|
+
class TestModelDynamicGroup < Test::Unit::TestCase
|
24
|
+
|
25
|
+
include SlowBlink
|
26
|
+
|
27
|
+
def setup
|
28
|
+
|
29
|
+
rawSchema = <<-eos
|
30
|
+
DynamicGroup/0x01 ->
|
31
|
+
string one,
|
32
|
+
u8 two,
|
33
|
+
u8 three
|
34
|
+
|
35
|
+
Test/0x00 ->
|
36
|
+
string one,
|
37
|
+
u8 two,
|
38
|
+
u8 three,
|
39
|
+
DynamicGroup * four
|
40
|
+
eos
|
41
|
+
|
42
|
+
schema = Schema.new(SchemaBuffer.new(rawSchema))
|
43
|
+
@model = Message::Model.new(schema)
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_init
|
48
|
+
|
49
|
+
message = @model.group("Test").new(
|
50
|
+
"one" => "hello",
|
51
|
+
"two" => 42,
|
52
|
+
"three" => 42,
|
53
|
+
"four" => @model.group("DynamicGroup").new(
|
54
|
+
"one" => "world",
|
55
|
+
"two" => 42,
|
56
|
+
"three" => 42
|
57
|
+
)
|
58
|
+
)
|
59
|
+
|
60
|
+
assert_equal("hello", message["one"])
|
61
|
+
assert_equal(42, message["two"])
|
62
|
+
assert_equal(42, message["three"])
|
63
|
+
assert_equal("world", message["four"]["one"])
|
64
|
+
assert_equal(42, message["four"]["two"])
|
65
|
+
assert_equal(42, message["four"]["three"])
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_encode_compact
|
70
|
+
|
71
|
+
message = @model.group("Test").new(
|
72
|
+
"one" => "hello",
|
73
|
+
"two" => 42,
|
74
|
+
"three" => 42,
|
75
|
+
"four" => @model.group("DynamicGroup").new(
|
76
|
+
"one" => "world",
|
77
|
+
"two" => 42,
|
78
|
+
"three" => 42
|
79
|
+
)
|
80
|
+
)
|
81
|
+
|
82
|
+
output = message.encode_compact
|
83
|
+
|
84
|
+
expected = "\x13\x00\x05hello\x2a\x2a\x09\x01\x05world\x2a\x2a"
|
85
|
+
|
86
|
+
assert_equal(expected, output)
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_decode_compact
|
91
|
+
|
92
|
+
input = "\x13\x00\x05hello\x2a\x2a\x09\x01\x05world\x2a\x2a"
|
93
|
+
|
94
|
+
message = @model.decode_compact(input)
|
95
|
+
|
96
|
+
assert_equal("hello", message["one"])
|
97
|
+
assert_equal(42, message["two"])
|
98
|
+
assert_equal(42, message["three"])
|
99
|
+
assert_equal("world", message["four"]["one"])
|
100
|
+
assert_equal(42, message["four"]["two"])
|
101
|
+
assert_equal(42, message["four"]["three"])
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
# Copyright (c) 2016 Cameron Harper
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
# this software and associated documentation files (the "Software"), to deal in
|
5
|
+
# the Software without restriction, including without limitation the rights to
|
6
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
7
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
8
|
+
# subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
11
|
+
# copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
15
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
16
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
|
+
|
20
|
+
require "test/unit"
|
21
|
+
require 'slow_blink'
|
22
|
+
|
23
|
+
class TestModelExtension < Test::Unit::TestCase
|
24
|
+
|
25
|
+
include SlowBlink
|
26
|
+
|
27
|
+
def setup
|
28
|
+
|
29
|
+
rawSchema = <<-eos
|
30
|
+
StaticGroup ->
|
31
|
+
string one,
|
32
|
+
u8 two,
|
33
|
+
u8 three
|
34
|
+
|
35
|
+
Test/0x00 ->
|
36
|
+
string one,
|
37
|
+
u8 two,
|
38
|
+
u8 three,
|
39
|
+
StaticGroup four
|
40
|
+
eos
|
41
|
+
|
42
|
+
schema = Schema.new(SchemaBuffer.new(rawSchema))
|
43
|
+
@model = Message::Model.new(schema)
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_init
|
48
|
+
|
49
|
+
message = @model.group("Test").new(
|
50
|
+
"one" => "hello",
|
51
|
+
"two" => 42,
|
52
|
+
"three" => 42,
|
53
|
+
"four" => {
|
54
|
+
"one" => "world",
|
55
|
+
"two" => 42,
|
56
|
+
"three" => 42
|
57
|
+
}
|
58
|
+
)
|
59
|
+
|
60
|
+
message.extension << @model.group("Test").new(
|
61
|
+
"one" => "hello",
|
62
|
+
"two" => 42,
|
63
|
+
"three" => 42,
|
64
|
+
"four" => {
|
65
|
+
"one" => "world",
|
66
|
+
"two" => 42,
|
67
|
+
"three" => 42
|
68
|
+
}
|
69
|
+
)
|
70
|
+
|
71
|
+
assert_equal("hello", message["one"])
|
72
|
+
assert_equal(42, message["two"])
|
73
|
+
assert_equal(42, message["three"])
|
74
|
+
assert_equal("world", message["four"]["one"])
|
75
|
+
assert_equal(42, message["four"]["two"])
|
76
|
+
assert_equal(42, message["four"]["three"])
|
77
|
+
|
78
|
+
assert_equal(1, message.extension.size)
|
79
|
+
assert_equal("hello", message.extension.first["one"])
|
80
|
+
assert_equal(42, message.extension.first["two"])
|
81
|
+
assert_equal(42, message.extension.first["three"])
|
82
|
+
assert_equal("world", message.extension.first["four"]["one"])
|
83
|
+
assert_equal(42, message.extension.first["four"]["two"])
|
84
|
+
assert_equal(42, message.extension.first["four"]["three"])
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_encode_compact
|
89
|
+
|
90
|
+
message = @model.group("Test").new(
|
91
|
+
"one" => "hello",
|
92
|
+
"two" => 42,
|
93
|
+
"three" => 42,
|
94
|
+
"four" => {
|
95
|
+
"one" => "world",
|
96
|
+
"two" => 42,
|
97
|
+
"three" => 42
|
98
|
+
}
|
99
|
+
)
|
100
|
+
|
101
|
+
message.extension << @model.group("Test").new(
|
102
|
+
"one" => "hello",
|
103
|
+
"two" => 42,
|
104
|
+
"three" => 42,
|
105
|
+
"four" => {
|
106
|
+
"one" => "world",
|
107
|
+
"two" => 42,
|
108
|
+
"three" => 42
|
109
|
+
}
|
110
|
+
)
|
111
|
+
|
112
|
+
output = message.encode_compact
|
113
|
+
|
114
|
+
expected = "\x24\x00\x05hello\x2a\x2a\x05world\x2a\x2a\x01\x11\x00\x05hello\x2a\x2a\x05world\x2a\x2a"
|
115
|
+
|
116
|
+
assert_equal(expected, output)
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_decode_compact
|
121
|
+
|
122
|
+
input = "\x24\x00\x05hello\x2a\x2a\x05world\x2a\x2a\x01\x11\x00\x05hello\x2a\x2a\x05world\x2a\x2a"
|
123
|
+
|
124
|
+
message = @model.decode_compact(input)
|
125
|
+
|
126
|
+
assert_equal("hello", message["one"])
|
127
|
+
assert_equal(42, message["two"])
|
128
|
+
assert_equal(42, message["three"])
|
129
|
+
assert_equal("world", message["four"]["one"])
|
130
|
+
assert_equal(42, message["four"]["two"])
|
131
|
+
assert_equal(42, message["four"]["three"])
|
132
|
+
|
133
|
+
assert_equal(1, message.extension.size)
|
134
|
+
assert_equal("hello", message.extension.first["one"])
|
135
|
+
assert_equal(42, message.extension.first["two"])
|
136
|
+
assert_equal(42, message.extension.first["three"])
|
137
|
+
assert_equal("world", message.extension.first["four"]["one"])
|
138
|
+
assert_equal(42, message.extension.first["four"]["two"])
|
139
|
+
assert_equal(42, message.extension.first["four"]["three"])
|
140
|
+
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
@@ -44,39 +44,19 @@ class TestModelStaticGroup < Test::Unit::TestCase
|
|
44
44
|
|
45
45
|
end
|
46
46
|
|
47
|
-
def
|
48
|
-
|
49
|
-
message = @model.group "Test" do |g|
|
50
|
-
g["one"] = "hello"
|
51
|
-
g["two"] = 42
|
52
|
-
g["three"] = 42
|
53
|
-
g["four"]["one"] = "world"
|
54
|
-
g["four"]["two"] = 42
|
55
|
-
g["four"]["three"] = 42
|
56
|
-
end
|
57
|
-
|
58
|
-
assert_equal("hello", message["one"])
|
59
|
-
assert_equal(42, message["two"])
|
60
|
-
assert_equal(42, message["three"])
|
61
|
-
assert_equal("world", message["four"]["one"])
|
62
|
-
assert_equal(42, message["four"]["two"])
|
63
|
-
assert_equal(42, message["four"]["three"])
|
47
|
+
def test_init
|
64
48
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
g["one"] = "hello"
|
71
|
-
g["two"] = 42
|
72
|
-
g["three"] = 42
|
73
|
-
g["four"] = {
|
49
|
+
message = @model.group("Test").new(
|
50
|
+
"one" => "hello",
|
51
|
+
"two" => 42,
|
52
|
+
"three" => 42,
|
53
|
+
"four" => {
|
74
54
|
"one" => "world",
|
75
55
|
"two" => 42,
|
76
56
|
"three" => 42
|
77
57
|
}
|
78
|
-
|
79
|
-
|
58
|
+
)
|
59
|
+
|
80
60
|
assert_equal("hello", message["one"])
|
81
61
|
assert_equal(42, message["two"])
|
82
62
|
assert_equal(42, message["three"])
|
@@ -86,9 +66,9 @@ class TestModelStaticGroup < Test::Unit::TestCase
|
|
86
66
|
|
87
67
|
end
|
88
68
|
|
89
|
-
def
|
69
|
+
def test_encode_compact
|
90
70
|
|
91
|
-
message = @model.group
|
71
|
+
message = @model.group("Test").new(
|
92
72
|
"one" => "hello",
|
93
73
|
"two" => 42,
|
94
74
|
"three" => 42,
|
@@ -97,18 +77,29 @@ class TestModelStaticGroup < Test::Unit::TestCase
|
|
97
77
|
"two" => 42,
|
98
78
|
"three" => 42
|
99
79
|
}
|
100
|
-
|
80
|
+
)
|
81
|
+
|
82
|
+
output = message.encode_compact
|
83
|
+
|
84
|
+
expected = "\x11\x00\x05hello\x2a\x2a\x05world\x2a\x2a"
|
85
|
+
|
86
|
+
assert_equal(expected, output)
|
101
87
|
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_decode_compact
|
91
|
+
|
92
|
+
input = "\x11\x00\x05hello\x2a\x2a\x05world\x2a\x2a"
|
93
|
+
|
94
|
+
message = @model.decode_compact(input)
|
95
|
+
|
102
96
|
assert_equal("hello", message["one"])
|
103
97
|
assert_equal(42, message["two"])
|
104
98
|
assert_equal(42, message["three"])
|
105
99
|
assert_equal("world", message["four"]["one"])
|
106
100
|
assert_equal(42, message["four"]["two"])
|
107
|
-
assert_equal(42, message["four"]["three"])
|
108
|
-
|
101
|
+
assert_equal(42, message["four"]["three"])
|
102
|
+
|
109
103
|
end
|
110
104
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
105
|
end
|
@@ -37,35 +37,16 @@ class TestModelThinkBlink < Test::Unit::TestCase
|
|
37
37
|
@model = Message::Model.new(schema)
|
38
38
|
end
|
39
39
|
|
40
|
-
def
|
40
|
+
def test_set
|
41
41
|
|
42
|
-
message = @model.group
|
43
|
-
g["Symbol"] = "hey"
|
44
|
-
g["OrderId"] = 42
|
45
|
-
g["Price"] = 42
|
46
|
-
g["Qty"] = 42
|
47
|
-
g["MatchId"] = 42
|
48
|
-
end
|
49
|
-
|
50
|
-
assert_equal("hey", message["Symbol"])
|
51
|
-
assert_equal(42, message["OrderId"])
|
52
|
-
assert_equal(42, message["Price"])
|
53
|
-
assert_equal(42, message["Qty"])
|
54
|
-
assert_equal(42, message["MatchId"])
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_set_bulk
|
59
|
-
|
60
|
-
message = @model.group "OrderExecuted", {
|
42
|
+
message = @model.group("OrderExecuted").new(
|
61
43
|
"Symbol" => "hey",
|
62
|
-
"OrderId" => 42,
|
63
|
-
"Price" => 42,
|
64
|
-
"Qty" => 42,
|
65
|
-
"MatchId" => 42
|
66
|
-
|
44
|
+
"OrderId" => 42,
|
45
|
+
"Price" => 42,
|
46
|
+
"Qty" => 42,
|
47
|
+
"MatchId" => 42
|
48
|
+
)
|
67
49
|
|
68
|
-
|
69
50
|
assert_equal("hey", message["Symbol"])
|
70
51
|
assert_equal(42, message["OrderId"])
|
71
52
|
assert_equal(42, message["Price"])
|
@@ -76,15 +57,15 @@ class TestModelThinkBlink < Test::Unit::TestCase
|
|
76
57
|
|
77
58
|
def test_encode_compact
|
78
59
|
|
79
|
-
message = @model.group
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
60
|
+
message = @model.group("OrderExecuted").new(
|
61
|
+
"Symbol" => "hey",
|
62
|
+
"OrderId" => 42,
|
63
|
+
"Price" => 42,
|
64
|
+
"Qty" => 42,
|
65
|
+
"MatchId" => 42
|
66
|
+
)
|
86
67
|
|
87
|
-
output = message.
|
68
|
+
output = message.encode_compact
|
88
69
|
|
89
70
|
expected = "\x09\x4c\x03hey\x2a\x2a\x2a\x2a"
|
90
71
|
|
@@ -102,7 +83,9 @@ class TestModelThinkBlink < Test::Unit::TestCase
|
|
102
83
|
assert_equal(0, message["OrderId"])
|
103
84
|
assert_equal(1, message["Price"])
|
104
85
|
assert_equal(2, message["Qty"])
|
105
|
-
assert_equal(3, message["MatchId"])
|
86
|
+
assert_equal(3, message["MatchId"])
|
87
|
+
|
106
88
|
end
|
107
89
|
|
90
|
+
|
108
91
|
end
|