cbor-simple 1.1.1 → 1.2.0
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/README.md +5 -5
- data/lib/cbor/dumper.rb +1 -1
- data/lib/cbor/loader.rb +2 -2
- data/lib/cbor/version.rb +1 -1
- data/lib/cbor.rb +12 -12
- data/test/load_test.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 697f956fd9e4ec493cbefa2c2b9fed9343b1da3e
|
4
|
+
data.tar.gz: a3d4282de9bed819127ad272abd2e7169e702a83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 |
|
20
|
-
Time.iso8601(
|
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 |
|
28
|
-
|
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 => -> (
|
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(
|
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(
|
43
|
+
block.call(load)
|
44
44
|
elsif block = @local_tags[tag]
|
45
|
-
block.call(
|
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
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 |
|
40
|
-
|
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 |
|
44
|
-
Time.iso8601(
|
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 |
|
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
|
-
|
51
|
+
[exponent - significant_digits.size, val]
|
52
52
|
end
|
53
53
|
|
54
|
-
CBOR.register_tag CBOR::Consts::Tag::DECIMAL do |
|
55
|
-
arr =
|
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 |
|
62
|
-
|
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 |
|
66
|
-
UUIDTools::UUID.parse_raw(
|
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