bare-rb 0.1.4 → 0.1.5
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.
- checksums.yaml +4 -4
- data/lib/bare-rb.rb +9 -7
- data/lib/exceptions.rb +6 -0
- data/lib/lexer.rb +14 -14
- data/lib/parser.rb +22 -22
- data/lib/types.rb +54 -63
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e8e36acbdcc47dc92e23a029edf5fac7001fbec9bd4948549cc0e682ea238b0
|
4
|
+
data.tar.gz: 86ffe342e8f2ec768b6fb222fe3575dd35eda7500ee88cff7111056a8bd422d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 555833846daa3aa6337fb836b3a7959d656dd329c3925bceb01ab27d6f873bde95e83bf965daea90f3429c73b8659b40929f6f9e1b138a631c85966910750ee2
|
7
|
+
data.tar.gz: 0f9b6ef29fd8731c688f8507d6b141e2bb0992b0074b7118cb8b13a9263b57aad9e30becbb990c94d6cc33792abad805a3cd4a44d8deab93ee3847a8de57e68a
|
data/lib/bare-rb.rb
CHANGED
@@ -6,8 +6,8 @@ require_relative "parser"
|
|
6
6
|
class Bare
|
7
7
|
def self.encode(msg, schema, type=nil)
|
8
8
|
if schema.is_a?(Bare::Schema)
|
9
|
-
raise NoTypeProvided("To encode with a schema as opposed to a raw type you must specify which type in the
|
10
|
-
|
9
|
+
raise NoTypeProvided("To encode with a schema as opposed to a raw type you must specify which type in the schema you want to encode as a symbol.\nBare.encode(msg, schema, :Type)") if type.nil?
|
10
|
+
schema[type].encode(msg)
|
11
11
|
else
|
12
12
|
schema.encode(msg)
|
13
13
|
end
|
@@ -16,9 +16,11 @@ class Bare
|
|
16
16
|
def self.decode(msg, schema, type=nil)
|
17
17
|
if schema.is_a?(Bare::Schema)
|
18
18
|
raise NoTypeProvided("To decode with a schema as opposed to a raw type you must specify which type in the same you want to encode as a symbol.\nBare.encode(msg, schema, :Type)") if type.nil?
|
19
|
-
|
19
|
+
value, rest = schema[type].decode(msg)
|
20
|
+
value
|
20
21
|
else
|
21
|
-
schema.decode(msg)
|
22
|
+
value, rest = schema.decode(msg)
|
23
|
+
return value
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
@@ -34,10 +36,9 @@ class Bare
|
|
34
36
|
end
|
35
37
|
|
36
38
|
class Schema
|
37
|
-
|
38
39
|
def ==(otherSchema)
|
39
40
|
return false unless otherSchema.is_a?(Bare::Schema)
|
40
|
-
|
41
|
+
@types == otherSchema.types
|
41
42
|
end
|
42
43
|
|
43
44
|
def types
|
@@ -54,8 +55,9 @@ class Bare
|
|
54
55
|
if @types[key].is_a?(Symbol)
|
55
56
|
@types[key] = @types[@types[key]]
|
56
57
|
else
|
57
|
-
# Users may
|
58
|
+
# Users may use symbols to reference not yet defined types
|
58
59
|
# here we recursively call our bare classes to finalize their types
|
60
|
+
# replacing Symbols like :SomeType with a reference to the other type
|
59
61
|
@types[key].finalize_references(@types)
|
60
62
|
end
|
61
63
|
end
|
data/lib/exceptions.rb
CHANGED
data/lib/lexer.rb
CHANGED
@@ -10,48 +10,48 @@ def lexer(path)
|
|
10
10
|
elsif /^\n/.match(line)
|
11
11
|
break
|
12
12
|
elsif /^ /.match(line)
|
13
|
-
line = line[1..]
|
13
|
+
line = line[1..line.size]
|
14
14
|
elsif /^</.match(line)
|
15
|
-
line = line[1..]
|
15
|
+
line = line[1..line.size]
|
16
16
|
tokens << :less_than
|
17
17
|
elsif /^>/.match(line)
|
18
|
-
line = line[1..]
|
18
|
+
line = line[1..line.size]
|
19
19
|
tokens << :greater_than
|
20
20
|
next
|
21
21
|
elsif /^{/.match(line)
|
22
|
-
line = line[1..]
|
22
|
+
line = line[1..line.size]
|
23
23
|
tokens << :open_block
|
24
24
|
elsif /^=/.match(line)
|
25
|
-
line = line[1..]
|
25
|
+
line = line[1..line.size]
|
26
26
|
tokens << :equal
|
27
27
|
elsif /^}/.match(line)
|
28
|
-
line = line[1..]
|
28
|
+
line = line[1..line.size]
|
29
29
|
tokens << :close_block
|
30
30
|
elsif /^\[/.match(line)
|
31
|
-
line = line[1..]
|
31
|
+
line = line[1..line.size]
|
32
32
|
tokens << :open_brace
|
33
33
|
elsif /^\]/.match(line)
|
34
|
-
line = line[1..]
|
34
|
+
line = line[1..line.size]
|
35
35
|
tokens << :close_brace
|
36
36
|
elsif /^\(/.match(line)
|
37
|
-
line = line[1..]
|
37
|
+
line = line[1..line.size]
|
38
38
|
tokens << :open_paren
|
39
39
|
elsif /^\)/.match(line)
|
40
|
-
line = line[1..]
|
40
|
+
line = line[1..line.size]
|
41
41
|
tokens << :close_paren
|
42
42
|
elsif /^\|/.match(line)
|
43
|
-
line = line[1..]
|
43
|
+
line = line[1..line.size]
|
44
44
|
tokens << :bar
|
45
45
|
elsif match = /^([0-9]+)/.match(line)
|
46
46
|
tokens << match[0].to_i
|
47
|
-
line = line[(match[0].size)..]
|
47
|
+
line = line[(match[0].size)..line.size]
|
48
48
|
next
|
49
49
|
elsif match = /^[a-z,A-Z,_][_,a-z,A-Z,0-9]+/.match(line)
|
50
50
|
tokens << match[0]
|
51
|
-
line = line[(match[0].size)..]
|
51
|
+
line = line[(match[0].size)..line.size]
|
52
52
|
elsif /:/.match(line)
|
53
53
|
tokens << :colon
|
54
|
-
line = line[1..]
|
54
|
+
line = line[1..line.size]
|
55
55
|
else
|
56
56
|
raise SchemaParsingException.new("Unable to lex line #{line_num} near #{line.inspect}")
|
57
57
|
end
|
data/lib/parser.rb
CHANGED
@@ -38,15 +38,15 @@ class Parser
|
|
38
38
|
name = tokens[0]
|
39
39
|
int_repr = tokens[2]
|
40
40
|
enum_hash[int_repr] = name
|
41
|
-
tokens = tokens[3..]
|
41
|
+
tokens = tokens[3..tokens.size]
|
42
42
|
else
|
43
43
|
enum_hash[count] = tokens[0]
|
44
44
|
count += 1
|
45
|
-
tokens = tokens[1..]
|
45
|
+
tokens = tokens[1..tokens.size]
|
46
46
|
end
|
47
47
|
end
|
48
48
|
enum = Bare.Enum(enum_hash)
|
49
|
-
return tokens[1..], enum
|
49
|
+
return tokens[1..tokens.size], enum
|
50
50
|
end
|
51
51
|
|
52
52
|
def parse_union(tokens)
|
@@ -55,13 +55,13 @@ class Parser
|
|
55
55
|
# type A_UNION ( int | uint | data = 7 | f32 )
|
56
56
|
while tokens[0] != :close_paren
|
57
57
|
if tokens[0] == :bar
|
58
|
-
tokens = tokens[1..]
|
58
|
+
tokens = tokens[1..tokens.size]
|
59
59
|
else
|
60
60
|
if tokens[1] == :equal
|
61
61
|
raise SchemaParsingException.new("Equals sign in union must be followed by a number") unless tokens[2].is_a?(Numeric)
|
62
62
|
count = tokens[2]
|
63
63
|
tokens, type = self.parse(tokens)
|
64
|
-
tokens = tokens[2..]
|
64
|
+
tokens = tokens[2..tokens.size]
|
65
65
|
union_hash[count] = type
|
66
66
|
count += 1
|
67
67
|
else
|
@@ -78,63 +78,63 @@ class Parser
|
|
78
78
|
struct_fields = {}
|
79
79
|
while tokens.size >= 2 and tokens[1] == :colon
|
80
80
|
name = tokens[0]
|
81
|
-
tokens, type = self.parse(tokens[2..])
|
81
|
+
tokens, type = self.parse(tokens[2..tokens.size])
|
82
82
|
struct_fields[name.to_sym] = type
|
83
83
|
end
|
84
|
-
return tokens[1..], struct_fields
|
84
|
+
return tokens[1..tokens.size], struct_fields
|
85
85
|
end
|
86
86
|
|
87
87
|
def parse(tokens)
|
88
88
|
while tokens.size > 0
|
89
89
|
if tokens[0] == "type"
|
90
90
|
name = tokens[1]
|
91
|
-
tokens, type = self.parse(tokens[2..])
|
91
|
+
tokens, type = self.parse(tokens[2..tokens.size])
|
92
92
|
@definitions[name.to_sym] = type
|
93
93
|
elsif tokens[0] == "map"
|
94
94
|
raise SchemaParsingException.new("Map must be followed by a '[' eg. map[string]data") if tokens[1] != :open_brace
|
95
|
-
tokens, map_from_type = parse(tokens[2..])
|
95
|
+
tokens, map_from_type = parse(tokens[2..tokens.size])
|
96
96
|
raise SchemaParsingException.new("Map to type must be followed by a ']' eg. map[string]data") if tokens[0] != :close_brace
|
97
|
-
tokens, map_to_type = parse(tokens[1..])
|
97
|
+
tokens, map_to_type = parse(tokens[1..tokens.size])
|
98
98
|
return tokens, Bare.Map(map_from_type, map_to_type)
|
99
99
|
elsif tokens[0] == "data" && tokens.size > 3 && tokens[1] == :less_than
|
100
100
|
raise SchemaParsingException.new("data< must be followed by a number for a fixed sized bare data") unless tokens[2].is_a?(Numeric)
|
101
101
|
raise SchemaParsingException.new("data<# must be followed by a >") unless tokens[3] == :greater_than
|
102
|
-
return tokens[4..], Bare.DataFixedLen(tokens[2])
|
102
|
+
return tokens[4..tokens.size], Bare.DataFixedLen(tokens[2])
|
103
103
|
elsif tokens[0] == "enum"
|
104
104
|
name = tokens[1]
|
105
105
|
raise SchemaParsingException.new("Enum must be followed by a '{'") if tokens[2] != :open_block
|
106
|
-
tokens, enum = parse_enum(tokens[3..])
|
106
|
+
tokens, enum = parse_enum(tokens[3..tokens.size])
|
107
107
|
@definitions[name.to_sym] = enum
|
108
108
|
elsif tokens[0] == "optional"
|
109
109
|
raise SchemaParsingException.new("Optional must be followed by a '< TYPE > you are missing the first <'") if tokens[1] != :less_than
|
110
|
-
tokens, optional_type = self.parse(tokens[2..])
|
110
|
+
tokens, optional_type = self.parse(tokens[2..tokens.size])
|
111
111
|
raise SchemaParsingException.new("Optional must be followed by a '< TYPE >' you are missing the last >") if tokens[0] != :greater_than
|
112
|
-
return tokens[1..], Bare.Optional(optional_type)
|
112
|
+
return tokens[1..tokens.size], Bare.Optional(optional_type)
|
113
113
|
elsif tokens[0] == :open_brace
|
114
114
|
if tokens[1].is_a?(Numeric)
|
115
115
|
size = tokens[1]
|
116
116
|
raise SchemaParsingException.new("Fixed Length Array size must be followed by a ']'") if tokens[2] != :close_brace
|
117
|
-
tokens, arr_type = parse(tokens[3..])
|
117
|
+
tokens, arr_type = parse(tokens[3..tokens.size])
|
118
118
|
return tokens, Bare.ArrayFixedLen(arr_type, size)
|
119
119
|
else
|
120
|
-
tokens, arr_type = parse(tokens[2..])
|
120
|
+
tokens, arr_type = parse(tokens[2..tokens.size])
|
121
121
|
return tokens, Bare.Array(arr_type)
|
122
122
|
end
|
123
123
|
elsif tokens[0] == :open_paren
|
124
|
-
tokens, union_hash = parse_union(tokens[1..])
|
124
|
+
tokens, union_hash = parse_union(tokens[1..tokens.size])
|
125
125
|
raise SchemaParsingException.new("Union must be followed by a ')'") if tokens[0] != :close_paren
|
126
|
-
return tokens[1..], Bare.Union(union_hash)
|
126
|
+
return tokens[1..tokens.size], Bare.Union(union_hash)
|
127
127
|
elsif tokens[0] == :open_block
|
128
|
-
tokens, struct_fields = parse_struct(tokens[1..])
|
128
|
+
tokens, struct_fields = parse_struct(tokens[1..tokens.size])
|
129
129
|
strct = Bare.Struct(struct_fields)
|
130
130
|
return tokens, strct
|
131
131
|
elsif @primitives.include?(tokens[0])
|
132
132
|
type = @primitives[tokens[0]]
|
133
|
-
return tokens[1..], type
|
133
|
+
return tokens[1..tokens.size], type
|
134
134
|
elsif @definitions.keys.include?(tokens[0].to_sym) # User defined type
|
135
|
-
return tokens[1..], @definitions[tokens[0].to_sym]
|
135
|
+
return tokens[1..tokens.size], @definitions[tokens[0].to_sym]
|
136
136
|
elsif tokens[0].is_a?(String) && tokens[0][0].upcase == tokens[0][0] # Not yet defined user type
|
137
|
-
return tokens[1..], tokens[0].to_sym
|
137
|
+
return tokens[1..tokens.size], tokens[0].to_sym
|
138
138
|
else
|
139
139
|
raise SchemaParsingException.new("Unable to parse token: #{tokens[0]}")
|
140
140
|
end
|
data/lib/types.rb
CHANGED
@@ -10,6 +10,7 @@ class BareTypes
|
|
10
10
|
end
|
11
11
|
|
12
12
|
class BarePrimitive < BaseType
|
13
|
+
|
13
14
|
# Types which are always equivalent to another instantiation of themselves
|
14
15
|
# Eg. Uint.new == Uint.new
|
15
16
|
# But Union.new(types1) != Union.new(types2)
|
@@ -33,10 +34,9 @@ class BareTypes
|
|
33
34
|
end
|
34
35
|
|
35
36
|
def decode(msg)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
return {value: unmapped, rest: output[:rest]}
|
37
|
+
value, rest = Uint.new.decode(msg)
|
38
|
+
value = value.odd? ? (value + 1) / -2 : value / 2
|
39
|
+
return value, rest
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -46,17 +46,17 @@ class BareTypes
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def decode(msg)
|
49
|
-
return
|
49
|
+
return nil, msg
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
53
|
class F32 < BarePrimitive
|
54
54
|
def encode(msg)
|
55
|
-
|
55
|
+
[msg].pack("e")
|
56
56
|
end
|
57
57
|
|
58
58
|
def decode(msg)
|
59
|
-
return
|
59
|
+
return msg.unpack("e")[0], msg[4..msg.size]
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
@@ -66,7 +66,7 @@ class BareTypes
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def decode(msg)
|
69
|
-
return
|
69
|
+
return msg.unpack("E")[0], msg[8..msg.size]
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
@@ -84,10 +84,9 @@ class BareTypes
|
|
84
84
|
end
|
85
85
|
|
86
86
|
def decode(msg)
|
87
|
-
|
88
|
-
|
89
|
-
string
|
90
|
-
return {value: string.force_encoding("utf-8"), rest: output[:rest][strLen..output[:rest].size]}
|
87
|
+
strLen, rest = Uint.new.decode(msg)
|
88
|
+
string = rest[0..strLen - 1]
|
89
|
+
return string.force_encoding("utf-8"), rest[strLen..rest.size]
|
91
90
|
end
|
92
91
|
end
|
93
92
|
|
@@ -119,7 +118,7 @@ class BareTypes
|
|
119
118
|
if msg.nil?
|
120
119
|
return "\x00".b
|
121
120
|
else
|
122
|
-
bytes = "\
|
121
|
+
bytes = "\x01".b
|
123
122
|
bytes << @optionalType.encode(msg)
|
124
123
|
return bytes
|
125
124
|
end
|
@@ -127,7 +126,7 @@ class BareTypes
|
|
127
126
|
|
128
127
|
def decode(msg)
|
129
128
|
if msg.unpack("C")[0] == 0
|
130
|
-
return
|
129
|
+
return nil, msg[1..msg.size]
|
131
130
|
else
|
132
131
|
return @optionalType.decode(msg[1..msg.size])
|
133
132
|
end
|
@@ -179,15 +178,13 @@ class BareTypes
|
|
179
178
|
|
180
179
|
def decode(msg)
|
181
180
|
hash = Hash.new
|
182
|
-
|
183
|
-
mapSize = output[:value]
|
181
|
+
mapSize, rest = Uint.new.decode(msg)
|
184
182
|
(mapSize - 1).to_i.downto(0) do
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
hash[key] = output[:value]
|
183
|
+
key, rest = @from.decode(rest)
|
184
|
+
value, rest = @to.decode(rest)
|
185
|
+
hash[key] = value
|
189
186
|
end
|
190
|
-
return
|
187
|
+
return hash, rest
|
191
188
|
end
|
192
189
|
end
|
193
190
|
|
@@ -244,11 +241,10 @@ class BareTypes
|
|
244
241
|
end
|
245
242
|
|
246
243
|
def decode(msg)
|
247
|
-
|
248
|
-
int = unionTypeInt[:value]
|
244
|
+
int, rest = Uint.new.decode(msg)
|
249
245
|
type = @intToType[int]
|
250
|
-
value = type.decode(
|
251
|
-
return {value:
|
246
|
+
value, rest = type.decode(rest)
|
247
|
+
return {value: value, type: type}, rest
|
252
248
|
end
|
253
249
|
end
|
254
250
|
|
@@ -270,11 +266,14 @@ class BareTypes
|
|
270
266
|
end
|
271
267
|
|
272
268
|
def encode(msg)
|
273
|
-
|
269
|
+
if msg.size != @length
|
270
|
+
raise FixedDataSizeWrong.new("Message is not proper sized for DataFixedLen should have been #{@length} but was #{msg.size}")
|
271
|
+
end
|
272
|
+
msg
|
274
273
|
end
|
275
274
|
|
276
275
|
def decode(msg)
|
277
|
-
return
|
276
|
+
return msg[0..@length], msg[@length..msg.size]
|
278
277
|
end
|
279
278
|
end
|
280
279
|
|
@@ -290,10 +289,8 @@ class BareTypes
|
|
290
289
|
end
|
291
290
|
|
292
291
|
def decode(msg)
|
293
|
-
|
294
|
-
rest
|
295
|
-
dataSize = output[:value]
|
296
|
-
return {value: rest[0..dataSize - 1], rest: rest[dataSize..]}
|
292
|
+
dataSize, rest = Uint.new.decode(msg)
|
293
|
+
return rest[0..dataSize - 1], rest[dataSize..rest.size]
|
297
294
|
end
|
298
295
|
end
|
299
296
|
|
@@ -320,7 +317,7 @@ class BareTypes
|
|
320
317
|
end
|
321
318
|
|
322
319
|
def decode(msg)
|
323
|
-
ints = msg.unpack("
|
320
|
+
ints = msg.unpack("CCCCCCCC")
|
324
321
|
relevantInts = []
|
325
322
|
i = 0
|
326
323
|
while ints[i] & 0b10000000 == 128
|
@@ -332,7 +329,7 @@ class BareTypes
|
|
332
329
|
relevantInts.each_with_index do |int, idx|
|
333
330
|
sum += int << (idx * 7)
|
334
331
|
end
|
335
|
-
return
|
332
|
+
return sum, msg[(i + 1)..msg.size]
|
336
333
|
end
|
337
334
|
end
|
338
335
|
|
@@ -342,7 +339,7 @@ class BareTypes
|
|
342
339
|
end
|
343
340
|
|
344
341
|
def decode(msg)
|
345
|
-
return
|
342
|
+
return msg[0].unpack("C")[0], msg[1..msg.size]
|
346
343
|
end
|
347
344
|
end
|
348
345
|
|
@@ -352,7 +349,7 @@ class BareTypes
|
|
352
349
|
end
|
353
350
|
|
354
351
|
def decode(msg)
|
355
|
-
return
|
352
|
+
return msg.unpack("v")[0], msg[2..msg.size]
|
356
353
|
end
|
357
354
|
end
|
358
355
|
|
@@ -362,7 +359,7 @@ class BareTypes
|
|
362
359
|
end
|
363
360
|
|
364
361
|
def decode(msg)
|
365
|
-
return
|
362
|
+
return msg.unpack("V")[0], msg[4..msg.size]
|
366
363
|
end
|
367
364
|
end
|
368
365
|
|
@@ -372,7 +369,7 @@ class BareTypes
|
|
372
369
|
end
|
373
370
|
|
374
371
|
def decode(msg)
|
375
|
-
return
|
372
|
+
return msg.unpack("Q")[0], msg[8..msg.size]
|
376
373
|
end
|
377
374
|
end
|
378
375
|
|
@@ -382,7 +379,7 @@ class BareTypes
|
|
382
379
|
end
|
383
380
|
|
384
381
|
def decode(msg)
|
385
|
-
return
|
382
|
+
return msg[0].unpack("c")[0], msg[1..msg.size]
|
386
383
|
end
|
387
384
|
end
|
388
385
|
|
@@ -392,7 +389,7 @@ class BareTypes
|
|
392
389
|
end
|
393
390
|
|
394
391
|
def decode(msg)
|
395
|
-
return
|
392
|
+
return msg.unpack('s<')[0], msg[2..msg.size]
|
396
393
|
end
|
397
394
|
end
|
398
395
|
|
@@ -402,7 +399,7 @@ class BareTypes
|
|
402
399
|
end
|
403
400
|
|
404
401
|
def decode(msg)
|
405
|
-
return
|
402
|
+
return msg.unpack('l<')[0], msg[4..msg.size]
|
406
403
|
end
|
407
404
|
end
|
408
405
|
|
@@ -412,7 +409,7 @@ class BareTypes
|
|
412
409
|
end
|
413
410
|
|
414
411
|
def decode(msg)
|
415
|
-
return
|
412
|
+
return msg.unpack('q<')[0], msg[8..msg.size]
|
416
413
|
end
|
417
414
|
end
|
418
415
|
|
@@ -422,7 +419,7 @@ class BareTypes
|
|
422
419
|
end
|
423
420
|
|
424
421
|
def decode(msg)
|
425
|
-
return
|
422
|
+
return (msg == "\x00\x00" ? false : true), msg[1..msg.size]
|
426
423
|
end
|
427
424
|
end
|
428
425
|
|
@@ -483,11 +480,10 @@ class BareTypes
|
|
483
480
|
hash = Hash.new
|
484
481
|
rest = msg
|
485
482
|
@mapping.keys.each do |symbol|
|
486
|
-
|
487
|
-
hash[symbol] =
|
488
|
-
rest = output[:rest]
|
483
|
+
value, rest = @mapping[symbol].decode(rest)
|
484
|
+
hash[symbol] = value
|
489
485
|
end
|
490
|
-
return
|
486
|
+
return hash, rest
|
491
487
|
end
|
492
488
|
end
|
493
489
|
|
@@ -524,17 +520,16 @@ class BareTypes
|
|
524
520
|
end
|
525
521
|
|
526
522
|
def decode(msg)
|
527
|
-
output = Uint.new.decode(msg)
|
528
523
|
arr = []
|
529
|
-
arrayLen =
|
524
|
+
arrayLen, rest = Uint.new.decode(msg)
|
530
525
|
lastSize = msg.size + 1 # Make sure msg size monotonically decreasing
|
531
526
|
(arrayLen - 1).downto(0) do
|
532
|
-
|
533
|
-
arr <<
|
534
|
-
break if
|
535
|
-
lastSize =
|
527
|
+
arrVal, rest = @type.decode(rest)
|
528
|
+
arr << arrVal
|
529
|
+
break if rest.nil? || rest.size == 0 || lastSize <= rest.size
|
530
|
+
lastSize = rest.size
|
536
531
|
end
|
537
|
-
return
|
532
|
+
return arr, rest
|
538
533
|
end
|
539
534
|
end
|
540
535
|
|
@@ -577,15 +572,13 @@ class BareTypes
|
|
577
572
|
return bytes
|
578
573
|
end
|
579
574
|
|
580
|
-
def decode(
|
575
|
+
def decode(rest)
|
581
576
|
array = []
|
582
|
-
rest = msg
|
583
577
|
@size.times do
|
584
|
-
|
585
|
-
|
586
|
-
array << output[:value]
|
578
|
+
arrVal, rest = @type.decode(rest)
|
579
|
+
array << arrVal
|
587
580
|
end
|
588
|
-
return
|
581
|
+
return array, rest
|
589
582
|
end
|
590
583
|
end
|
591
584
|
|
@@ -627,10 +620,8 @@ class BareTypes
|
|
627
620
|
end
|
628
621
|
|
629
622
|
def decode(msg)
|
630
|
-
|
631
|
-
|
632
|
-
rest = output[:rest]
|
633
|
-
return {value: @intToVal[value], rest: rest}
|
623
|
+
value, rest = BareTypes::Uint.new.decode(msg)
|
624
|
+
return @intToVal[value], rest
|
634
625
|
end
|
635
626
|
end
|
636
627
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bare-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nate Tracy-Amoroso
|
@@ -11,7 +11,7 @@ cert_chain: []
|
|
11
11
|
date: 2020-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: The first implementation of the BARE (Binary Application Record Encoding)
|
14
|
-
in Ruby. Includes schema parsing
|
14
|
+
in Ruby. Includes schema parsing and compatibility tests.
|
15
15
|
email: n8@u.northwestern.edu
|
16
16
|
executables: []
|
17
17
|
extensions: []
|