cbor-diag 0.5.12 → 0.5.20

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
  SHA256:
3
- metadata.gz: 3528a462928a5e354625093ab38377abd4591b29b8d9c1b999ec8dc46c4b71ce
4
- data.tar.gz: 727c825e585e16487d995a4d501726bbe383f26221a2747e6a1b0945fa8ef1dd
3
+ metadata.gz: 8dbeccb9b1a15bac6beb52ab1388adddac2c19cf5fce92d2184de8120326fb5e
4
+ data.tar.gz: ccd67a87d8e7c04518e0fc7852e4eac5076182cdbe58a97b7e2daea13acbfc53
5
5
  SHA512:
6
- metadata.gz: 46c6dbc28aaf1c2dc8938206ff90b66ab9920b6822dbf47ddbcdb32d465d76c5233400d4401625df25e1c4b99d1afd335b30277c2aee253940abf471ac7c1eee
7
- data.tar.gz: '029468920932c7d281d03c11030611c363a275db28386e4db273f57e729841cc822ef18bfd704a5f6f825ce7ff8a1e184095127f4721b828b35dea7f859d584e'
6
+ metadata.gz: 1f1cadddbfc82820493a77b7c50eb1bbb365be5a61016ee155f5ab88895f667d4c789d03b6d8e78983b5a765d34c316053dfbe8b730716f3d2979061759624b4
7
+ data.tar.gz: e3eff5464c68065fb23c2158fba3209880878edb8ecb04bc225bd757b572343f23513856da112377517f2318c5d8c0f2872579e2faa197088eda952ac4e01e48
data/bin/cbor2diag.rb CHANGED
@@ -1,8 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'cbor-diagnostic'
3
+ require 'cbor-packed'
4
+ require 'cbor-deterministic'
5
+ require 'cbor-canonical'
3
6
 
4
7
  options = ''
5
- while /\A-([etu]+)\z/ === ARGV[0]
8
+ while /\A-([cdetpqu]+)\z/ === ARGV[0]
6
9
  options << $1
7
10
  ARGV.shift
8
11
  end
@@ -10,6 +13,10 @@ end
10
13
  ARGF.binmode
11
14
  i = ARGF.read
12
15
  o = CBOR.decode(i)
16
+ o = o.to_packed_cbor if /p/ === options
17
+ o = o.to_unpacked_cbor if /q/ === options
18
+ o = o.cbor_pre_canonicalize if /c/ === options
19
+ o = o.cbor_prepare_deterministic if /d/ === options
13
20
  puts o.cbor_diagnostic(try_decode_embedded: /e/ === options,
14
21
  bytes_as_text: /t/ === options,
15
22
  utf8: /u/ === options)
data/bin/cbor2json.rb CHANGED
@@ -1,8 +1,21 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'json'
3
3
  require 'cbor-pure'
4
+ require 'cbor-packed'
5
+ require 'cbor-deterministic'
6
+ require 'cbor-canonical'
7
+
8
+ options = ''
9
+ while /\A-([cdpq]+)\z/ === ARGV[0]
10
+ options << $1
11
+ ARGV.shift
12
+ end
4
13
 
5
14
  ARGF.binmode
6
15
  i = ARGF.read
7
16
  o = CBOR.decode(i)
17
+ o = o.to_packed_cbor if /p/ === options
18
+ o = o.to_unpacked_cbor if /q/ === options
19
+ o = o.cbor_pre_canonicalize if /c/ === options
20
+ o = o.cbor_prepare_deterministic if /d/ === options
8
21
  puts JSON.pretty_generate(o)
data/bin/cbor2u8.rb ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ require 'cbor-pure'
3
+ require 'cbor-pretty'
4
+
5
+ ARGF.binmode
6
+ i = ARGF.read
7
+ i.bytes.each_slice(8) do |s|
8
+ puts s.map {|b| "0x%02x," % b}.join(" ")
9
+ end
data/bin/cbor2yaml.rb CHANGED
@@ -2,6 +2,9 @@
2
2
  require 'psych.rb' # WTF
3
3
  require 'yaml'
4
4
  require 'cbor-pure'
5
+ require 'cbor-packed'
6
+ require 'cbor-deterministic'
7
+ require 'cbor-canonical'
5
8
 
