scale_rb 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97c7224f0e7d0a5f0d754206cee8d1d9cb5f1519c6c80e37b6c0b541aa0a4bcf
4
- data.tar.gz: 51434a46e4f46a6c91bc0859575287076b0b1457e942ceff4ea66e74c0c89132
3
+ metadata.gz: 381954b869c210f582d6d119be4efe2b0f41ab4aa783793ee1a8b5b3ae3f37fc
4
+ data.tar.gz: 474b9ae37ee03d0112f63892a10b1a7965f73987ec03f28838dc3e050d5f29cd
5
5
  SHA512:
6
- metadata.gz: 6b0e80c6756b68f75d9f42e0d65f4c3205af0f63c3d57f51f5d3abf838057cb9dfc17d87b47f277aba5f95361bedf7618d4c31680a8c09ca57cde438c3be1020
7
- data.tar.gz: 30351dad5922fffb55c37907225c19bbb1f771af842e231f18dd6ff1c43091876a70ed514536d3fbece2814528dc1b03d0c8a9a109cdb31e07bf1eed201ebf84
6
+ metadata.gz: 50ee90afbb3f5a9b27676912608dfa8de48bac33e8e19f1e21ee5db8f2aa1cf4c21f95cfca27e3bc6220481312bb57254004a8f219f6b6d1be94b295c47ffd68
7
+ data.tar.gz: 7cdedc298adc696bb5a3df76c63710c13863a86d4c066f7a9fe2767bd349cb7f71ed4f26490faa3a77abb8022144102396b407f6ce02e9d8d10c8029f754a451
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- scale_rb (0.1.2)
4
+ scale_rb (0.1.3)
5
5
  blake2b_rs (~> 0.1.2)
6
6
  xxhash
7
7
 
data/lib/codec.rb CHANGED
@@ -314,7 +314,7 @@ module ScaleRb
314
314
 
315
315
  item = items.to_a[index] # 'name' or [:name, inner_type]
316
316
  debug 'value', item.inspect
317
- return [item, remaining_bytes] if item.instance_of?(String)
317
+ return [item, bytes[1..]] if item.instance_of?(String)
318
318
 
319
319
  value, remaining_bytes = decode(item[1], bytes[1..], registry)
320
320
  [
data/lib/metadata.rb CHANGED
@@ -24,7 +24,7 @@ module Metadata
24
24
 
25
25
  TYPES = {
26
26
  'MetadataTop' => {
27
- magic_number: 'U32',
27
+ magicNumber: 'U32',
28
28
  metadata: 'Metadata'
29
29
  },
30
30
  'Metadata' => {
@@ -197,27 +197,27 @@ module PortableCodec
197
197
 
198
198
  # value:
199
199
  # {
200
- # name: the_value(Hash)
200
+ # name: v(Hash)
201
201
  # }
202
202
  # or
203
203
  # the_value(String)
204
204
  def encode_variant(variant_type, value, registry)
205
205
  variants = variant_type._get(:variants)
206
206
 
207
- if value.instance_of?(Hash)
208
- name = value.keys.first.to_s
209
- the_value = value.values.first
210
- elsif value.instance_of?(String)
211
- name = value
212
- the_value = {}
213
- else
214
- raise VariantInvalidValue, "type: #{variant_type}, value: #{value}"
215
- end
207
+ name, v = # v: item inner value
208
+ if value.instance_of?(Hash)
209
+ [value.keys.first.to_s, value.values.first]
210
+ elsif value.instance_of?(String)
211
+ [value, {}]
212
+ else
213
+ raise VariantInvalidValue, "type: #{variant_type}, value: #{value}"
214
+ end
216
215
 
217
- variant = variants.find { |v| v[:name] == name }
216
+ variant = variants.find { |var| var._get(:name) == name }
218
217
  raise VariantItemNotFound, "type: #{variant_type}, name: #{name}" if variant.nil?
218
+ raise VariantInvalidValue, "type: #{variant_type}, v: #{v}" if variant._get(:fields).length != v.length
219
219
 
220
- ScaleRb.encode_uint('u8', variant._get(:index)) + encode_composite(variant, the_value, registry)
220
+ ScaleRb.encode_uint('u8', variant._get(:index)) + encode_composite(variant, v, registry)
221
221
  end
222
222
 
223
223
  def _encode_types(ids, values, registry)
@@ -1,3 +1,3 @@
1
1
  module ScaleRb
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scale_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aki Wu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-11 00:00:00.000000000 Z
11
+ date: 2022-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: blake2b_rs