scale_rb 0.1.10 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/portable_codec.rb +21 -2
- data/lib/scale_rb/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9af24645257f5dc7c2028047ba01ef9a3d1fe4282581717cb62334a6f96f153
|
4
|
+
data.tar.gz: 8d79a47702d593158680d4fe2f5a887962fd87bc19e51e2d57b4ea6ca2ec0a9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b573f530576618d07382f3b995cc5413a564e4bf95149882cc83b6cb0d885e2adee2f903b5db0c8a14fd5b6964683b6851f6105e0c53c6bcb98e625c2991a639
|
7
|
+
data.tar.gz: efa796fe20f73749749bfd06de0f08c1d836268ddb99963775003f282eff60e15accd4d62556eaa1d01b0821447bdcb4bd8956e5445401ca562da2df1fc547f8
|
data/Gemfile.lock
CHANGED
data/lib/portable_codec.rb
CHANGED
@@ -70,7 +70,23 @@ module PortableCodec
|
|
70
70
|
def decode_array(array_type, bytes, registry)
|
71
71
|
len = array_type._get(:len)
|
72
72
|
inner_type_id = array_type._get(:type)
|
73
|
-
|
73
|
+
|
74
|
+
# check if the type of inner_type_id is a u8
|
75
|
+
if _u8?(inner_type_id, registry)
|
76
|
+
[
|
77
|
+
bytes[0...len].to_hex,
|
78
|
+
bytes[len..]
|
79
|
+
]
|
80
|
+
else
|
81
|
+
_decode_types([inner_type_id] * len, bytes, registry)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def _u8?(type_id, registry)
|
86
|
+
type = registry[type_id]
|
87
|
+
raise TypeNotFound, "id: #{type_id}" if type.nil?
|
88
|
+
|
89
|
+
type._get(:def)._get(:primitive)&.downcase == 'u8'
|
74
90
|
end
|
75
91
|
|
76
92
|
def decode_sequence(sequence_type, bytes, registry)
|
@@ -242,7 +258,10 @@ module PortableCodec
|
|
242
258
|
|
243
259
|
# if the variant item has more than one field, the value must be a hash with the same length.
|
244
260
|
# if the variant item has only one field, that means the field is a type id point to a composite. TODO: check the type's fields length
|
245
|
-
|
261
|
+
if item._get(:fields).length > 1 && item._get(:fields).length != v.length
|
262
|
+
raise VariantFieldsLengthNotMatch,
|
263
|
+
"type: #{variant_type}, \nvalue: #{v}"
|
264
|
+
end
|
246
265
|
|
247
266
|
ScaleRb.encode_uint('u8', item._get(:index)) + encode_composite(item, v, registry)
|
248
267
|
end
|
data/lib/scale_rb/version.rb
CHANGED