6
9
  class Array
7
10
  def to_yaml_style()
@@ -9,7 +12,17 @@ class Array
9
12
  end
10
13
  end
11
14
 
15
+ options = ''
16
+ while /\A-([cdpq]+)\z/ === ARGV[0]
17
+ options << $1
18
+ ARGV.shift
19
+ end
20
+
12
21
  ARGF.binmode
13
22
  i = ARGF.read
14
23
  o = CBOR.decode(i)
24
+ o = o.to_packed_cbor if /p/ === options
25
+ o = o.to_unpacked_cbor if /q/ === options
26
+ o = o.cbor_prepare_deterministic if /d/ === options
27
+ o = o.cbor_pre_canonicalize if /c/ === options
15
28
  puts YAML.dump(o)
@@ -1,5 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'cbor-diagnostic'
3
+ require 'cbor-packed'
4
+ require 'cbor-deterministic'
5
+ require 'cbor-canonical'
6
+
7
+ options = ''
8
+ while /\A-([cdetpqu]+)\z/ === ARGV[0]
9
+ options << $1
10
+ ARGV.shift
11
+ end
3
12
 
4
13
  ARGF.binmode
5
14
  i = ARGF.read
@@ -7,4 +16,10 @@ o,r = CBOR.decode_with_rest(i)
7
16
  if r != ''
8
17
  warn "** ignoring rest of #{r.bytesize} bytes after first CBOR data item"
9
18
  end
10
- puts o.cbor_diagnostic
19
+ o = o.to_packed_cbor if /p/ === options
20
+ o = o.to_unpacked_cbor if /q/ === options
21
+ o = o.cbor_prepare_deterministic if /d/ === options
22
+ o = o.cbor_pre_canonicalize if /c/ === options
23
+ puts o.cbor_diagnostic(try_decode_embedded: /e/ === options,
24
+ bytes_as_text: /t/ === options,
25
+ utf8: /u/ === options)
data/bin/cborseq2diag.rb CHANGED
@@ -1,8 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'cbor-diagnostic'
3
+ require 'cbor-packed'
4
+ require 'cbor-deterministic'
5
+ require 'cbor-canonical'
3
6
 
4
7
  options = ''
5
- while /\A-([etu]+)\z/ === ARGV[0]
8
+ while /\A-([cdetpqu]+)\z/ === ARGV[0]
6
9
  options << $1
7
10
  ARGV.shift
8
11
  end
@@ -11,6 +14,10 @@ ARGF.binmode
11
14
  i = ARGF.read
12
15
  while !i.empty?
13
16
  o, i = CBOR.decode_with_rest(i)
17
+ o = o.to_packed_cbor if /p/ === options
18
+ o = o.to_unpacked_cbor if /q/ === options
19
+ o = o.cbor_pre_canonicalize if /c/ === options
20
+ o = o.cbor_prepare_deterministic if /d/ === options
14
21
  out = o.cbor_diagnostic(try_decode_embedded: /e/ === options,
15
22
  bytes_as_text: /t/ === options,
16
23
  utf8: /u/ === options)
data/bin/cborseq2json.rb CHANGED
@@ -1,10 +1,22 @@
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-([cdpq]+)\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.to_packed_cbor if /p/ === options
18
+ o = o.to_unpacked_cbor if /q/ === options
19
+ o = o.cbor_pre_canonicalize if /c/ === options
20
+ o = o.cbor_prepare_deterministic if /d/ === options
9
21
  puts JSON.pretty_generate(o)
10
22
  end
@@ -2,10 +2,22 @@
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-([cdpq]+)\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.to_packed_cbor if /p/ === options
19
+ o = o.to_unpacked_cbor if /q/ === options
20
+ o = o.cbor_pre_canonicalize if /c/ === options
21
+ o = o.cbor_prepare_deterministic if /d/ === options
10
22
  puts JSON.neat_generate(o, after_comma: 1, after_colon: 1)
11
23
  end
@@ -4,8 +4,4 @@ require 'cbor-pretty'
4
4
 
5
5
  ARGF.binmode
6
6
  i = ARGF.read
