cbor-diag 0.5.10 → 0.5.15
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/bin/cbor2diag.rb +4 -2
- data/bin/cborseq2diag.rb +4 -2
- data/bin/cborseq2pretty.rb +7 -0
- data/bin/diag2cbor.rb +8 -1
- data/bin/diag2pretty.rb +8 -1
- data/cbor-diag.gemspec +2 -2
- data/lib/cbor-diag-parser.rb +105 -8
- data/lib/cbor-pretty.rb +13 -2
- data/lib/cbor-pure.rb +14 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 631d4dd7cf5f08c4a1a33f2a021eb2627da7007d5ad16e10ac83182fd161fb49
|
4
|
+
data.tar.gz: 4ca7971612f93597169a0af602d9b919e5dd67b2291d0999aea328fba8150c20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9d148ad270cddc39982052b895e18b1d1c3e0bc7b4b574e4267c7cfb07b76e013e20af1ba1c15ae7e6e9465860bd9cc485d6ad2c369a6a29ab6d3bed1924aa2
|
7
|
+
data.tar.gz: 4be65c57df7e7f2d64ef7e26672ba0835f4a9ff9b4e78387c0ba50ea3e0ec83e75e32ee21b97996af11529f76c4e3b9cd5038189906febf5f5f3cffde1089dad
|
data/bin/cbor2diag.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
require 'cbor-diagnostic'
|
3
3
|
|
4
4
|
options = ''
|
5
|
-
while /\A-([
|
5
|
+
while /\A-([etu]+)\z/ === ARGV[0]
|
6
6
|
options << $1
|
7
7
|
ARGV.shift
|
8
8
|
end
|
@@ -10,4 +10,6 @@ end
|
|
10
10
|
ARGF.binmode
|
11
11
|
i = ARGF.read
|
12
12
|
o = CBOR.decode(i)
|
13
|
-
puts o.cbor_diagnostic(try_decode_embedded: /e/ === options,
|
13
|
+
puts o.cbor_diagnostic(try_decode_embedded: /e/ === options,
|
14
|
+
bytes_as_text: /t/ === options,
|
15
|
+
utf8: /u/ === options)
|
data/bin/cborseq2diag.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
require 'cbor-diagnostic'
|
3
3
|
|
4
4
|
options = ''
|
5
|
-
while /\A-([
|
5
|
+
while /\A-([etu]+)\z/ === ARGV[0]
|
6
6
|
options << $1
|
7
7
|
ARGV.shift
|
8
8
|
end
|
@@ -11,7 +11,9 @@ ARGF.binmode
|
|
11
11
|
i = ARGF.read
|
12
12
|
while !i.empty?
|
13
13
|
o, i = CBOR.decode_with_rest(i)
|
14
|
-
out = o.cbor_diagnostic(try_decode_embedded: /e/ === options,
|
14
|
+
out = o.cbor_diagnostic(try_decode_embedded: /e/ === options,
|
15
|
+
bytes_as_text: /t/ === options,
|
16
|
+
utf8: /u/ === options)
|
15
17
|
if i.empty?
|
16
18
|
puts out
|
17
19
|
else
|
data/bin/diag2cbor.rb
CHANGED
@@ -13,7 +13,14 @@ $stdout.binmode
|
|
13
13
|
|
14
14
|
i = ARGF.read.b # binary to work around treetop performance bug
|
15
15
|
if result = parser.parse(i)
|
16
|
-
|
16
|
+
decoded = result.to_rb
|
17
|
+
out = case decoded
|
18
|
+
when CBOR::Sequence
|
19
|
+
CBOR::encode_seq(decoded.elements)
|
20
|
+
else
|
21
|
+
CBOR::encode(decoded)
|
22
|
+
end
|
23
|
+
print out
|
17
24
|
else
|
18
25
|
puts "*** can't parse #{i}"
|
19
26
|
puts "*** #{parser.failure_reason}"
|
data/bin/diag2pretty.rb
CHANGED
@@ -8,7 +8,14 @@ parser = CBOR_DIAGParser.new
|
|
8
8
|
|
9
9
|
i = ARGF.read
|
10
10
|
if result = parser.parse(i)
|
11
|
-
|
11
|
+
decoded = result.to_rb
|
12
|
+
puts case decoded
|
13
|
+
when CBOR::Sequence
|
14
|
+
"# CBOR sequence with #{decoded.elements.size} elements\n" <<
|
15
|
+
CBOR::pretty_seq(CBOR::encode_seq(decoded.elements))
|
16
|
+
else
|
17
|
+
CBOR::pretty(CBOR::encode(decoded))
|
18
|
+
end
|
12
19
|
else
|
13
20
|
puts "*** can't parse #{i}"
|
14
21
|
puts "*** #{parser.failure_reason}"
|
data/cbor-diag.gemspec
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "cbor-diag"
|
3
|
-
s.version = "0.5.
|
3
|
+
s.version = "0.5.15"
|
4
4
|
s.summary = "CBOR (Concise Binary Object Representation) diagnostic notation"
|
5
|
-
s.description = %q{cbor-diag implements diagnostic notation for CBOR, RFC
|
5
|
+
s.description = %q{cbor-diag implements diagnostic notation for CBOR, RFC 8949 and RFC 8742}
|
6
6
|
s.author = "Carsten Bormann"
|
7
7
|
s.email = "cabo@tzi.org"
|
8
8
|
s.license = "Apache-2.0"
|
data/lib/cbor-diag-parser.rb
CHANGED
@@ -10,10 +10,38 @@ module CBOR_DIAG
|
|
10
10
|
|
11
11
|
module Text0
|
12
12
|
def ows1
|
13
|
-
elements[
|
13
|
+
elements[1]
|
14
14
|
end
|
15
15
|
|
16
16
|
def value
|
17
|
+
elements[2]
|
18
|
+
end
|
19
|
+
|
20
|
+
def ows2
|
21
|
+
elements[3]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module Text1
|
26
|
+
def value
|
27
|
+
elements[0]
|
28
|
+
end
|
29
|
+
|
30
|
+
def ows
|
31
|
+
elements[1]
|
32
|
+
end
|
33
|
+
|
34
|
+
def an
|
35
|
+
elements[2]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
module Text2
|
40
|
+
def ows1
|
41
|
+
elements[0]
|
42
|
+
end
|
43
|
+
|
44
|
+
def a1
|
17
45
|
elements[1]
|
18
46
|
end
|
19
47
|
|
@@ -22,8 +50,19 @@ module CBOR_DIAG
|
|
22
50
|
end
|
23
51
|
end
|
24
52
|
|
25
|
-
module
|
26
|
-
def to_rb
|
53
|
+
module Text3
|
54
|
+
def to_rb
|
55
|
+
r = if e = a1.elements
|
56
|
+
[e[0].to_rb] + e[2].elements.map {|x| x.value.to_rb }
|
57
|
+
else
|
58
|
+
[]
|
59
|
+
end
|
60
|
+
if r.size == 1
|
61
|
+
r.first
|
62
|
+
else
|
63
|
+
CBOR::Sequence.new(r)
|
64
|
+
end
|
65
|
+
end
|
27
66
|
end
|
28
67
|
|
29
68
|
def _nt_text
|
@@ -41,17 +80,75 @@ module CBOR_DIAG
|
|
41
80
|
r1 = _nt_ows
|
42
81
|
s0 << r1
|
43
82
|
if r1
|
44
|
-
|
83
|
+
i3, s3 = index, []
|
84
|
+
r4 = _nt_value
|
85
|
+
s3 << r4
|
86
|
+
if r4
|
87
|
+
r5 = _nt_ows
|
88
|
+
s3 << r5
|
89
|
+
if r5
|
90
|
+
s6, i6 = [], index
|
91
|
+
loop do
|
92
|
+
i7, s7 = index, []
|
93
|
+
if (match_len = has_terminal?(',', false, index))
|
94
|
+
r8 = true
|
95
|
+
@index += match_len
|
96
|
+
else
|
97
|
+
terminal_parse_failure('\',\'')
|
98
|
+
r8 = nil
|
99
|
+
end
|
100
|
+
s7 << r8
|
101
|
+
if r8
|
102
|
+
r9 = _nt_ows
|
103
|
+
s7 << r9
|
104
|
+
if r9
|
105
|
+
r10 = _nt_value
|
106
|
+
s7 << r10
|
107
|
+
if r10
|
108
|
+
r11 = _nt_ows
|
109
|
+
s7 << r11
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
if s7.last
|
114
|
+
r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
|
115
|
+
r7.extend(Text0)
|
116
|
+
else
|
117
|
+
@index = i7
|
118
|
+
r7 = nil
|
119
|
+
end
|
120
|
+
if r7
|
121
|
+
s6 << r7
|
122
|
+
else
|
123
|
+
break
|
124
|
+
end
|
125
|
+
end
|
126
|
+
r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
|
127
|
+
s3 << r6
|
128
|
+
end
|
129
|
+
end
|
130
|
+
if s3.last
|
131
|
+
r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
|
132
|
+
r3.extend(Text1)
|
133
|
+
else
|
134
|
+
@index = i3
|
135
|
+
r3 = nil
|
136
|
+
end
|
137
|
+
if r3
|
138
|
+
r2 = r3
|
139
|
+
else
|
140
|
+
r2 = instantiate_node(SyntaxNode,input, index...index)
|
141
|
+
end
|
45
142
|
s0 << r2
|
46
143
|
if r2
|
47
|
-
|
48
|
-
s0 <<
|
144
|
+
r12 = _nt_ows
|
145
|
+
s0 << r12
|
49
146
|
end
|
50
147
|
end
|
51
148
|
if s0.last
|
52
149
|
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
53
|
-
r0.extend(
|
54
|
-
r0.extend(
|
150
|
+
r0.extend(Text2)
|
151
|
+
r0.extend(Text3)
|
55
152
|
else
|
56
153
|
@index = i0
|
57
154
|
r0 = nil
|
data/lib/cbor-pretty.rb
CHANGED
@@ -17,6 +17,15 @@ module CBOR
|
|
17
17
|
Buffer.new(s).pretty_item_final(indent, max_target)
|
18
18
|
end
|
19
19
|
|
20
|
+
def self.pretty_seq(s, indent = 0, max_target = 40)
|
21
|
+
b = Buffer.new(s)
|
22
|
+
res = '' # XXX: not all indented the same
|
23
|
+
while !b.empty?
|
24
|
+
res << b.pretty_item_final(indent, max_target, true)
|
25
|
+
end
|
26
|
+
res
|
27
|
+
end
|
28
|
+
|
20
29
|
class Buffer
|
21
30
|
|
22
31
|
def take_and_print(n, prefix = '')
|
@@ -72,11 +81,13 @@ module CBOR
|
|
72
81
|
nil
|
73
82
|
end
|
74
83
|
|
75
|
-
def pretty_item_final(indent = 0, max_target = 40)
|
84
|
+
def pretty_item_final(indent = 0, max_target = 40, seq = false)
|
76
85
|
@out = ''
|
77
86
|
@indent = indent
|
78
87
|
pretty_item
|
79
|
-
|
88
|
+
unless seq
|
89
|
+
raise if @pos != @buffer.size
|
90
|
+
end
|
80
91
|
target = [@out.each_line.map {|ln| ln =~ /#/ || 0}.max, max_target].min
|
81
92
|
@out.each_line.map {|ln|
|
82
93
|
col = ln =~ /#/
|
data/lib/cbor-pure.rb
CHANGED
@@ -64,6 +64,16 @@ module CBOR
|
|
64
64
|
alias_method :inspect, :to_s
|
65
65
|
end
|
66
66
|
|
67
|
+
Sequence = Struct.new(:elements) do
|
68
|
+
def to_s
|
69
|
+
elements.map(&:to_s).join(", ")
|
70
|
+
end
|
71
|
+
alias_method :inspect, :to_s
|
72
|
+
def to_cborseq
|
73
|
+
CBOR.encode_seq(self)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
67
77
|
def self.encode(d)
|
68
78
|
Buffer.new.add(d).buffer
|
69
79
|
end
|
@@ -314,6 +324,10 @@ module CBOR
|
|
314
324
|
ret
|
315
325
|
end
|
316
326
|
|
327
|
+
def empty?
|
328
|
+
@pos == buffer.size
|
329
|
+
end
|
330
|
+
|
317
331
|
|
318
332
|
end
|
319
333
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cbor-diag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carsten Bormann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description: cbor-diag implements diagnostic notation for CBOR, RFC
|
69
|
+
description: cbor-diag implements diagnostic notation for CBOR, RFC 8949 and RFC 8742
|
70
70
|
email: cabo@tzi.org
|
71
71
|
executables:
|
72
72
|
- cbor2diag.rb
|
@@ -77,6 +77,7 @@ executables:
|
|
77
77
|
- cborseq2diag.rb
|
78
78
|
- cborseq2json.rb
|
79
79
|
- cborseq2neatjson.rb
|
80
|
+
- cborseq2pretty.rb
|
80
81
|
- cborseq2yaml.rb
|
81
82
|
- diag2cbor.rb
|
82
83
|
- diag2pretty.rb
|
@@ -96,6 +97,7 @@ files:
|
|
96
97
|
- bin/cborseq2diag.rb
|
97
98
|
- bin/cborseq2json.rb
|
98
99
|
- bin/cborseq2neatjson.rb
|
100
|
+
- bin/cborseq2pretty.rb
|
99
101
|
- bin/cborseq2yaml.rb
|
100
102
|
- bin/diag2cbor.rb
|
101
103
|
- bin/diag2pretty.rb
|