cbor-diag 0.5.12 → 0.5.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/cbor2diag.rb +5 -1
- data/bin/cbor2json.rb +10 -0
- data/bin/cbor2u8.rb +9 -0
- data/bin/cbor2yaml.rb +10 -0
- data/bin/cborleader2diag.rb +13 -1
- data/bin/cborseq2diag.rb +5 -1
- data/bin/cborseq2json.rb +10 -0
- data/bin/cborseq2neatjson.rb +10 -0
- data/bin/cborseq2pretty.rb +1 -5
- data/bin/cborseq2yaml.rb +11 -0
- data/bin/diag2cbor.rb +8 -1
- data/bin/diag2diag.rb +42 -0
- data/bin/diag2pretty.rb +8 -1
- data/bin/json2cbor.rb +10 -4
- data/bin/json2json.rb +17 -0
- data/bin/json2neatjson.rb +19 -0
- data/bin/json2yaml.rb +25 -0
- data/bin/yaml2cbor.rb +10 -4
- data/bin/yaml2json.rb +19 -0
- data/cbor-diag.gemspec +4 -2
- data/lib/cbor-diag-parser.rb +105 -8
- data/lib/cbor-pretty.rb +13 -2
- data/lib/cbor-pure.rb +14 -0
- metadata +43 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 222a5a85e9ce7a04e69d4620d0bbcd851500cea2b56ff6206b317f10c04bbeb8
|
4
|
+
data.tar.gz: 61b1b698cd6e8a0a34d532053e5f8784a1a4fe2c9c94713f75359a795926aea3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b43b8603b856c370d9290fe89c8b6fdc3242c0fe4124704a46c3734c9123a3d4e4da9f21fb838dc55145eae216b0277b5ed57435bcabe56f2df751c0968f6633
|
7
|
+
data.tar.gz: 9ae5c2a6d02c854c5e0b4cd0de9f3210ce83d7cd61c86b3eaa1585a478cc54e9df0d0aa1998f28b835483ccfb296787942a40799af717faa8971b6e74de53cc9
|
data/bin/cbor2diag.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'cbor-diagnostic'
|
3
|
+
require 'cbor-deterministic'
|
4
|
+
require 'cbor-canonical'
|
3
5
|
|
4
6
|
options = ''
|
5
|
-
while /\A-([
|
7
|
+
while /\A-([cdetu]+)\z/ === ARGV[0]
|
6
8
|
options << $1
|
7
9
|
ARGV.shift
|
8
10
|
end
|
@@ -10,6 +12,8 @@ end
|
|
10
12
|
ARGF.binmode
|
11
13
|
i = ARGF.read
|
12
14
|
o = CBOR.decode(i)
|
15
|
+
o = o.cbor_pre_canonicalize if /c/ === options
|
16
|
+
o = o.cbor_prepare_deterministic if /d/ === options
|
13
17
|
puts o.cbor_diagnostic(try_decode_embedded: /e/ === options,
|
14
18
|
bytes_as_text: /t/ === options,
|
15
19
|
utf8: /u/ === options)
|
data/bin/cbor2json.rb
CHANGED
@@ -1,8 +1,18 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'json'
|
3
3
|
require 'cbor-pure'
|
4
|
+
require 'cbor-deterministic'
|
5
|
+
require 'cbor-canonical'
|
6
|
+
|
7
|
+
options = ''
|
8
|
+
while /\A-([cd]+)\z/ === ARGV[0]
|
9
|
+
options << $1
|
10
|
+
ARGV.shift
|
11
|
+
end
|
4
12
|
|
5
13
|
ARGF.binmode
|
6
14
|
i = ARGF.read
|
7
15
|
o = CBOR.decode(i)
|
16
|
+
o = o.cbor_pre_canonicalize if /c/ === options
|
17
|
+
o = o.cbor_prepare_deterministic if /d/ === options
|
8
18
|
puts JSON.pretty_generate(o)
|
data/bin/cbor2u8.rb
ADDED
data/bin/cbor2yaml.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
require 'psych.rb' # WTF
|
3
3
|
require 'yaml'
|
4
4
|
require 'cbor-pure'
|
5
|
+
require 'cbor-deterministic'
|
6
|
+
require 'cbor-canonical'
|
5
7
|
|
6
8
|
class Array
|
7
9
|
def to_yaml_style()
|
@@ -9,7 +11,15 @@ class Array
|
|
9
11
|
end
|
10
12
|
end
|
11
13
|
|
14
|
+
options = ''
|
15
|
+
while /\A-([cd]+)\z/ === ARGV[0]
|
16
|
+
options << $1
|
17
|
+
ARGV.shift
|
18
|
+
end
|
19
|
+
|
12
20
|
ARGF.binmode
|
13
21
|
i = ARGF.read
|
14
22
|
o = CBOR.decode(i)
|
23
|
+
o = o.cbor_prepare_deterministic if /d/ === options
|
24
|
+
o = o.cbor_pre_canonicalize if /c/ === options
|
15
25
|
puts YAML.dump(o)
|
data/bin/cborleader2diag.rb
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'cbor-diagnostic'
|
3
|
+
require 'cbor-deterministic'
|
4
|
+
require 'cbor-canonical'
|
5
|
+
|
6
|
+
options = ''
|
7
|
+
while /\A-([cdetu]+)\z/ === ARGV[0]
|
8
|
+
options << $1
|
9
|
+
ARGV.shift
|
10
|
+
end
|
3
11
|
|
4
12
|
ARGF.binmode
|
5
13
|
i = ARGF.read
|
@@ -7,4 +15,8 @@ o,r = CBOR.decode_with_rest(i)
|
|
7
15
|
if r != ''
|
8
16
|
warn "** ignoring rest of #{r.bytesize} bytes after first CBOR data item"
|
9
17
|
end
|
10
|
-
|
18
|
+
o = o.cbor_prepare_deterministic if /d/ === options
|
19
|
+
o = o.cbor_pre_canonicalize if /c/ === options
|
20
|
+
puts o.cbor_diagnostic(try_decode_embedded: /e/ === options,
|
21
|
+
bytes_as_text: /t/ === options,
|
22
|
+
utf8: /u/ === options)
|
data/bin/cborseq2diag.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'cbor-diagnostic'
|
3
|
+
require 'cbor-deterministic'
|
4
|
+
require 'cbor-canonical'
|
3
5
|
|
4
6
|
options = ''
|
5
|
-
while /\A-([
|
7
|
+
while /\A-([cdetu]+)\z/ === ARGV[0]
|
6
8
|
options << $1
|
7
9
|
ARGV.shift
|
8
10
|
end
|
@@ -11,6 +13,8 @@ ARGF.binmode
|
|
11
13
|
i = ARGF.read
|
12
14
|
while !i.empty?
|
13
15
|
o, i = CBOR.decode_with_rest(i)
|
16
|
+
o = o.cbor_pre_canonicalize if /c/ === options
|
17
|
+
o = o.cbor_prepare_deterministic if /d/ === options
|
14
18
|
out = o.cbor_diagnostic(try_decode_embedded: /e/ === options,
|
15
19
|
bytes_as_text: /t/ === options,
|
16
20
|
utf8: /u/ === options)
|
data/bin/cborseq2json.rb
CHANGED
@@ -1,10 +1,20 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'json'
|
3
3
|
require 'cbor-pure'
|
4
|
+
require 'cbor-deterministic'
|
5
|
+
require 'cbor-canonical'
|
6
|
+
|
7
|
+
options = ''
|
8
|
+
while /\A-([cd]+)\z/ === ARGV[0]
|
9
|
+
options << $1
|
10
|
+
ARGV.shift
|
11
|
+
end
|
4
12
|
|
5
13
|
ARGF.binmode
|
6
14
|
i = ARGF.read
|
7
15
|
while i != ''
|
8
16
|
o, i = CBOR.decode_with_rest(i)
|
17
|
+
o = o.cbor_pre_canonicalize if /c/ === options
|
18
|
+
o = o.cbor_prepare_deterministic if /d/ === options
|
9
19
|
puts JSON.pretty_generate(o)
|
10
20
|
end
|
data/bin/cborseq2neatjson.rb
CHANGED
@@ -2,10 +2,20 @@
|
|
2
2
|
require 'json'
|
3
3
|
require 'cbor-pure'
|
4
4
|
require 'neatjson'
|
5
|
+
require 'cbor-deterministic'
|
6
|
+
require 'cbor-canonical'
|
7
|
+
|
8
|
+
options = ''
|
9
|
+
while /\A-([cd]+)\z/ === ARGV[0]
|
10
|
+
options << $1
|
11
|
+
ARGV.shift
|
12
|
+
end
|
5
13
|
|
6
14
|
ARGF.binmode
|
7
15
|
i = ARGF.read
|
8
16
|
while i != ''
|
9
17
|
o, i = CBOR.decode_with_rest(i)
|
18
|
+
o = o.cbor_pre_canonicalize if /c/ === options
|
19
|
+
o = o.cbor_prepare_deterministic if /d/ === options
|
10
20
|
puts JSON.neat_generate(o, after_comma: 1, after_colon: 1)
|
11
21
|
end
|
data/bin/cborseq2pretty.rb
CHANGED
data/bin/cborseq2yaml.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
require 'psych.rb' # WTF
|
3
3
|
require 'yaml'
|
4
4
|
require 'cbor-pure'
|
5
|
+
require 'cbor-deterministic'
|
6
|
+
require 'cbor-canonical'
|
5
7
|
|
6
8
|
class Array
|
7
9
|
def to_yaml_style()
|
@@ -9,10 +11,19 @@ class Array
|
|
9
11
|
end
|
10
12
|
end
|
11
13
|
|
14
|
+
options = ''
|
15
|
+
while /\A-([cd]+)\z/ === ARGV[0]
|
16
|
+
options << $1
|
17
|
+
ARGV.shift
|
18
|
+
end
|
19
|
+
|
20
|
+
|
12
21
|
ARGF.binmode
|
13
22
|
i = ARGF.read
|
14
23
|
while i != ''
|
15
24
|
o, i = CBOR.decode_with_rest(i)
|
25
|
+
o = o.cbor_pre_canonicalize if /c/ === options
|
26
|
+
o = o.cbor_prepare_deterministic if /d/ === options
|
16
27
|
puts YAML.dump(o)
|
17
28
|
end
|
18
29
|
|
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/diag2diag.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'cbor-pure'
|
3
|
+
require 'treetop'
|
4
|
+
require 'cbor-diag-parser'
|
5
|
+
unless ''.respond_to? :b
|
6
|
+
require 'cbor-diagnostic' # for .b
|
7
|
+
end
|
8
|
+
require 'cbor-pretty'
|
9
|
+
require 'cbor-diagnostic'
|
10
|
+
require 'cbor-deterministic'
|
11
|
+
require 'cbor-canonical'
|
12
|
+
|
13
|
+
options = ''
|
14
|
+
while /\A-([cdetu]+)\z/ === ARGV[0]
|
15
|
+
options << $1
|
16
|
+
ARGV.shift
|
17
|
+
end
|
18
|
+
|
19
|
+
def diagnostic(o, options)
|
20
|
+
o = o.cbor_pre_canonicalize if /c/ === options
|
21
|
+
o = o.cbor_prepare_deterministic if /d/ === options
|
22
|
+
puts o.cbor_diagnostic(try_decode_embedded: /e/ === options,
|
23
|
+
bytes_as_text: /t/ === options,
|
24
|
+
utf8: /u/ === options)
|
25
|
+
end
|
26
|
+
|
27
|
+
parser = CBOR_DIAGParser.new
|
28
|
+
|
29
|
+
i = ARGF.read.b # binary to work around treetop performance bug
|
30
|
+
if result = parser.parse(i)
|
31
|
+
decoded = result.to_rb
|
32
|
+
out = case decoded
|
33
|
+
when CBOR::Sequence
|
34
|
+
decoded.elements
|
35
|
+
else
|
36
|
+
[decoded]
|
37
|
+
end.map {|x| diagnostic(x, options)}.join(", ")
|
38
|
+
print out
|
39
|
+
else
|
40
|
+
puts "*** can't parse #{i}"
|
41
|
+
puts "*** #{parser.failure_reason}"
|
42
|
+
end
|
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/bin/json2cbor.rb
CHANGED
@@ -1,14 +1,20 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'json'
|
3
3
|
require 'cbor-pure'
|
4
|
+
require 'cbor-deterministic'
|
5
|
+
require 'cbor-canonical'
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
+
options = ''
|
8
|
+
while /\A-([cdv]+)\z/ === ARGV[0]
|
9
|
+
options << $1
|
7
10
|
ARGV.shift
|
8
11
|
end
|
9
12
|
|
10
13
|
$stdout.binmode
|
11
14
|
i = ARGF.read
|
12
|
-
o =
|
15
|
+
o = JSON.load(i)
|
16
|
+
o = o.cbor_pre_canonicalize if /c/ === options
|
17
|
+
o = o.cbor_prepare_deterministic if /d/ === options
|
18
|
+
o = CBOR.encode(o)
|
13
19
|
print o
|
14
|
-
warn "JSON size: #{i.size} bytes, CBOR size: #{o.size} bytes." if
|
20
|
+
warn "JSON size: #{i.size} bytes, CBOR size: #{o.size} bytes." if /v/ === options
|
data/bin/json2json.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'json'
|
3
|
+
require 'cbor-pure'
|
4
|
+
require 'cbor-deterministic'
|
5
|
+
require 'cbor-canonical'
|
6
|
+
|
7
|
+
options = ''
|
8
|
+
while /\A-([cd]+)\z/ === ARGV[0]
|
9
|
+
options << $1
|
10
|
+
ARGV.shift
|
11
|
+
end
|
12
|
+
|
13
|
+
i = ARGF.read
|
14
|
+
o = JSON.load(i)
|
15
|
+
o = o.cbor_pre_canonicalize if /c/ === options
|
16
|
+
o = o.cbor_prepare_deterministic if /d/ === options
|
17
|
+
puts JSON.pretty_generate(o)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'json'
|
3
|
+
require 'cbor-pure'
|
4
|
+
require 'neatjson'
|
5
|
+
require 'cbor-deterministic'
|
6
|
+
require 'cbor-canonical'
|
7
|
+
|
8
|
+
options = ''
|
9
|
+
while /\A-([cd]+)\z/ === ARGV[0]
|
10
|
+
options << $1
|
11
|
+
ARGV.shift
|
12
|
+
end
|
13
|
+
|
14
|
+
$stdout.binmode
|
15
|
+
i = ARGF.read
|
16
|
+
o = JSON.load(i)
|
17
|
+
o = o.cbor_pre_canonicalize if /c/ === options
|
18
|
+
o = o.cbor_prepare_deterministic if /d/ === options
|
19
|
+
puts JSON.neat_generate(o, after_comma: 1, after_colon: 1)
|
data/bin/json2yaml.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'psych.rb' # WTF
|
3
|
+
require 'yaml'
|
4
|
+
require 'json'
|
5
|
+
require 'cbor-pure'
|
6
|
+
require 'cbor-deterministic'
|
7
|
+
require 'cbor-canonical'
|
8
|
+
|
9
|
+
class Array
|
10
|
+
def to_yaml_style()
|
11
|
+
all? {|x| Integer === x } && length < 20 ? :inline : super
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
options = ''
|
16
|
+
while /\A-([cd]+)\z/ === ARGV[0]
|
17
|
+
options << $1
|
18
|
+
ARGV.shift
|
19
|
+
end
|
20
|
+
|
21
|
+
i = ARGF.read
|
22
|
+
o = JSON.load(i)
|
23
|
+
o = o.cbor_pre_canonicalize if /c/ === options
|
24
|
+
o = o.cbor_prepare_deterministic if /d/ === options
|
25
|
+
puts YAML.dump(o)
|
data/bin/yaml2cbor.rb
CHANGED
@@ -2,14 +2,20 @@
|
|
2
2
|
require 'psych.rb' # WTF
|
3
3
|
require 'yaml'
|
4
4
|
require 'cbor-pure'
|
5
|
+
require 'cbor-deterministic'
|
6
|
+
require 'cbor-canonical'
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
+
options = ''
|
9
|
+
while /\A-([cdv]+)\z/ === ARGV[0]
|
10
|
+
options << $1
|
8
11
|
ARGV.shift
|
9
12
|
end
|
10
13
|
|
11
14
|
$stdout.binmode
|
12
15
|
i = ARGF.read
|
13
|
-
o =
|
16
|
+
o = YAML.load(i)
|
17
|
+
o = o.cbor_pre_canonicalize if /c/ === options
|
18
|
+
o = o.cbor_prepare_deterministic if /d/ === options
|
19
|
+
o = CBOR.encode(o)
|
14
20
|
print o
|
15
|
-
warn "YAML size: #{i.size} bytes, CBOR size: #{o.size} bytes." if
|
21
|
+
warn "YAML size: #{i.size} bytes, CBOR size: #{o.size} bytes." if /v/ === options
|
data/bin/yaml2json.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'json'
|
3
|
+
require 'psych.rb' # WTF
|
4
|
+
require 'yaml'
|
5
|
+
require 'cbor-pure'
|
6
|
+
require 'cbor-deterministic'
|
7
|
+
require 'cbor-canonical'
|
8
|
+
|
9
|
+
options = ''
|
10
|
+
while /\A-([cd]+)\z/ === ARGV[0]
|
11
|
+
options << $1
|
12
|
+
ARGV.shift
|
13
|
+
end
|
14
|
+
|
15
|
+
i = ARGF.read
|
16
|
+
o = YAML.load(i)
|
17
|
+
o = o.cbor_pre_canonicalize if /c/ === options
|
18
|
+
o = o.cbor_prepare_deterministic if /d/ === options
|
19
|
+
puts JSON.pretty_generate(o)
|
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.19"
|
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"
|
@@ -20,4 +20,6 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.add_dependency 'treetop', '~>1'
|
21
21
|
s.add_dependency 'json'
|
22
22
|
s.add_dependency 'neatjson'
|
23
|
+
s.add_dependency 'cbor-deterministic'
|
24
|
+
s.add_dependency 'cbor-canonical'
|
23
25
|
end
|
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.19
|
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-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,12 +66,41 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: cbor-deterministic
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: cbor-canonical
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: cbor-diag implements diagnostic notation for CBOR, RFC 8949 and RFC 8742
|
70
98
|
email: cabo@tzi.org
|
71
99
|
executables:
|
72
100
|
- cbor2diag.rb
|
73
101
|
- cbor2json.rb
|
74
102
|
- cbor2pretty.rb
|
103
|
+
- cbor2u8.rb
|
75
104
|
- cbor2yaml.rb
|
76
105
|
- cborleader2diag.rb
|
77
106
|
- cborseq2diag.rb
|
@@ -80,18 +109,24 @@ executables:
|
|
80
109
|
- cborseq2pretty.rb
|
81
110
|
- cborseq2yaml.rb
|
82
111
|
- diag2cbor.rb
|
112
|
+
- diag2diag.rb
|
83
113
|
- diag2pretty.rb
|
84
114
|
- json2cbor.rb
|
115
|
+
- json2json.rb
|
116
|
+
- json2neatjson.rb
|
85
117
|
- json2pretty.rb
|
118
|
+
- json2yaml.rb
|
86
119
|
- pretty2cbor.rb
|
87
120
|
- pretty2diag.rb
|
88
121
|
- yaml2cbor.rb
|
122
|
+
- yaml2json.rb
|
89
123
|
extensions: []
|
90
124
|
extra_rdoc_files: []
|
91
125
|
files:
|
92
126
|
- bin/cbor2diag.rb
|
93
127
|
- bin/cbor2json.rb
|
94
128
|
- bin/cbor2pretty.rb
|
129
|
+
- bin/cbor2u8.rb
|
95
130
|
- bin/cbor2yaml.rb
|
96
131
|
- bin/cborleader2diag.rb
|
97
132
|
- bin/cborseq2diag.rb
|
@@ -100,12 +135,17 @@ files:
|
|
100
135
|
- bin/cborseq2pretty.rb
|
101
136
|
- bin/cborseq2yaml.rb
|
102
137
|
- bin/diag2cbor.rb
|
138
|
+
- bin/diag2diag.rb
|
103
139
|
- bin/diag2pretty.rb
|
104
140
|
- bin/json2cbor.rb
|
141
|
+
- bin/json2json.rb
|
142
|
+
- bin/json2neatjson.rb
|
105
143
|
- bin/json2pretty.rb
|
144
|
+
- bin/json2yaml.rb
|
106
145
|
- bin/pretty2cbor.rb
|
107
146
|
- bin/pretty2diag.rb
|
108
147
|
- bin/yaml2cbor.rb
|
148
|
+
- bin/yaml2json.rb
|
109
149
|
- cbor-diag.gemspec
|
110
150
|
- lib/cbor-diag-parser.rb
|
111
151
|
- lib/cbor-diagnostic.rb
|