7
- while !i.empty?
8
- o, ni = CBOR.decode_with_rest(i)
9
- puts CBOR::pretty(i[0...i.size-ni.size])
10
- i = ni
11
- end
7
+ puts CBOR::pretty_seq(i)
data/bin/cborseq2yaml.rb CHANGED
@@ -2,6 +2,9 @@
2
2
  require 'psych.rb' # WTF
3
3
  require 'yaml'
4
4
  require 'cbor-pure'
5
+ require 'cbor-packed'
6
+ require 'cbor-deterministic'
7
+ require 'cbor-canonical'
5
8
 
6
9
  class Array
7
10
  def to_yaml_style()
@@ -9,10 +12,21 @@ class Array
9
12
  end
10
13
  end
11
14
 
15
+ options = ''
16
+ while /\A-([cdpq]+)\z/ === ARGV[0]
17
+ options << $1
18
+ ARGV.shift
19
+ end
20
+
21
+
12
22
  ARGF.binmode
13
23
  i = ARGF.read
14
24
  while i != ''
15
25
  o, i = CBOR.decode_with_rest(i)
26
+ o = o.to_packed_cbor if /p/ === options
27
+ o = o.to_unpacked_cbor if /q/ === options
28
+ o = o.cbor_pre_canonicalize if /c/ === options
29
+ o = o.cbor_prepare_deterministic if /d/ === options
16
30
  puts YAML.dump(o)
17
31
  end
18
32
 
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
- print(CBOR::encode(result.to_rb))
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,45 @@
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-packed'
11
+ require 'cbor-deterministic'
12
+ require 'cbor-canonical'
13
+
14
+ options = ''
15
+ while /\A-([cdetpqu]+)\z/ === ARGV[0]
16
+ options << $1
17
+ ARGV.shift
18
+ end
19
+
20
+ def diagnostic(o, options)
21
+ o = o.to_packed_cbor if /p/ === options
22
+ o = o.to_unpacked_cbor if /q/ === options
23
+ o = o.cbor_pre_canonicalize if /c/ === options
24
+ o = o.cbor_prepare_deterministic if /d/ === options
25
+ puts o.cbor_diagnostic(try_decode_embedded: /e/ === options,
26
+ bytes_as_text: /t/ === options,
27
+ utf8: /u/ === options)
28
+ end
29
+
30
+ parser = CBOR_DIAGParser.new
31
+
32
+ i = ARGF.read.b # binary to work around treetop performance bug
33
+ if result = parser.parse(i)
34
+ decoded = result.to_rb
35
+ out = case decoded
36
+ when CBOR::Sequence
37
+ decoded.elements
38
+ else
39
+ [decoded]
40
+ end.map {|x| diagnostic(x, options)}.join(", ")
41
+ print out
42
+ else
43
+ puts "*** can't parse #{i}"
44
+ puts "*** #{parser.failure_reason}"
45
+ 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
- puts(CBOR::pretty(CBOR::encode(result.to_rb)))
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,23 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'json'
3
3
  require 'cbor-pure'
4
+ require 'cbor-packed'
5
+ require 'cbor-deterministic'
6
+ require 'cbor-canonical'
4
7
 
5
- if ARGV[0] == "-v"
6
- verbose = true
8
+ options = ''
9
+ while /\A-([cdpqv]+)\z/ === ARGV[0]
10
+ options << $1
7
11
  ARGV.shift
8
12
  end
9
13
 
10
14
  $stdout.binmode
11
15
  i = ARGF.read
12
- o = CBOR.encode(JSON.load(i))
16
+ o = JSON.load(i)
17
+ o = o.to_packed_cbor if /p/ === options
18
+ o = o.to_unpacked_cbor if /q/ === options
19
+ o = o.cbor_pre_canonicalize if /c/ === options
20
+ o = o.cbor_prepare_deterministic if /d/ === options
21
+ o = CBOR.encode(o)
13
22
  print o
