cbor-simple 1.1.1 → 1.2.0

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
  SHA1:
3
- metadata.gz: e5176aa2287fb35f0248f05a044ce06847472cdb
4
- data.tar.gz: 1a43f30a6df490a04aceb0abb4f0231baa891a39
3
+ metadata.gz: 697f956fd9e4ec493cbefa2c2b9fed9343b1da3e
4
+ data.tar.gz: a3d4282de9bed819127ad272abd2e7169e702a83
5
5
  SHA512:
6
- metadata.gz: 4925ff04985be8f75d08ccb04ce6a5cabe062c3c5f39d7731eddd91d7954d3199fbaa5fd3836ac1bfc3acc461b14a61ef2841beb115b23874673a485015be363
7
- data.tar.gz: 8fa857cddc5ae25cb7acfcbb72b7248c844edadb4a893336e5566e449926202eff7c77913767da03a0922403e5f8ebdc8f07f3890a10ee9a1eea76c9866d3238
6
+ metadata.gz: fc7a528ba7ba544efd22d52b4c603cd9b4d3ae2dfacecdeb0490e02fd5f891fbf168660bdfe344a0499ed620df0d39a5acd1a23c22d9294d7ab6e76f64957fdf
7
+ data.tar.gz: f96d73d5f705a43f66814326cbb3b87392a80a385a99456f214ba9e1ce30eed1856770761c105823493855917e1ae2a4f065a0a50f90a9fecaa455af28031694
data/README.md CHANGED
@@ -16,16 +16,16 @@ CBOR.load("\x18\x2a") # => 42
16
16
  You can add custom tags like this:
17
17
 
18
18
  ```ruby
19
- CBOR.register_tag 0 do |l|
20
- Time.iso8601(l.load())
19
+ CBOR.register_tag 0 do |raw|
20
+ Time.iso8601(raw)
21
21
  end
22
22
  ```
23
23
 
24
24
  And add classes for dumping:
25
25
 
26
26
  ```ruby
27
- CBOR.register_class Time, 0 do |d, val|
28
- d.dump(val.iso8601(6))
27
+ CBOR.register_class Time, 0 do |val|
28
+ val.iso8601(6)
29
29
  end
30
30
  ```
31
31
 
@@ -33,7 +33,7 @@ Custom tags can also be given as second parameter to `load`, however this should
33
33
 
34
34
  ```ruby
35
35
  # Invert values tagged with 0x26 (nonstandard!)
36
- CBOR.load("\xd8\x26\xf5", {0x26 => -> (l) { !l.load }}) # => false
36
+ CBOR.load("\xd8\x26\xf5", {0x26 => -> (raw) { !raw }}) # => false
37
37
  ```
38
38
 
39
39
  Currently supported classes:
data/lib/cbor/dumper.rb CHANGED
@@ -35,7 +35,7 @@ class CBOR::Dumper
35
35
  dump_uint(Major::MAP, val.count) + val.map{|k, v| dump(k.to_s) + dump(v)}.join
36
36
  else
37
37
  if h = @@registered_classes[val.class]
38
- dump_uint(Major::TAG, h[:tag]) + h[:block].call(self, val)
38
+ dump_uint(Major::TAG, h[:tag]) + dump(h[:block].call(val))
39
39
  else
40
40
  raise CBOR::CborError.new("dumping not supported for objects of type #{val.class} (#{val.inspect})")
41
41
  end
data/lib/cbor/loader.rb CHANGED
@@ -40,9 +40,9 @@ class CBOR::Loader
40
40
  when Major::TAG
41
41
  tag = get_uint(typeInt)
42
42
  if block = @@registered_tags[tag]
43
- block.call(self)
43
+ block.call(load)
44
44
  elsif block = @local_tags[tag]
45
- block.call(self)
45
+ block.call(load)
46
46
  else
47
47
  raise CBOR::CborError.new("Unknown tag #{tag}")
48
48
  end
data/lib/cbor/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CBOR
2
- VERSION = "1.1.1"
2
+ VERSION = "1.2.0"
3
3
  end
data/lib/cbor.rb CHANGED
@@ -36,33 +36,33 @@ module CBOR
36
36
  end
37
37
  end
38
38
 
39
- CBOR.register_class Time, CBOR::Consts::Tag::DATETIME do |d, val|
40
- d.dump(val.iso8601(6))
39
+ CBOR.register_class Time, CBOR::Consts::Tag::DATETIME do |val|
40
+ val.iso8601(6)
41
41
  end
42
42
 
43
- CBOR.register_tag CBOR::Consts::Tag::DATETIME do |l|
44
- Time.iso8601(l.load)
43
+ CBOR.register_tag CBOR::Consts::Tag::DATETIME do |raw|
44
+ Time.iso8601(raw)
45
45
  end
46
46
 
47
- CBOR.register_class BigDecimal, CBOR::Consts::Tag::DECIMAL do |d, val|
47
+ CBOR.register_class BigDecimal, CBOR::Consts::Tag::DECIMAL do |val|
48
48
  sign, significant_digits, base, exponent = val.split
49
49
  raise CBOR::CborError.new("NaN while sending BigDecimal #{val.inspect}") if sign == 0
50
50
  val = sign * significant_digits.to_i(base)
51
- d.dump([exponent - significant_digits.size, val])
51
+ [exponent - significant_digits.size, val]
52
52
  end
53
53
 
54
- CBOR.register_tag CBOR::Consts::Tag::DECIMAL do |l|
55
- arr = l.load
54
+ CBOR.register_tag CBOR::Consts::Tag::DECIMAL do |raw|
55
+ arr = raw
56
56
  raise CBOR::CborError.new("invalid decimal") if arr.length != 2
57
57
  BigDecimal.new(arr[1]) * (BigDecimal.new(10) ** arr[0])
58
58
  end
59
59
 
60
60
  if defined? UUIDTools::UUID
61
- CBOR.register_class UUIDTools::UUID, CBOR::Consts::Tag::UUID do |d, val|
62
- d.dump val.raw.b
61
+ CBOR.register_class UUIDTools::UUID, CBOR::Consts::Tag::UUID do |val|
62
+ val.raw.b
63
63
  end
64
64
 
65
- CBOR.register_tag CBOR::Consts::Tag::UUID do |l|
66
- UUIDTools::UUID.parse_raw(l.load)
65
+ CBOR.register_tag CBOR::Consts::Tag::UUID do |raw|
66
+ UUIDTools::UUID.parse_raw(raw)
67
67
  end
68
68
  end
data/test/load_test.rb CHANGED
@@ -14,6 +14,6 @@ class TestLoad < Minitest::Test
14
14
  end
15
15
 
16
16
  def test_loading_local_tags
17
- assert_equal false, CBOR.load("\xd8\x26\xf5", {0x26 => -> (l) { !l.load }})
17
+ assert_equal false, CBOR.load("\xd8\x26\xf5", {0x26 => -> (raw) { !raw }})
18
18
  end
19
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cbor-simple
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Clemente