bin_utils 0.0.4-java
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/bin_utils/bin_utils.jar +0 -0
- data/lib/bin_utils/pure_ruby.rb +1035 -0
- data/lib/bin_utils/version.rb +3 -0
- data/lib/bin_utils.rb +19 -0
- data/test/benchmark.rb +176 -0
- data/test/test_bin_utils.rb +471 -0
- metadata +73 -0
@@ -0,0 +1,471 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'minitest/spec'
|
3
|
+
require 'minitest/autorun'
|
4
|
+
|
5
|
+
shared_example = proc do
|
6
|
+
def src; "\x01\x02\x03\x04\xf5\xf6\xf7\xf8\xf9\x0a\x0b\x0c".force_encoding(::Encoding::BINARY) ; end
|
7
|
+
def dest; "\x01\x02".force_encoding(::Encoding::BINARY); end
|
8
|
+
|
9
|
+
it "must get integer" do
|
10
|
+
util.get_int8(src).must_equal 1
|
11
|
+
util.get_int8(src, 0).must_equal 1
|
12
|
+
util.get_int8(src, 4).must_equal 0xf5
|
13
|
+
util.get_sint8(src).must_equal 1
|
14
|
+
util.get_sint8(src, 0).must_equal 1
|
15
|
+
util.get_sint8(src, 4).must_equal(-11)
|
16
|
+
|
17
|
+
util.get_int16_le(src).must_equal 0x0201
|
18
|
+
util.get_int16_le(src, 0).must_equal 0x0201
|
19
|
+
util.get_int16_le(src, 5).must_equal 0xf7f6
|
20
|
+
util.get_sint16_le(src).must_equal 0x0201
|
21
|
+
util.get_sint16_le(src, 0).must_equal 0x0201
|
22
|
+
util.get_sint16_le(src, 5).must_equal(-2058)
|
23
|
+
|
24
|
+
util.get_int16_be(src).must_equal 0x0102
|
25
|
+
util.get_int16_be(src, 0).must_equal 0x0102
|
26
|
+
util.get_int16_be(src, 5).must_equal 0xf6f7
|
27
|
+
util.get_sint16_be(src).must_equal 0x0102
|
28
|
+
util.get_sint16_be(src, 0).must_equal 0x0102
|
29
|
+
util.get_sint16_be(src, 5).must_equal(-2313)
|
30
|
+
|
31
|
+
util.get_int24_le(src).must_equal 0x030201
|
32
|
+
util.get_int24_le(src, 0).must_equal 0x030201
|
33
|
+
util.get_int24_le(src, 5).must_equal 0xf8f7f6
|
34
|
+
util.get_sint24_le(src).must_equal 0x030201
|
35
|
+
util.get_sint24_le(src, 0).must_equal 0x030201
|
36
|
+
util.get_sint24_le(src, 5).must_equal(-460810)
|
37
|
+
|
38
|
+
util.get_int24_be(src).must_equal 0x010203
|
39
|
+
util.get_int24_be(src, 0).must_equal 0x010203
|
40
|
+
util.get_int24_be(src, 5).must_equal 0xf6f7f8
|
41
|
+
util.get_sint24_be(src).must_equal 0x010203
|
42
|
+
util.get_sint24_be(src, 0).must_equal 0x010203
|
43
|
+
util.get_sint24_be(src, 5).must_equal(-591880)
|
44
|
+
|
45
|
+
util.get_int32_le(src).must_equal 0x04030201
|
46
|
+
util.get_int32_le(src, 0).must_equal 0x04030201
|
47
|
+
util.get_int32_le(src, 4).must_equal 0xf8f7f6f5
|
48
|
+
util.get_sint32_le(src).must_equal 0x04030201
|
49
|
+
util.get_sint32_le(src, 0).must_equal 0x04030201
|
50
|
+
util.get_sint32_le(src, 4).must_equal(-117967115)
|
51
|
+
|
52
|
+
util.get_int32_be(src).must_equal 0x01020304
|
53
|
+
util.get_int32_be(src, 0).must_equal 0x01020304
|
54
|
+
util.get_int32_be(src, 4).must_equal 0xf5f6f7f8
|
55
|
+
util.get_sint32_be(src).must_equal 0x01020304
|
56
|
+
util.get_sint32_be(src, 0).must_equal 0x01020304
|
57
|
+
util.get_sint32_be(src, 4).must_equal(-168364040)
|
58
|
+
|
59
|
+
util.get_int40_le(src).must_equal 0xf504030201
|
60
|
+
util.get_int40_le(src, 0).must_equal 0xf504030201
|
61
|
+
util.get_int40_le(src, 3).must_equal 0xf8f7f6f504
|
62
|
+
util.get_sint40_le(src).must_equal(-47177334271)
|
63
|
+
util.get_sint40_le(src, 0).must_equal(-47177334271)
|
64
|
+
util.get_sint40_le(src, 3).must_equal(-30199581436)
|
65
|
+
|
66
|
+
util.get_int40_be(src).must_equal 0x01020304f5
|
67
|
+
util.get_int40_be(src, 0).must_equal 0x01020304f5
|
68
|
+
util.get_int40_be(src, 4).must_equal 0xf5f6f7f8f9
|
69
|
+
util.get_sint40_be(src).must_equal 0x01020304f5
|
70
|
+
util.get_sint40_be(src, 0).must_equal 0x01020304f5
|
71
|
+
util.get_sint40_be(src, 4).must_equal(-43101193991)
|
72
|
+
|
73
|
+
util.get_int48_le(src).must_equal 0xf6f504030201
|
74
|
+
util.get_int48_le(src, 0).must_equal 0xf6f504030201
|
75
|
+
util.get_int48_le(src, 4).must_equal 0x0af9f8f7f6f5
|
76
|
+
util.get_sint48_le(src).must_equal(-9942781984255)
|
77
|
+
util.get_sint48_le(src, 0).must_equal(-9942781984255)
|
78
|
+
util.get_sint48_le(src, 4).must_equal 0x0af9f8f7f6f5
|
79
|
+
|
80
|
+
util.get_int48_be(src).must_equal 0x01020304f5f6
|
81
|
+
util.get_int48_be(src, 0).must_equal 0x01020304f5f6
|
82
|
+
util.get_int48_be(src, 4).must_equal 0xf5f6f7f8f90a
|
83
|
+
util.get_sint48_be(src).must_equal 0x01020304f5f6
|
84
|
+
util.get_sint48_be(src, 0).must_equal 0x01020304f5f6
|
85
|
+
util.get_sint48_be(src, 4).must_equal(-11033905661686)
|
86
|
+
|
87
|
+
util.get_int56_le(src).must_equal 0xf7f6f504030201
|
88
|
+
util.get_int56_le(src, 0).must_equal 0xf7f6f504030201
|
89
|
+
util.get_int56_le(src, 4).must_equal 0x0b0af9f8f7f6f5
|
90
|
+
util.get_sint56_le(src).must_equal(-2261742595669503)
|
91
|
+
util.get_sint56_le(src, 0).must_equal(-2261742595669503)
|
92
|
+
util.get_sint56_le(src, 4).must_equal 3108293483951861
|
93
|
+
|
94
|
+
util.get_int56_be(src).must_equal 0x01020304f5f6f7
|
95
|
+
util.get_int56_be(src, 0).must_equal 0x01020304f5f6f7
|
96
|
+
util.get_int56_be(src, 4).must_equal 0xf5f6f7f8f90a0b
|
97
|
+
util.get_sint56_be(src).must_equal 0x01020304f5f6f7
|
98
|
+
util.get_sint56_be(src, 0).must_equal 0x01020304f5f6f7
|
99
|
+
util.get_sint56_be(src, 4).must_equal(-2824679849391605)
|
100
|
+
|
101
|
+
util.get_int64_le(src).must_equal 0xf8f7f6f504030201
|
102
|
+
util.get_int64_le(src, 0).must_equal 0xf8f7f6f504030201
|
103
|
+
util.get_int64_le(src, 4).must_equal 0x0c0b0af9f8f7f6f5
|
104
|
+
util.get_sint64_le(src).must_equal(-506664900861165055)
|
105
|
+
util.get_sint64_le(src, 0).must_equal(-506664900861165055)
|
106
|
+
util.get_sint64_le(src, 4).must_equal 0x0c0b0af9f8f7f6f5
|
107
|
+
|
108
|
+
util.get_int64_be(src).must_equal 0x01020304f5f6f7f8
|
109
|
+
util.get_int64_be(src, 0).must_equal 0x01020304f5f6f7f8
|
110
|
+
util.get_int64_be(src, 4).must_equal 0xf5f6f7f8f90a0b0c
|
111
|
+
util.get_sint64_be(src).must_equal 0x01020304f5f6f7f8
|
112
|
+
util.get_sint64_be(src, 0).must_equal 0x01020304f5f6f7f8
|
113
|
+
util.get_sint64_be(src, 4).must_equal(-723118041444250868)
|
114
|
+
|
115
|
+
util.get_ber(src).must_equal 1
|
116
|
+
util.get_ber(src, 0).must_equal 1
|
117
|
+
util.get_ber(src, 6).must_equal 251542666
|
118
|
+
end
|
119
|
+
|
120
|
+
def asrc; "\x01\x02\x03\x04\x05\x06\x07\x08\x09".force_encoding(::Encoding::BINARY) ; end
|
121
|
+
def msrc; "\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9".force_encoding(::Encoding::BINARY) ; end
|
122
|
+
|
123
|
+
it "must slice integer" do
|
124
|
+
s = asrc; util.slice_int8!(s).must_equal 0x01; s.must_equal asrc[1..-1]
|
125
|
+
s = msrc; util.slice_int8!(s).must_equal 0xf1; s.must_equal msrc[1..-1]
|
126
|
+
s = asrc; util.slice_sint8!(s).must_equal 0x01; s.must_equal asrc[1..-1]
|
127
|
+
s = msrc; util.slice_sint8!(s).must_equal(-15); s.must_equal msrc[1..-1]
|
128
|
+
|
129
|
+
s = asrc; util.slice_int16_le!(s).must_equal 0x0201; s.must_equal asrc[2..-1]
|
130
|
+
s = msrc; util.slice_int16_le!(s).must_equal 0xf2f1; s.must_equal msrc[2..-1]
|
131
|
+
s = asrc; util.slice_sint16_le!(s).must_equal 0x0201; s.must_equal asrc[2..-1]
|
132
|
+
s = msrc; util.slice_sint16_le!(s).must_equal(-3343); s.must_equal msrc[2..-1]
|
133
|
+
|
134
|
+
s = asrc; util.slice_int16_be!(s).must_equal 0x0102; s.must_equal asrc[2..-1]
|
135
|
+
s = msrc; util.slice_int16_be!(s).must_equal 0xf1f2; s.must_equal msrc[2..-1]
|
136
|
+
s = asrc; util.slice_sint16_be!(s).must_equal 0x0102; s.must_equal asrc[2..-1]
|
137
|
+
s = msrc; util.slice_sint16_be!(s).must_equal(-3598); s.must_equal msrc[2..-1]
|
138
|
+
|
139
|
+
s = asrc; util.slice_int24_le!(s).must_equal 0x030201; s.must_equal asrc[3..-1]
|
140
|
+
s = msrc; util.slice_int24_le!(s).must_equal 0xf3f2f1; s.must_equal msrc[3..-1]
|
141
|
+
s = asrc; util.slice_sint24_le!(s).must_equal 0x030201; s.must_equal asrc[3..-1]
|
142
|
+
s = msrc; util.slice_sint24_le!(s).must_equal(-789775); s.must_equal msrc[3..-1]
|
143
|
+
|
144
|
+
s = asrc; util.slice_int24_be!(s).must_equal 0x010203; s.must_equal asrc[3..-1]
|
145
|
+
s = msrc; util.slice_int24_be!(s).must_equal 0xf1f2f3; s.must_equal msrc[3..-1]
|
146
|
+
s = asrc; util.slice_sint24_be!(s).must_equal 0x010203; s.must_equal asrc[3..-1]
|
147
|
+
s = msrc; util.slice_sint24_be!(s).must_equal(-920845); s.must_equal msrc[3..-1]
|
148
|
+
|
149
|
+
s = asrc; util.slice_int32_le!(s).must_equal 0x04030201; s.must_equal asrc[4..-1]
|
150
|
+
s = msrc; util.slice_int32_le!(s).must_equal 0xf4f3f2f1; s.must_equal msrc[4..-1]
|
151
|
+
s = asrc; util.slice_sint32_le!(s).must_equal 0x04030201; s.must_equal asrc[4..-1]
|
152
|
+
s = msrc; util.slice_sint32_le!(s).must_equal(-185339151); s.must_equal msrc[4..-1]
|
153
|
+
|
154
|
+
s = asrc; util.slice_int32_be!(s).must_equal 0x01020304; s.must_equal asrc[4..-1]
|
155
|
+
s = msrc; util.slice_int32_be!(s).must_equal 0xf1f2f3f4; s.must_equal msrc[4..-1]
|
156
|
+
s = asrc; util.slice_sint32_be!(s).must_equal 0x01020304; s.must_equal asrc[4..-1]
|
157
|
+
s = msrc; util.slice_sint32_be!(s).must_equal(-235736076); s.must_equal msrc[4..-1]
|
158
|
+
|
159
|
+
s = asrc; util.slice_int40_le!(s).must_equal 0x0504030201; s.must_equal asrc[5..-1]
|
160
|
+
s = msrc; util.slice_int40_le!(s).must_equal 0xf5f4f3f2f1; s.must_equal msrc[5..-1]
|
161
|
+
s = asrc; util.slice_sint40_le!(s).must_equal 0x0504030201; s.must_equal asrc[5..-1]
|
162
|
+
s = msrc; util.slice_sint40_le!(s).must_equal(-43135012111); s.must_equal msrc[5..-1]
|
163
|
+
|
164
|
+
s = asrc; util.slice_int40_be!(s).must_equal 0x0102030405; s.must_equal asrc[5..-1]
|
165
|
+
s = msrc; util.slice_int40_be!(s).must_equal 0xf1f2f3f4f5; s.must_equal msrc[5..-1]
|
166
|
+
s = asrc; util.slice_sint40_be!(s).must_equal 0x0102030405; s.must_equal asrc[5..-1]
|
167
|
+
s = msrc; util.slice_sint40_be!(s).must_equal(-60348435211); s.must_equal msrc[5..-1]
|
168
|
+
|
169
|
+
s = asrc; util.slice_int48_le!(s).must_equal 0x060504030201; s.must_equal asrc[6..-1]
|
170
|
+
s = msrc; util.slice_int48_le!(s).must_equal 0xf6f5f4f3f2f1; s.must_equal msrc[6..-1]
|
171
|
+
s = asrc; util.slice_sint48_le!(s).must_equal 0x060504030201; s.must_equal asrc[6..-1]
|
172
|
+
s = msrc; util.slice_sint48_le!(s).must_equal(-9938739662095); s.must_equal msrc[6..-1]
|
173
|
+
|
174
|
+
s = asrc; util.slice_int48_be!(s).must_equal 0x010203040506; s.must_equal asrc[6..-1]
|
175
|
+
s = msrc; util.slice_int48_be!(s).must_equal 0xf1f2f3f4f5f6; s.must_equal msrc[6..-1]
|
176
|
+
s = asrc; util.slice_sint48_be!(s).must_equal 0x010203040506; s.must_equal asrc[6..-1]
|
177
|
+
s = msrc; util.slice_sint48_be!(s).must_equal(-15449199413770); s.must_equal msrc[6..-1]
|
178
|
+
|
179
|
+
s = asrc; util.slice_int56_le!(s).must_equal 0x07060504030201; s.must_equal asrc[7..-1]
|
180
|
+
s = msrc; util.slice_int56_le!(s).must_equal 0xf7f6f5f4f3f2f1; s.must_equal msrc[7..-1]
|
181
|
+
s = asrc; util.slice_sint56_le!(s).must_equal 0x07060504030201; s.must_equal asrc[7..-1]
|
182
|
+
s = msrc; util.slice_sint56_le!(s).must_equal(-2261738553347343); s.must_equal msrc[7..-1]
|
183
|
+
|
184
|
+
s = asrc; util.slice_int56_be!(s).must_equal 0x01020304050607; s.must_equal asrc[7..-1]
|
185
|
+
s = msrc; util.slice_int56_be!(s).must_equal 0xf1f2f3f4f5f6f7; s.must_equal msrc[7..-1]
|
186
|
+
s = asrc; util.slice_sint56_be!(s).must_equal 0x01020304050607; s.must_equal asrc[7..-1]
|
187
|
+
s = msrc; util.slice_sint56_be!(s).must_equal(-3954995049924873); s.must_equal msrc[7..-1]
|
188
|
+
|
189
|
+
s = asrc; util.slice_int64_le!(s).must_equal 0x0807060504030201; s.must_equal asrc[8..-1]
|
190
|
+
s = msrc; util.slice_int64_le!(s).must_equal 0xf8f7f6f5f4f3f2f1; s.must_equal msrc[8..-1]
|
191
|
+
s = asrc; util.slice_sint64_le!(s).must_equal 0x0807060504030201; s.must_equal asrc[8..-1]
|
192
|
+
s = msrc; util.slice_sint64_le!(s).must_equal(-506664896818842895); s.must_equal msrc[8..-1]
|
193
|
+
|
194
|
+
s = asrc; util.slice_int64_be!(s).must_equal 0x0102030405060708; s.must_equal asrc[8..-1]
|
195
|
+
s = msrc; util.slice_int64_be!(s).must_equal 0xf1f2f3f4f5f6f7f8; s.must_equal msrc[8..-1]
|
196
|
+
s = asrc; util.slice_sint64_be!(s).must_equal 0x0102030405060708; s.must_equal asrc[8..-1]
|
197
|
+
s = msrc; util.slice_sint64_be!(s).must_equal(-1012478732780767240); s.must_equal msrc[8..-1]
|
198
|
+
|
199
|
+
s = "\x01\x02\x03\x04"; util.slice_ber!(s).must_equal 1; s.must_equal "\x02\x03\x04"
|
200
|
+
s = "\xf1\x02\x03\x04"; util.slice_ber!(s).must_equal 14466; s.must_equal "\x03\x04"
|
201
|
+
s = "\xf1\xf2\x03\x04"; util.slice_ber!(s).must_equal 1865987; s.must_equal "\x04"
|
202
|
+
s = "\xf1\xf2\xf3\x04"; util.slice_ber!(s).must_equal 238860676; s.must_equal ""
|
203
|
+
end
|
204
|
+
|
205
|
+
it "must append integer" do
|
206
|
+
d = dest; util.append_int8!(d, 0x03); d.must_equal "\x01\x02\x03"
|
207
|
+
d = dest; util.append_int8!(d, 0xf3); d.must_equal "\x01\x02\xf3".force_encoding('binary')
|
208
|
+
d = dest; util.append_int8!(d, -13); d.must_equal "\x01\x02\xf3".force_encoding('binary')
|
209
|
+
|
210
|
+
d = dest; util.append_int16_le!(d, 0x0403); d.must_equal "\x01\x02\x03\x04"
|
211
|
+
d = dest; util.append_int16_le!(d, 0xf4f3); d.must_equal "\x01\x02\xf3\xf4".force_encoding('binary')
|
212
|
+
d = dest; util.append_int16_le!(d, -2829); d.must_equal "\x01\x02\xf3\xf4".force_encoding('binary')
|
213
|
+
|
214
|
+
d = dest; util.append_int16_be!(d, 0x0304); d.must_equal "\x01\x02\x03\x04"
|
215
|
+
d = dest; util.append_int16_be!(d, 0xf3f4); d.must_equal "\x01\x02\xf3\xf4".force_encoding('binary')
|
216
|
+
d = dest; util.append_int16_be!(d, -3084); d.must_equal "\x01\x02\xf3\xf4".force_encoding('binary')
|
217
|
+
|
218
|
+
d = dest; util.append_int24_le!(d, 0x050403); d.must_equal "\x01\x02\x03\x04\x05"
|
219
|
+
d = dest; util.append_int24_le!(d, 0xf5f4f3); d.must_equal "\x01\x02\xf3\xf4\xf5".force_encoding('binary')
|
220
|
+
d = dest; util.append_int24_le!(d, -658189); d.must_equal "\x01\x02\xf3\xf4\xf5".force_encoding('binary')
|
221
|
+
|
222
|
+
d = dest; util.append_int24_be!(d, 0x030405); d.must_equal "\x01\x02\x03\x04\x05"
|
223
|
+
d = dest; util.append_int24_be!(d, 0xf3f4f5); d.must_equal "\x01\x02\xf3\xf4\xf5".force_encoding('binary')
|
224
|
+
d = dest; util.append_int24_be!(d, -789259); d.must_equal "\x01\x02\xf3\xf4\xf5".force_encoding('binary')
|
225
|
+
|
226
|
+
d = dest; util.append_int32_le!(d, 0x06050403); d.must_equal "\x01\x02\x03\x04\x05\x06"
|
227
|
+
d = dest; util.append_int32_le!(d, 0xf6f5f4f3); d.must_equal "\x01\x02\xf3\xf4\xf5\xf6".force_encoding('binary')
|
228
|
+
d = dest; util.append_int32_le!(d, -151653133); d.must_equal "\x01\x02\xf3\xf4\xf5\xf6".force_encoding('binary')
|
229
|
+
|
230
|
+
d = dest; util.append_int32_be!(d, 0x03040506); d.must_equal "\x01\x02\x03\x04\x05\x06"
|
231
|
+
d = dest; util.append_int32_be!(d, 0xf3f4f5f6); d.must_equal "\x01\x02\xf3\xf4\xf5\xf6".force_encoding('binary')
|
232
|
+
d = dest; util.append_int32_be!(d, -202050058); d.must_equal "\x01\x02\xf3\xf4\xf5\xf6".force_encoding('binary')
|
233
|
+
|
234
|
+
d = dest; util.append_int40_le!(d, 0x0706050403); d.must_equal "\x01\x02\x03\x04\x05\x06\x07"
|
235
|
+
d = dest; util.append_int40_le!(d, 0xf7f6f5f4f3); d.must_equal "\x01\x02\xf3\xf4\xf5\xf6\xf7".force_encoding('binary')
|
236
|
+
d = dest; util.append_int40_le!(d, -34511391501); d.must_equal "\x01\x02\xf3\xf4\xf5\xf6\xf7".force_encoding('binary')
|
237
|
+
|
238
|
+
d = dest; util.append_int40_be!(d, 0x0304050607); d.must_equal "\x01\x02\x03\x04\x05\x06\x07"
|
239
|
+
d = dest; util.append_int40_be!(d, 0xf3f4f5f6f7); d.must_equal "\x01\x02\xf3\xf4\xf5\xf6\xf7".force_encoding('binary')
|
240
|
+
d = dest; util.append_int40_be!(d, -51724814601); d.must_equal "\x01\x02\xf3\xf4\xf5\xf6\xf7".force_encoding('binary')
|
241
|
+
|
242
|
+
d = dest; util.append_int48_le!(d, 0x080706050403); d.must_equal "\x01\x02\x03\x04\x05\x06\x07\x08"
|
243
|
+
d = dest; util.append_int48_le!(d, 0xf8f7f6f5f4f3); d.must_equal "\x01\x02\xf3\xf4\xf5\xf6\xf7\xf8".force_encoding('binary')
|
244
|
+
d = dest; util.append_int48_le!(d, -7731092785933); d.must_equal "\x01\x02\xf3\xf4\xf5\xf6\xf7\xf8".force_encoding('binary')
|
245
|
+
|
246
|
+
d = dest; util.append_int48_be!(d, 0x030405060708); d.must_equal "\x01\x02\x03\x04\x05\x06\x07\x08"
|
247
|
+
d = dest; util.append_int48_be!(d, 0xf3f4f5f6f7f8); d.must_equal "\x01\x02\xf3\xf4\xf5\xf6\xf7\xf8".force_encoding('binary')
|
248
|
+
d = dest; util.append_int48_be!(d, -13241552537608); d.must_equal "\x01\x02\xf3\xf4\xf5\xf6\xf7\xf8".force_encoding('binary')
|
249
|
+
|
250
|
+
d = dest; util.append_int56_le!(d, 0x09080706050403); d.must_equal "\x01\x02\x03\x04\x05\x06\x07\x08\x09"
|
251
|
+
d = dest; util.append_int56_le!(d, 0xf9f8f7f6f5f4f3); d.must_equal "\x01\x02\xf3\xf4\xf5\xf6\xf7\xf8\xf9".force_encoding('binary')
|
252
|
+
d = dest; util.append_int56_le!(d, -1696580953049869); d.must_equal "\x01\x02\xf3\xf4\xf5\xf6\xf7\xf8\xf9".force_encoding('binary')
|
253
|
+
|
254
|
+
d = dest; util.append_int56_be!(d, 0x03040506070809); d.must_equal "\x01\x02\x03\x04\x05\x06\x07\x08\x09"
|
255
|
+
d = dest; util.append_int56_be!(d, 0xf3f4f5f6f7f8f9); d.must_equal "\x01\x02\xf3\xf4\xf5\xf6\xf7\xf8\xf9".force_encoding('binary')
|
256
|
+
d = dest; util.append_int56_be!(d, -3389837449627399); d.must_equal "\x01\x02\xf3\xf4\xf5\xf6\xf7\xf8\xf9".force_encoding('binary')
|
257
|
+
|
258
|
+
d = dest; util.append_int64_le!(d, 0x0a09080706050403); d.must_equal "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a"
|
259
|
+
d = dest; util.append_int64_le!(d, 0xfaf9f8f7f6f5f4f3); d.must_equal "\x01\x02\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa".force_encoding('binary')
|
260
|
+
d = dest; util.append_int64_le!(d, -361984551142689549); d.must_equal "\x01\x02\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa".force_encoding('binary')
|
261
|
+
|
262
|
+
d = dest; util.append_int64_be!(d, 0x030405060708090a); d.must_equal "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a"
|
263
|
+
d = dest; util.append_int64_be!(d, 0xf3f4f5f6f7f8f9fa); d.must_equal "\x01\x02\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa".force_encoding('binary')
|
264
|
+
d = dest; util.append_int64_be!(d, -867798387104613894); d.must_equal "\x01\x02\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa".force_encoding('binary')
|
265
|
+
|
266
|
+
d = dest; util.append_ber!(d, 3); d.must_equal "\x01\x02\x03"
|
267
|
+
d = dest; util.append_ber!(d, 14724); d.must_equal "\x01\x02\xf3\x04".force_encoding('binary')
|
268
|
+
d = dest; util.append_ber!(d, 1899013); d.must_equal "\x01\x02\xf3\xf4\x05".force_encoding('binary')
|
269
|
+
d = dest; util.append_ber!(d, 243088006); d.must_equal "\x01\x02\xf3\xf4\xf5\x06".force_encoding('binary')
|
270
|
+
end
|
271
|
+
|
272
|
+
it "must append bersize and integer" do
|
273
|
+
d = dest; util.append_bersize_int8!(d, 0x03); d.must_equal "\x01\x02\x01\x03"
|
274
|
+
d = dest; util.append_bersize_int8!(d, 0xf3); d.must_equal "\x01\x02\x01\xf3".force_encoding('binary')
|
275
|
+
d = dest; util.append_bersize_int8!(d, -13); d.must_equal "\x01\x02\x01\xf3".force_encoding('binary')
|
276
|
+
|
277
|
+
d = dest; util.append_bersize_int16_le!(d, 0x0403); d.must_equal "\x01\x02\x02\x03\x04"
|
278
|
+
d = dest; util.append_bersize_int16_le!(d, 0xf4f3); d.must_equal "\x01\x02\x02\xf3\xf4".force_encoding('binary')
|
279
|
+
d = dest; util.append_bersize_int16_le!(d, -2829); d.must_equal "\x01\x02\x02\xf3\xf4".force_encoding('binary')
|
280
|
+
|
281
|
+
d = dest; util.append_bersize_int16_be!(d, 0x0304); d.must_equal "\x01\x02\x02\x03\x04"
|
282
|
+
d = dest; util.append_bersize_int16_be!(d, 0xf3f4); d.must_equal "\x01\x02\x02\xf3\xf4".force_encoding('binary')
|
283
|
+
d = dest; util.append_bersize_int16_be!(d, -3084); d.must_equal "\x01\x02\x02\xf3\xf4".force_encoding('binary')
|
284
|
+
|
285
|
+
d = dest; util.append_bersize_int24_le!(d, 0x050403); d.must_equal "\x01\x02\x03\x03\x04\x05"
|
286
|
+
d = dest; util.append_bersize_int24_le!(d, 0xf5f4f3); d.must_equal "\x01\x02\x03\xf3\xf4\xf5".force_encoding('binary')
|
287
|
+
d = dest; util.append_bersize_int24_le!(d, -658189); d.must_equal "\x01\x02\x03\xf3\xf4\xf5".force_encoding('binary')
|
288
|
+
|
289
|
+
d = dest; util.append_bersize_int24_be!(d, 0x030405); d.must_equal "\x01\x02\x03\x03\x04\x05"
|
290
|
+
d = dest; util.append_bersize_int24_be!(d, 0xf3f4f5); d.must_equal "\x01\x02\x03\xf3\xf4\xf5".force_encoding('binary')
|
291
|
+
d = dest; util.append_bersize_int24_be!(d, -789259); d.must_equal "\x01\x02\x03\xf3\xf4\xf5".force_encoding('binary')
|
292
|
+
|
293
|
+
d = dest; util.append_bersize_int32_le!(d, 0x06050403); d.must_equal "\x01\x02\x04\x03\x04\x05\x06"
|
294
|
+
d = dest; util.append_bersize_int32_le!(d, 0xf6f5f4f3); d.must_equal "\x01\x02\x04\xf3\xf4\xf5\xf6".force_encoding('binary')
|
295
|
+
d = dest; util.append_bersize_int32_le!(d, -151653133); d.must_equal "\x01\x02\x04\xf3\xf4\xf5\xf6".force_encoding('binary')
|
296
|
+
|
297
|
+
d = dest; util.append_bersize_int32_be!(d, 0x03040506); d.must_equal "\x01\x02\x04\x03\x04\x05\x06"
|
298
|
+
d = dest; util.append_bersize_int32_be!(d, 0xf3f4f5f6); d.must_equal "\x01\x02\x04\xf3\xf4\xf5\xf6".force_encoding('binary')
|
299
|
+
d = dest; util.append_bersize_int32_be!(d, -202050058); d.must_equal "\x01\x02\x04\xf3\xf4\xf5\xf6".force_encoding('binary')
|
300
|
+
|
301
|
+
d = dest; util.append_bersize_int40_le!(d, 0x0706050403); d.must_equal "\x01\x02\x05\x03\x04\x05\x06\x07"
|
302
|
+
d = dest; util.append_bersize_int40_le!(d, 0xf7f6f5f4f3); d.must_equal "\x01\x02\x05\xf3\xf4\xf5\xf6\xf7".force_encoding('binary')
|
303
|
+
d = dest; util.append_bersize_int40_le!(d, -34511391501); d.must_equal "\x01\x02\x05\xf3\xf4\xf5\xf6\xf7".force_encoding('binary')
|
304
|
+
|
305
|
+
d = dest; util.append_bersize_int40_be!(d, 0x0304050607); d.must_equal "\x01\x02\x05\x03\x04\x05\x06\x07"
|
306
|
+
d = dest; util.append_bersize_int40_be!(d, 0xf3f4f5f6f7); d.must_equal "\x01\x02\x05\xf3\xf4\xf5\xf6\xf7".force_encoding('binary')
|
307
|
+
d = dest; util.append_bersize_int40_be!(d, -51724814601); d.must_equal "\x01\x02\x05\xf3\xf4\xf5\xf6\xf7".force_encoding('binary')
|
308
|
+
|
309
|
+
d = dest; util.append_bersize_int48_le!(d, 0x080706050403); d.must_equal "\x01\x02\x06\x03\x04\x05\x06\x07\x08"
|
310
|
+
d = dest; util.append_bersize_int48_le!(d, 0xf8f7f6f5f4f3); d.must_equal "\x01\x02\x06\xf3\xf4\xf5\xf6\xf7\xf8".force_encoding('binary')
|
311
|
+
d = dest; util.append_bersize_int48_le!(d, -7731092785933); d.must_equal "\x01\x02\x06\xf3\xf4\xf5\xf6\xf7\xf8".force_encoding('binary')
|
312
|
+
|
313
|
+
d = dest; util.append_bersize_int48_be!(d, 0x030405060708); d.must_equal "\x01\x02\x06\x03\x04\x05\x06\x07\x08"
|
314
|
+
d = dest; util.append_bersize_int48_be!(d, 0xf3f4f5f6f7f8); d.must_equal "\x01\x02\x06\xf3\xf4\xf5\xf6\xf7\xf8".force_encoding('binary')
|
315
|
+
d = dest; util.append_bersize_int48_be!(d, -13241552537608); d.must_equal "\x01\x02\x06\xf3\xf4\xf5\xf6\xf7\xf8".force_encoding('binary')
|
316
|
+
|
317
|
+
d = dest; util.append_bersize_int56_le!(d, 0x09080706050403); d.must_equal "\x01\x02\x07\x03\x04\x05\x06\x07\x08\x09"
|
318
|
+
d = dest; util.append_bersize_int56_le!(d, 0xf9f8f7f6f5f4f3); d.must_equal "\x01\x02\x07\xf3\xf4\xf5\xf6\xf7\xf8\xf9".force_encoding('binary')
|
319
|
+
d = dest; util.append_bersize_int56_le!(d, -1696580953049869); d.must_equal "\x01\x02\x07\xf3\xf4\xf5\xf6\xf7\xf8\xf9".force_encoding('binary')
|
320
|
+
|
321
|
+
d = dest; util.append_bersize_int56_be!(d, 0x03040506070809); d.must_equal "\x01\x02\x07\x03\x04\x05\x06\x07\x08\x09"
|
322
|
+
d = dest; util.append_bersize_int56_be!(d, 0xf3f4f5f6f7f8f9); d.must_equal "\x01\x02\x07\xf3\xf4\xf5\xf6\xf7\xf8\xf9".force_encoding('binary')
|
323
|
+
d = dest; util.append_bersize_int56_be!(d, -3389837449627399); d.must_equal "\x01\x02\x07\xf3\xf4\xf5\xf6\xf7\xf8\xf9".force_encoding('binary')
|
324
|
+
|
325
|
+
d = dest; util.append_bersize_int64_le!(d, 0x0a09080706050403); d.must_equal "\x01\x02\x08\x03\x04\x05\x06\x07\x08\x09\x0a"
|
326
|
+
d = dest; util.append_bersize_int64_le!(d, 0xfaf9f8f7f6f5f4f3); d.must_equal "\x01\x02\x08\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa".force_encoding('binary')
|
327
|
+
d = dest; util.append_bersize_int64_le!(d, -361984551142689549); d.must_equal "\x01\x02\x08\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa".force_encoding('binary')
|
328
|
+
|
329
|
+
d = dest; util.append_bersize_int64_be!(d, 0x030405060708090a); d.must_equal "\x01\x02\x08\x03\x04\x05\x06\x07\x08\x09\x0a"
|
330
|
+
d = dest; util.append_bersize_int64_be!(d, 0xf3f4f5f6f7f8f9fa); d.must_equal "\x01\x02\x08\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa".force_encoding('binary')
|
331
|
+
d = dest; util.append_bersize_int64_be!(d, -867798387104613894); d.must_equal "\x01\x02\x08\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa".force_encoding('binary')
|
332
|
+
|
333
|
+
d = dest; util.append_bersize_ber!(d, 3); d.must_equal "\x01\x02\x01\x03"
|
334
|
+
d = dest; util.append_bersize_ber!(d, 14724); d.must_equal "\x01\x02\x02\xf3\x04".force_encoding('binary')
|
335
|
+
d = dest; util.append_bersize_ber!(d, 1899013); d.must_equal "\x01\x02\x03\xf3\xf4\x05".force_encoding('binary')
|
336
|
+
d = dest; util.append_bersize_ber!(d, 243088006); d.must_equal "\x01\x02\x04\xf3\xf4\xf5\x06".force_encoding('binary')
|
337
|
+
end
|
338
|
+
|
339
|
+
it "must append int32size little endian and integer" do
|
340
|
+
d = dest; util.append_int32size_int8_le!(d, 0x03); d.must_equal "\x01\x02\x01\x00\x00\x00\x03"
|
341
|
+
d = dest; util.append_int32size_int8_le!(d, 0xf3); d.must_equal "\x01\x02\x01\x00\x00\x00\xf3".force_encoding('binary')
|
342
|
+
d = dest; util.append_int32size_int8_le!(d, -13); d.must_equal "\x01\x02\x01\x00\x00\x00\xf3".force_encoding('binary')
|
343
|
+
|
344
|
+
d = dest; util.append_int32size_int16_le!(d, 0x0403); d.must_equal "\x01\x02\x02\x00\x00\x00\x03\x04"
|
345
|
+
d = dest; util.append_int32size_int16_le!(d, 0xf4f3); d.must_equal "\x01\x02\x02\x00\x00\x00\xf3\xf4".force_encoding('binary')
|
346
|
+
d = dest; util.append_int32size_int16_le!(d, -2829); d.must_equal "\x01\x02\x02\x00\x00\x00\xf3\xf4".force_encoding('binary')
|
347
|
+
|
348
|
+
d = dest; util.append_int32size_int24_le!(d, 0x050403); d.must_equal "\x01\x02\x03\x00\x00\x00\x03\x04\x05"
|
349
|
+
d = dest; util.append_int32size_int24_le!(d, 0xf5f4f3); d.must_equal "\x01\x02\x03\x00\x00\x00\xf3\xf4\xf5".force_encoding('binary')
|
350
|
+
d = dest; util.append_int32size_int24_le!(d, -658189); d.must_equal "\x01\x02\x03\x00\x00\x00\xf3\xf4\xf5".force_encoding('binary')
|
351
|
+
|
352
|
+
d = dest; util.append_int32size_int32_le!(d, 0x06050403); d.must_equal "\x01\x02\x04\x00\x00\x00\x03\x04\x05\x06"
|
353
|
+
d = dest; util.append_int32size_int32_le!(d, 0xf6f5f4f3); d.must_equal "\x01\x02\x04\x00\x00\x00\xf3\xf4\xf5\xf6".force_encoding('binary')
|
354
|
+
d = dest; util.append_int32size_int32_le!(d, -151653133); d.must_equal "\x01\x02\x04\x00\x00\x00\xf3\xf4\xf5\xf6".force_encoding('binary')
|
355
|
+
|
356
|
+
d = dest; util.append_int32size_int40_le!(d, 0x0706050403); d.must_equal "\x01\x02\x05\x00\x00\x00\x03\x04\x05\x06\x07"
|
357
|
+
d = dest; util.append_int32size_int40_le!(d, 0xf7f6f5f4f3); d.must_equal "\x01\x02\x05\x00\x00\x00\xf3\xf4\xf5\xf6\xf7".force_encoding('binary')
|
358
|
+
d = dest; util.append_int32size_int40_le!(d, -34511391501); d.must_equal "\x01\x02\x05\x00\x00\x00\xf3\xf4\xf5\xf6\xf7".force_encoding('binary')
|
359
|
+
|
360
|
+
d = dest; util.append_int32size_int48_le!(d, 0x080706050403); d.must_equal "\x01\x02\x06\x00\x00\x00\x03\x04\x05\x06\x07\x08"
|
361
|
+
d = dest; util.append_int32size_int48_le!(d, 0xf8f7f6f5f4f3); d.must_equal "\x01\x02\x06\x00\x00\x00\xf3\xf4\xf5\xf6\xf7\xf8".force_encoding('binary')
|
362
|
+
d = dest; util.append_int32size_int48_le!(d, -7731092785933); d.must_equal "\x01\x02\x06\x00\x00\x00\xf3\xf4\xf5\xf6\xf7\xf8".force_encoding('binary')
|
363
|
+
|
364
|
+
d = dest; util.append_int32size_int56_le!(d, 0x09080706050403); d.must_equal "\x01\x02\x07\x00\x00\x00\x03\x04\x05\x06\x07\x08\x09"
|
365
|
+
d = dest; util.append_int32size_int56_le!(d, 0xf9f8f7f6f5f4f3); d.must_equal "\x01\x02\x07\x00\x00\x00\xf3\xf4\xf5\xf6\xf7\xf8\xf9".force_encoding('binary')
|
366
|
+
d = dest; util.append_int32size_int56_le!(d, -1696580953049869); d.must_equal "\x01\x02\x07\x00\x00\x00\xf3\xf4\xf5\xf6\xf7\xf8\xf9".force_encoding('binary')
|
367
|
+
|
368
|
+
d = dest; util.append_int32size_int64_le!(d, 0x0a09080706050403); d.must_equal "\x01\x02\x08\x00\x00\x00\x03\x04\x05\x06\x07\x08\x09\x0a"
|
369
|
+
d = dest; util.append_int32size_int64_le!(d, 0xfaf9f8f7f6f5f4f3); d.must_equal "\x01\x02\x08\x00\x00\x00\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa".force_encoding('binary')
|
370
|
+
d = dest; util.append_int32size_int64_le!(d, -361984551142689549); d.must_equal "\x01\x02\x08\x00\x00\x00\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa".force_encoding('binary')
|
371
|
+
|
372
|
+
d = dest; util.append_int32size_ber_le!(d, 3); d.must_equal "\x01\x02\x01\x00\x00\x00\x03"
|
373
|
+
d = dest; util.append_int32size_ber_le!(d, 14724); d.must_equal "\x01\x02\x02\x00\x00\x00\xf3\x04".force_encoding('binary')
|
374
|
+
d = dest; util.append_int32size_ber_le!(d, 1899013); d.must_equal "\x01\x02\x03\x00\x00\x00\xf3\xf4\x05".force_encoding('binary')
|
375
|
+
d = dest; util.append_int32size_ber_le!(d, 243088006); d.must_equal "\x01\x02\x04\x00\x00\x00\xf3\xf4\xf5\x06".force_encoding('binary')
|
376
|
+
end
|
377
|
+
|
378
|
+
it "must append int32size big endian and integer" do
|
379
|
+
d = dest; util.append_int32size_int8_be!(d, 0x03); d.must_equal "\x01\x02\x00\x00\x00\x01\x03"
|
380
|
+
d = dest; util.append_int32size_int8_be!(d, 0xf3); d.must_equal "\x01\x02\x00\x00\x00\x01\xf3".force_encoding('binary')
|
381
|
+
d = dest; util.append_int32size_int8_be!(d, -13); d.must_equal "\x01\x02\x00\x00\x00\x01\xf3".force_encoding('binary')
|
382
|
+
|
383
|
+
d = dest; util.append_int32size_int16_be!(d, 0x0304); d.must_equal "\x01\x02\x00\x00\x00\x02\x03\x04"
|
384
|
+
d = dest; util.append_int32size_int16_be!(d, 0xf3f4); d.must_equal "\x01\x02\x00\x00\x00\x02\xf3\xf4".force_encoding('binary')
|
385
|
+
d = dest; util.append_int32size_int16_be!(d, -3084); d.must_equal "\x01\x02\x00\x00\x00\x02\xf3\xf4".force_encoding('binary')
|
386
|
+
|
387
|
+
d = dest; util.append_int32size_int24_be!(d, 0x030405); d.must_equal "\x01\x02\x00\x00\x00\x03\x03\x04\x05"
|
388
|
+
d = dest; util.append_int32size_int24_be!(d, 0xf3f4f5); d.must_equal "\x01\x02\x00\x00\x00\x03\xf3\xf4\xf5".force_encoding('binary')
|
389
|
+
d = dest; util.append_int32size_int24_be!(d, -789259); d.must_equal "\x01\x02\x00\x00\x00\x03\xf3\xf4\xf5".force_encoding('binary')
|
390
|
+
|
391
|
+
d = dest; util.append_int32size_int32_be!(d, 0x03040506); d.must_equal "\x01\x02\x00\x00\x00\x04\x03\x04\x05\x06"
|
392
|
+
d = dest; util.append_int32size_int32_be!(d, 0xf3f4f5f6); d.must_equal "\x01\x02\x00\x00\x00\x04\xf3\xf4\xf5\xf6".force_encoding('binary')
|
393
|
+
d = dest; util.append_int32size_int32_be!(d, -202050058); d.must_equal "\x01\x02\x00\x00\x00\x04\xf3\xf4\xf5\xf6".force_encoding('binary')
|
394
|
+
|
395
|
+
d = dest; util.append_int32size_int40_be!(d, 0x0304050607); d.must_equal "\x01\x02\x00\x00\x00\x05\x03\x04\x05\x06\x07"
|
396
|
+
d = dest; util.append_int32size_int40_be!(d, 0xf3f4f5f6f7); d.must_equal "\x01\x02\x00\x00\x00\x05\xf3\xf4\xf5\xf6\xf7".force_encoding('binary')
|
397
|
+
d = dest; util.append_int32size_int40_be!(d, -51724814601); d.must_equal "\x01\x02\x00\x00\x00\x05\xf3\xf4\xf5\xf6\xf7".force_encoding('binary')
|
398
|
+
|
399
|
+
d = dest; util.append_int32size_int48_be!(d, 0x030405060708); d.must_equal "\x01\x02\x00\x00\x00\x06\x03\x04\x05\x06\x07\x08"
|
400
|
+
d = dest; util.append_int32size_int48_be!(d, 0xf3f4f5f6f7f8); d.must_equal "\x01\x02\x00\x00\x00\x06\xf3\xf4\xf5\xf6\xf7\xf8".force_encoding('binary')
|
401
|
+
d = dest; util.append_int32size_int48_be!(d, -13241552537608); d.must_equal "\x01\x02\x00\x00\x00\x06\xf3\xf4\xf5\xf6\xf7\xf8".force_encoding('binary')
|
402
|
+
|
403
|
+
d = dest; util.append_int32size_int56_be!(d, 0x03040506070809); d.must_equal "\x01\x02\x00\x00\x00\x07\x03\x04\x05\x06\x07\x08\x09"
|
404
|
+
d = dest; util.append_int32size_int56_be!(d, 0xf3f4f5f6f7f8f9); d.must_equal "\x01\x02\x00\x00\x00\x07\xf3\xf4\xf5\xf6\xf7\xf8\xf9".force_encoding('binary')
|
405
|
+
d = dest; util.append_int32size_int56_be!(d, -3389837449627399); d.must_equal "\x01\x02\x00\x00\x00\x07\xf3\xf4\xf5\xf6\xf7\xf8\xf9".force_encoding('binary')
|
406
|
+
|
407
|
+
d = dest; util.append_int32size_int64_be!(d, 0x030405060708090a); d.must_equal "\x01\x02\x00\x00\x00\x08\x03\x04\x05\x06\x07\x08\x09\x0a"
|
408
|
+
d = dest; util.append_int32size_int64_be!(d, 0xf3f4f5f6f7f8f9fa); d.must_equal "\x01\x02\x00\x00\x00\x08\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa".force_encoding('binary')
|
409
|
+
d = dest; util.append_int32size_int64_be!(d, -867798387104613894); d.must_equal "\x01\x02\x00\x00\x00\x08\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa".force_encoding('binary')
|
410
|
+
|
411
|
+
d = dest; util.append_int32size_ber_be!(d, 3); d.must_equal "\x01\x02\x00\x00\x00\x01\x03"
|
412
|
+
d = dest; util.append_int32size_ber_be!(d, 14724); d.must_equal "\x01\x02\x00\x00\x00\x02\xf3\x04".force_encoding('binary')
|
413
|
+
d = dest; util.append_int32size_ber_be!(d, 1899013); d.must_equal "\x01\x02\x00\x00\x00\x03\xf3\xf4\x05".force_encoding('binary')
|
414
|
+
d = dest; util.append_int32size_ber_be!(d, 243088006); d.must_equal "\x01\x02\x00\x00\x00\x04\xf3\xf4\xf5\x06".force_encoding('binary')
|
415
|
+
end
|
416
|
+
|
417
|
+
it "must append string" do
|
418
|
+
d = dest; util.append_string!(d, "asdfфыва"); d.must_equal "\x01\x02asdf\xD1\x84\xD1\x8B\xD0\xB2\xD0\xB0".force_encoding('binary')
|
419
|
+
d = dest; util.append_bersize_string!(d, "asdfфыва"); d.must_equal "\x01\x02\x0casdf\xD1\x84\xD1\x8B\xD0\xB2\xD0\xB0".force_encoding('binary')
|
420
|
+
d = dest; util.append_int32size_string_le!(d, "asdfфыва"); d.must_equal "\x01\x02\x0c\x00\x00\x00asdf\xD1\x84\xD1\x8B\xD0\xB2\xD0\xB0".force_encoding('binary')
|
421
|
+
d = dest; util.append_int32size_string_be!(d, "asdfфыва"); d.must_equal "\x01\x02\x00\x00\x00\x0casdf\xD1\x84\xD1\x8B\xD0\xB2\xD0\xB0".force_encoding('binary')
|
422
|
+
end
|
423
|
+
|
424
|
+
it "must append complex" do
|
425
|
+
d0 = dest; util.append_int8_ber!(d0, 5, 500)
|
426
|
+
d1 = dest; util.append_int8!(d1, 5); util.append_ber!(d1, 500)
|
427
|
+
d0.must_equal d1
|
428
|
+
d0 = dest; util.append_ber_int8!(d0, 500, 5)
|
429
|
+
d1 = dest; util.append_ber!(d1, 500); util.append_int8!(d1, 5)
|
430
|
+
d0.must_equal d1
|
431
|
+
|
432
|
+
for _e in %w{le be}
|
433
|
+
for m1 in %w{ber int8}
|
434
|
+
for m2 in %w{int16 int24 int32}
|
435
|
+
d0 = dest; util.send(:"append_#{m1}_#{m2}_#{_e}!", d0, 251, 172)
|
436
|
+
d1 = dest; util.send(:"append_#{m1}!", d1, 251); util.send(:"append_#{m2}_#{_e}!", d1, 172)
|
437
|
+
d0.must_equal d1
|
438
|
+
d0 = dest; util.send(:"append_#{m2}_#{m1}_#{_e}!", d0, 251, 172)
|
439
|
+
d1 = dest; util.send(:"append_#{m2}_#{_e}!", d1, 251); util.send(:"append_#{m1}!", d1, 172)
|
440
|
+
d0.must_equal d1
|
441
|
+
end
|
442
|
+
end
|
443
|
+
|
444
|
+
for m1 in %w{int16 int24 int32}
|
445
|
+
for m2 in %w{int16 int24 int32}
|
446
|
+
next if m1 == m2
|
447
|
+
d0 = dest; util.send(:"append_#{m1}_#{m2}_#{_e}!", d0, 254, 199)
|
448
|
+
d1 = dest; util.send(:"append_#{m1}_#{_e}!", d1, 254); util.send(:"append_#{m2}_#{_e}!", d1, 199)
|
449
|
+
d0.must_equal d1
|
450
|
+
end
|
451
|
+
end
|
452
|
+
end
|
453
|
+
end
|
454
|
+
end
|
455
|
+
|
456
|
+
require 'bin_utils/pure_ruby'
|
457
|
+
describe 'pure_ruby' do
|
458
|
+
let(:util){ BinUtils::PureRuby }
|
459
|
+
class_eval(&shared_example)
|
460
|
+
end
|
461
|
+
|
462
|
+
begin
|
463
|
+
require 'bin_utils/bin_utils'
|
464
|
+
describe 'native' do
|
465
|
+
let(:util){ BinUtils::Native }
|
466
|
+
class_eval(&shared_example)
|
467
|
+
end
|
468
|
+
rescue LoadError
|
469
|
+
puts "NO NATIVE MODULE TESTED"
|
470
|
+
end
|
471
|
+
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bin_utils
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
prerelease:
|
6
|
+
platform: java
|
7
|
+
authors:
|
8
|
+
- Sokolov Yura 'funny-falcon'
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake-compiler
|
16
|
+
version_requirements: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: !binary |-
|
21
|
+
MA==
|
22
|
+
none: false
|
23
|
+
requirement: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: !binary |-
|
28
|
+
MA==
|
29
|
+
none: false
|
30
|
+
prerelease: false
|
31
|
+
type: :development
|
32
|
+
description: utils for extracting binary integers from binary string and packing them back
|
33
|
+
email:
|
34
|
+
- funny.falcon@gmail.com
|
35
|
+
executables: []
|
36
|
+
extensions: []
|
37
|
+
extra_rdoc_files: []
|
38
|
+
files:
|
39
|
+
- lib/bin_utils.rb
|
40
|
+
- lib/bin_utils/pure_ruby.rb
|
41
|
+
- lib/bin_utils/version.rb
|
42
|
+
- test/benchmark.rb
|
43
|
+
- test/test_bin_utils.rb
|
44
|
+
- ext/bin_utils/bin_utils.jar
|
45
|
+
homepage: https://github.com/funny-falcon/bin_utils
|
46
|
+
licenses: []
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
- ext
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 1.9.1
|
57
|
+
none: false
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: !binary |-
|
63
|
+
MA==
|
64
|
+
none: false
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.8.24
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: Faster alternative to String#unpack and Array#unpack, though not as complete as those methods
|
71
|
+
test_files:
|
72
|
+
- test/benchmark.rb
|
73
|
+
- test/test_bin_utils.rb
|