14
- warn "JSON size: #{i.size} bytes, CBOR size: #{o.size} bytes." if verbose
23
+ warn "JSON size: #{i.size} bytes, CBOR size: #{o.size} bytes." if /v/ === options
data/bin/json2json.rb ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ require 'json'
3
+ require 'cbor-pure'
4
+ require 'cbor-packed'
5
+ require 'cbor-deterministic'
6
+ require 'cbor-canonical'
7
+
8
+ options = ''
9
+ while /\A-([cdpq]+)\z/ === ARGV[0]
10
+ options << $1
11
+ ARGV.shift
12
+ end
13
+
14
+ i = ARGF.read
15
+ o = JSON.load(i)
16
+ o = o.to_packed_cbor if /p/ === options
17
+ o = o.to_unpacked_cbor if /q/ === options
18
+ o = o.cbor_pre_canonicalize if /c/ === options
19
+ o = o.cbor_prepare_deterministic if /d/ === options
20
+ puts JSON.pretty_generate(o)
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+ require 'json'
3
+ require 'cbor-pure'
4
+ require 'neatjson'
5
+ require 'cbor-packed'
6
+ require 'cbor-deterministic'
7
+ require 'cbor-canonical'
8
+
9
+ options = ''
10
+ while /\A-([cdpq]+)\z/ === ARGV[0]
11
+ options << $1
12
+ ARGV.shift
13
+ end
14
+
15
+ $stdout.binmode
16
+ i = ARGF.read
17
+ o = JSON.load(i)
18
+ o = o.to_packed_cbor if /p/ === options
19
+ o = o.to_unpacked_cbor if /q/ === options
20
+ o = o.cbor_pre_canonicalize if /c/ === options
21
+ o = o.cbor_prepare_deterministic if /d/ === options
22
+ puts JSON.neat_generate(o, after_comma: 1, after_colon: 1)
data/bin/json2yaml.rb ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+ require 'psych.rb' # WTF
3
+ require 'yaml'
4
+ require 'json'
5
+ require 'cbor-pure'
6
+ require 'cbor-packed'
7
+ require 'cbor-deterministic'
8
+ require 'cbor-canonical'
9
+
10
+ class Array
11
+ def to_yaml_style()
12
+ all? {|x| Integer === x } && length < 20 ? :inline : super
13
+ end
14
+ end
15
+
16
+ options = ''
17
+ while /\A-([cdpq]+)\z/ === ARGV[0]
18
+ options << $1
19
+ ARGV.shift
20
+ end
21
+
22
+ i = ARGF.read
23
+ o = JSON.load(i)
24
+ o = o.to_packed_cbor if /p/ === options
25
+ o = o.to_unpacked_cbor if /q/ === options
26
+ o = o.cbor_pre_canonicalize if /c/ === options
27
+ o = o.cbor_prepare_deterministic if /d/ === options
28
+ puts YAML.dump(o)
data/bin/yaml2cbor.rb CHANGED
@@ -2,14 +2,23 @@
2
2
  require 'psych.rb' # WTF
3
3
  require 'yaml'
4
4
  require 'cbor-pure'
5
+ require 'cbor-packed'
6
+ require 'cbor-deterministic'
7
+ require 'cbor-canonical'
5
8
 
6
- if ARGV[0] == "-v"
7
- verbose = true
9
+ options = ''
10
+ while /\A-([cdpqv]+)\z/ === ARGV[0]
11
+ options << $1
8
12
  ARGV.shift
9
13
  end
10
14
 
11
15
  $stdout.binmode
12
16
  i = ARGF.read
13
- o = CBOR.encode(YAML.load(i))
17
+ o = YAML.load(i)
18
+ o = o.to_packed_cbor if /p/ === options
19
+ o = o.to_unpacked_cbor if /q/ === options
20
+ o = o.cbor_pre_canonicalize if /c/ === options
21
+ o = o.cbor_prepare_deterministic if /d/ === options
22
+ o = CBOR.encode(o)
14
23
  print o
