cbor-diag 0.10.2 → 0.10.3
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/cbor-diag.gemspec +1 -1
- data/lib/cbor-diag-parser.rb +1 -1
- data/lib/cbor-diagnostic.rb +1 -1
- data/lib/cbor-pretty.rb +21 -6
- data/lib/cbor-pure.rb +32 -2
- 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: 38def274f572f92dcd5b6cfd02fc4e7b0bc2006f5339f5db046e1b9bb388fcaa
|
|
4
|
+
data.tar.gz: f8027b5da38f62e5b0411f55c182fae2025768be56ed978775e491273a19e150
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8ad0cd6b46dd03e2fd5457a440bea503ece1e4dc293dde4a701f41f9434092d26e4576711afc321ceddf9a661e81e7b4ada743f37a0c25f4e04c475bbfd9fed0
|
|
7
|
+
data.tar.gz: 8a55d75ba512cbceeed3f995d10615a0666d892449c13c1b729d69858fe3180b4fe4eee2ac06dca4bb8a31787a40d0b687f0205df77bd6fae5b6226e194e18cd
|
data/cbor-diag.gemspec
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Gem::Specification.new do |s|
|
|
2
2
|
s.name = "cbor-diag"
|
|
3
|
-
s.version = "0.10.
|
|
3
|
+
s.version = "0.10.3"
|
|
4
4
|
s.summary = "CBOR (Concise Binary Object Representation) diagnostic notation"
|
|
5
5
|
s.description = %q{cbor-diag implements diagnostic notation for CBOR, RFC 8949 and RFC 8742}
|
|
6
6
|
s.author = "Carsten Bormann"
|
data/lib/cbor-diag-parser.rb
CHANGED
|
@@ -2730,7 +2730,7 @@ module CBOR_DIAG
|
|
|
2730
2730
|
module Map3
|
|
2731
2731
|
def to_rb
|
|
2732
2732
|
r = if e = a1.elements
|
|
2733
|
-
Hash[
|
|
2733
|
+
Hash.cbor_from_entries([e[0].to_rb] + e[2].elements.map {|x| x.kp.to_rb })
|
|
2734
2734
|
else
|
|
2735
2735
|
{}
|
|
2736
2736
|
end
|
data/lib/cbor-diagnostic.rb
CHANGED
|
@@ -109,7 +109,7 @@ end
|
|
|
109
109
|
|
|
110
110
|
class Hash
|
|
111
111
|
def cbor_diagnostic(options = {})
|
|
112
|
-
"{#{"_ " if cbor_stream?}#{map{ |k, v| %{#{k.cbor_diagnostic(options)}: #{v.cbor_diagnostic(options)}}}.join(", ")}}"
|
|
112
|
+
"{#{"_ " if cbor_stream?}#{map{ |k, v| %{#{k.cbor_diagnostic(options)}: #{v.cbor_diagnostic(options)}}}.join(", ")}#{cbor_map_lost_warning}}"
|
|
113
113
|
end
|
|
114
114
|
end
|
|
115
115
|
|
data/lib/cbor-pretty.rb
CHANGED
|
@@ -18,16 +18,22 @@ class String
|
|
|
18
18
|
ret.encode(Encoding::UTF_16BE) # exception if bad
|
|
19
19
|
ret
|
|
20
20
|
end
|
|
21
|
+
attr_accessor :cbor_warnings
|
|
21
22
|
end
|
|
22
23
|
|
|
23
24
|
|
|
24
25
|
module CBOR
|
|
25
|
-
def self.pretty(s, indent = 0, max_target = 40)
|
|
26
|
-
Buffer.new(s)
|
|
26
|
+
def self.pretty(s, indent = 0, max_target = 40, warnings: nil)
|
|
27
|
+
b = Buffer.new(s)
|
|
28
|
+
warnings ||= s.cbor_warnings
|
|
29
|
+
b.warnings = warnings if warnings
|
|
30
|
+
b.pretty_item_final(indent, max_target)
|
|
27
31
|
end
|
|
28
32
|
|
|
29
|
-
def self.pretty_seq(s, indent = 0, max_target = 40)
|
|
33
|
+
def self.pretty_seq(s, indent = 0, max_target = 40, warnings: nil)
|
|
30
34
|
b = Buffer.new(s)
|
|
35
|
+
warnings ||= s.cbor_warnings
|
|
36
|
+
b.warnings = warnings if warnings
|
|
31
37
|
res = '' # XXX: not all indented the same
|
|
32
38
|
while !b.empty?
|
|
33
39
|
res << b.pretty_item_final(indent, max_target, true)
|
|
@@ -37,16 +43,24 @@ module CBOR
|
|
|
37
43
|
|
|
38
44
|
class Buffer
|
|
39
45
|
|
|
46
|
+
attr_accessor :warnings
|
|
47
|
+
|
|
40
48
|
def take_and_print(n, prefix = '')
|
|
41
49
|
s = take(n)
|
|
42
50
|
@out << prefix
|
|
43
51
|
@out << s.hexbytes
|
|
44
52
|
s
|
|
45
53
|
end
|
|
46
|
-
|
|
54
|
+
|
|
55
|
+
def warning_message
|
|
56
|
+
if warnings
|
|
57
|
+
warnings[@item_pos]
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
47
61
|
def pretty_item_streaming(ib)
|
|
48
62
|
res = nil
|
|
49
|
-
@out << " # #{MT_NAMES[ib >> 5]}(*)\n"
|
|
63
|
+
@out << " # #{MT_NAMES[ib >> 5]}(*)#{warning_message}\n"
|
|
50
64
|
@indent += 1
|
|
51
65
|
case ib >>= 5
|
|
52
66
|
when 2, 3, 4, 5
|
|
@@ -62,6 +76,7 @@ module CBOR
|
|
|
62
76
|
MT_NAMES = ["unsigned", "negative", "bytes", "text", "array", "map", "tag", "primitive"]
|
|
63
77
|
|
|
64
78
|
def pretty_item
|
|
79
|
+
@item_pos = @pos
|
|
65
80
|
ib = take_and_print(1, ' ' * @indent).ord
|
|
66
81
|
ai = ib & 0x1F
|
|
67
82
|
val = case ai
|
|
@@ -73,7 +88,7 @@ module CBOR
|
|
|
73
88
|
when 31; return pretty_item_streaming(ib)
|
|
74
89
|
else raise "unknown additional information #{ai} in ib #{ib}"
|
|
75
90
|
end
|
|
76
|
-
@out << " # #{MT_NAMES[ib >> 5]}(#{val})\n"
|
|
91
|
+
@out << " # #{MT_NAMES[ib >> 5]}(#{val})#{warning_message}\n"
|
|
77
92
|
@indent += 1
|
|
78
93
|
case ib >>= 5
|
|
79
94
|
when 6
|
data/lib/cbor-pure.rb
CHANGED
|
@@ -35,6 +35,31 @@ module CBOR
|
|
|
35
35
|
end
|
|
36
36
|
Object.send(:include, CoreExt)
|
|
37
37
|
|
|
38
|
+
class ::Hash
|
|
39
|
+
attr_accessor :cbor_entries
|
|
40
|
+
def self.cbor_from_entries(entries)
|
|
41
|
+
h = Hash[entries]
|
|
42
|
+
if h.size != entries.size # dupkeys found
|
|
43
|
+
h.cbor_entries = entries
|
|
44
|
+
end
|
|
45
|
+
h
|
|
46
|
+
end
|
|
47
|
+
def cbor_map_push(key, value, entries)
|
|
48
|
+
entries << [key, value]
|
|
49
|
+
n = size
|
|
50
|
+
self[key] = value
|
|
51
|
+
if n == size # key was overwritten
|
|
52
|
+
self.cbor_entries = entries
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
def cbor_map_lost_warning
|
|
56
|
+
if cbor_entries
|
|
57
|
+
lost = cbor_entries.size - size
|
|
58
|
+
" / #{lost} DUP KEY#{"S" if lost > 1} LOST / "
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
38
63
|
class Break
|
|
39
64
|
end
|
|
40
65
|
BREAK = Break.new.freeze
|
|
@@ -217,6 +242,9 @@ module CBOR
|
|
|
217
242
|
d.each {|di| add(di)}
|
|
218
243
|
end
|
|
219
244
|
when Hash
|
|
245
|
+
if warning = d.cbor_map_lost_warning
|
|
246
|
+
(@buffer.cbor_warnings ||= {})[@buffer.bytesize] = warning
|
|
247
|
+
end
|
|
220
248
|
if d.cbor_stream?
|
|
221
249
|
@buffer << 0xbf
|
|
222
250
|
d.each {|k, v| add(k); add(v)}
|
|
@@ -266,8 +294,10 @@ module CBOR
|
|
|
266
294
|
when 5
|
|
267
295
|
result = Hash.new
|
|
268
296
|
result.cbor_stream!
|
|
297
|
+
entries = []
|
|
269
298
|
while (key = decode_item(true)) != BREAK
|
|
270
|
-
|
|
299
|
+
value = decode_item
|
|
300
|
+
result.cbor_map_push(key, value, entries)
|
|
271
301
|
end
|
|
272
302
|
result
|
|
273
303
|
when 7
|
|
@@ -327,7 +357,7 @@ module CBOR
|
|
|
327
357
|
when 2; take(val).force_encoding(Encoding::BINARY)
|
|
328
358
|
when 3; take(val).force_encoding(Encoding::UTF_8)
|
|
329
359
|
when 4; atleast(val); Array.new(val) { decode_item }
|
|
330
|
-
when 5; atleast(val<<1); Hash
|
|
360
|
+
when 5; atleast(val<<1); Hash.cbor_from_entries(Array.new(val) {[decode_item, decode_item]})
|
|
331
361
|
end
|
|
332
362
|
end
|
|
333
363
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cbor-diag
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.10.
|
|
4
|
+
version: 0.10.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Carsten Bormann
|
|
@@ -197,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
197
197
|
- !ruby/object:Gem::Version
|
|
198
198
|
version: '0'
|
|
199
199
|
requirements: []
|
|
200
|
-
rubygems_version: 3.
|
|
200
|
+
rubygems_version: 3.7.2
|
|
201
201
|
specification_version: 4
|
|
202
202
|
summary: CBOR (Concise Binary Object Representation) diagnostic notation
|
|
203
203
|
test_files: []
|