15
- warn "YAML size: #{i.size} bytes, CBOR size: #{o.size} bytes." if verbose
24
+ warn "YAML size: #{i.size} bytes, CBOR size: #{o.size} bytes." if /v/ === options
data/bin/yaml2json.rb ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+ require 'json'
3
+ require 'psych.rb' # WTF
4
+ require 'yaml'
5
+ require 'cbor-pure'
6
+ require 'cbor-packed'
7
+ require 'cbor-deterministic'
8
+ require 'cbor-canonical'
9
+
10
+ options = ''
11
+ while /\A-([cdpq]+)\z/ === ARGV[0]
12
+ options << $1
13
+ ARGV.shift
14
+ end
15
+
16
+ i = ARGF.read
17
+ o = YAML.load(i)
18
+ o = o.to_packed_cbor if /p/ === options
19
+ o = o.to_unpacked_cbor if /q/ === options
20
+ o = o.cbor_pre_canonicalize if /c/ === options
21
+ o = o.cbor_prepare_deterministic if /d/ === options
22
+ 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.12"
3
+ s.version = "0.5.20"
4
4
  s.summary = "CBOR (Concise Binary Object Representation) diagnostic notation"
5
- s.description = %q{cbor-diag implements diagnostic notation for CBOR, RFC 7049}
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,7 @@ 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'
25
+ s.add_dependency 'cbor-packed'
23
26
  end
@@ -10,10 +10,38 @@ module CBOR_DIAG
10
10
 
11
11
  module Text0
12
12
  def ows1
13
- elements[0]
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 Text1
26
- def to_rb; value.to_rb end
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
- r2 = _nt_value
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
- r3 = _nt_ows
48
- s0 << r3
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(Text0)
54
- r0.extend(Text1)
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
- raise if @pos != @buffer.size
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.12
4
+ version: 0.5.20
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-02-18 00:00:00.000000000 Z
11
+ date: 2021-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,12 +66,55 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- description: cbor-diag implements diagnostic notation for CBOR, RFC 7049
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
+ - !ruby/object:Gem::Dependency
98
+ name: cbor-packed
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: cbor-diag implements diagnostic notation for CBOR, RFC 8949 and RFC 8742
70
112
  email: cabo@tzi.org
71
113
  executables:
72
114
  - cbor2diag.rb
73
115
  - cbor2json.rb
74
116
  - cbor2pretty.rb
117
+ - cbor2u8.rb
75
118
  - cbor2yaml.rb
76
119
  - cborleader2diag.rb
77
120
  - cborseq2diag.rb
@@ -80,18 +123,24 @@ executables:
80
123
  - cborseq2pretty.rb
81
124
  - cborseq2yaml.rb
82
125
  - diag2cbor.rb
126
+ - diag2diag.rb
83
127
  - diag2pretty.rb
84
128
  - json2cbor.rb
129
+ - json2json.rb
130
+ - json2neatjson.rb
85
131
  - json2pretty.rb
132
+ - json2yaml.rb
86
133
  - pretty2cbor.rb
87
134
  - pretty2diag.rb
88
135
  - yaml2cbor.rb
136
+ - yaml2json.rb
89
137
  extensions: []
90
138
  extra_rdoc_files: []
91
139
  files:
92
140
  - bin/cbor2diag.rb
93
141
  - bin/cbor2json.rb
94
142
  - bin/cbor2pretty.rb
143
+ - bin/cbor2u8.rb
95
144
  - bin/cbor2yaml.rb
96
145
  - bin/cborleader2diag.rb
97
146
  - bin/cborseq2diag.rb
@@ -100,12 +149,17 @@ files:
100
149
  - bin/cborseq2pretty.rb
101
150
  - bin/cborseq2yaml.rb
102
151
  - bin/diag2cbor.rb
152
+ - bin/diag2diag.rb
103
153
  - bin/diag2pretty.rb
104
154
  - bin/json2cbor.rb
155
+ - bin/json2json.rb
156
+ - bin/json2neatjson.rb
105
157
  - bin/json2pretty.rb
158
+ - bin/json2yaml.rb
106
159
  - bin/pretty2cbor.rb
107
160
  - bin/pretty2diag.rb
108
161
  - bin/yaml2cbor.rb
162
+ - bin/yaml2json.rb
109
163
  - cbor-diag.gemspec
110
164
  - lib/cbor-diag-parser.rb
111
165
  - lib/cbor-diagnostic.rb
@@ -131,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
185
  - !ruby/object:Gem::Version
132
186
  version: '0'
133
187
  requirements: []
134
- rubygems_version: 3.2.3
188
+ rubygems_version: 3.2.15
135
189
  signing_key:
136
190
  specification_version: 4
137
191
  summary: CBOR (Concise Binary Object Representation) diagnostic notation