cbor-diag 0.5.20 → 0.7.0

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: 8dbeccb9b1a15bac6beb52ab1388adddac2c19cf5fce92d2184de8120326fb5e
4
- data.tar.gz: ccd67a87d8e7c04518e0fc7852e4eac5076182cdbe58a97b7e2daea13acbfc53
3
+ metadata.gz: d46971cb4fe65291d5659c969853e2776bc803a4260d3831107ee5b801c0fc76
4
+ data.tar.gz: e54c7b33742851467b3b631220a65558f5493c61eb011a973a5283191d4cbe0c
5
5
  SHA512:
6
- metadata.gz: 1f1cadddbfc82820493a77b7c50eb1bbb365be5a61016ee155f5ab88895f667d4c789d03b6d8e78983b5a765d34c316053dfbe8b730716f3d2979061759624b4
7
- data.tar.gz: e3eff5464c68065fb23c2158fba3209880878edb8ecb04bc225bd757b572343f23513856da112377517f2318c5d8c0f2872579e2faa197088eda952ac4e01e48
6
+ metadata.gz: bbc73e462fd6fa8a3e44255d4d85847512a320a2e75d141c657849cd21fd1c975429fcaea9798e257ffb681bebec3c6f19d1f50461cc8f36b04a73592ba61fc8
7
+ data.tar.gz: dad9a127145e629293892154b6b7e51dde44151138f7596f006226ed238a6bc74740f291b40818123d435a25b0f6eb739cb67a8c7c74f3c1c49cd4ab207fe386
data/bin/cbor2diag.rb CHANGED
@@ -4,19 +4,11 @@ require 'cbor-packed'
4
4
  require 'cbor-deterministic'
5
5
  require 'cbor-canonical'
6
6
 
7
- options = ''
8
- while /\A-([cdetpqu]+)\z/ === ARGV[0]
9
- options << $1
10
- ARGV.shift
11
- end
7
+
8
+ require 'cbor-diagnostic-helper'
9
+ options = cbor_diagnostic_process_args("cdetpqu")
12
10
 
13
11
  ARGF.binmode
14
12
  i = ARGF.read
15
13
  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
20
- puts o.cbor_diagnostic(try_decode_embedded: /e/ === options,
21
- bytes_as_text: /t/ === options,
22
- utf8: /u/ === options)
14
+ puts cbor_diagnostic_output(o, options)
data/bin/cbor2json.rb CHANGED
@@ -5,17 +5,16 @@ require 'cbor-packed'
5
5
  require 'cbor-deterministic'
6
6
  require 'cbor-canonical'
7
7
 
8
- options = ''
9
- while /\A-([cdpq]+)\z/ === ARGV[0]
10
- options << $1
11
- ARGV.shift
12
- end
8
+
9
+ require 'cbor-diagnostic-helper'
10
+ options = cbor_diagnostic_process_args("cdpqj")
13
11
 
14
12
  ARGF.binmode
15
13
  i = ARGF.read
16
14
  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
15
+ o = cbor_diagnostic_item_processing(o, options)
16
+ if /j/ === options
17
+ require 'cbor-transform-j'
18
+ o = CBOR::Transform_j.new.transform(o)
19
+ end
21
20
  puts JSON.pretty_generate(o)
data/bin/cbor2yaml.rb CHANGED
@@ -12,17 +12,11 @@ class Array
12
12
  end
13
13
  end
14
14
 
15
- options = ''
16
- while /\A-([cdpq]+)\z/ === ARGV[0]
17
- options << $1
18
- ARGV.shift
19
- end
15
+ require 'cbor-diagnostic-helper'
16
+ options = cbor_diagnostic_process_args("cdpq")
20
17
 
21
18
  ARGF.binmode
22
19
  i = ARGF.read
23
20
  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
21
+ o = cbor_diagnostic_item_processing(o, options)
28
22
  puts YAML.dump(o)
@@ -4,11 +4,8 @@ require 'cbor-packed'
4
4
  require 'cbor-deterministic'
5
5
  require 'cbor-canonical'
6
6
 
7
- options = ''
8
- while /\A-([cdetpqu]+)\z/ === ARGV[0]
9
- options << $1
10
- ARGV.shift
11
- end
7
+ require 'cbor-diagnostic-helper'
8
+ options = cbor_diagnostic_process_args("cdetpqu")
12
9
 
13
10
  ARGF.binmode
14
11
  i = ARGF.read
@@ -16,10 +13,4 @@ o,r = CBOR.decode_with_rest(i)
16
13
  if r != ''
17
14
  warn "** ignoring rest of #{r.bytesize} bytes after first CBOR data item"
18
15
  end
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)
16
+ puts cbor_diagnostic_output(o, options)
data/bin/cborseq2diag.rb CHANGED
@@ -4,23 +4,20 @@ require 'cbor-packed'
4
4
  require 'cbor-deterministic'
5
5
  require 'cbor-canonical'
6
6
 
7
- options = ''
8
- while /\A-([cdetpqu]+)\z/ === ARGV[0]
9
- options << $1
10
- ARGV.shift
11
- end
7
+ require 'cbor-diagnostic-helper'
8
+ options = cbor_diagnostic_process_args("cdetpqu")
12
9
 
13
10
  ARGF.binmode
14
11
  i = ARGF.read
12
+ totalsize = i.bytesize
15
13
  while !i.empty?
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
21
- out = o.cbor_diagnostic(try_decode_embedded: /e/ === options,
22
- bytes_as_text: /t/ === options,
23
- utf8: /u/ === options)
14
+ begin
15
+ o, i = CBOR.decode_with_rest(i)
16
+ rescue Exception => e
17
+ puts "/ *** Garbage at byte #{totalsize-i.bytesize}: #{e.message} /"
18
+ exit 1
19
+ end
20
+ out = cbor_diagnostic_output(o, options)
24
21
  if i.empty?
25
22
  puts out
26
23
  else
data/bin/cborseq2json.rb CHANGED
@@ -4,19 +4,13 @@ require 'cbor-pure'
4
4
  require 'cbor-deterministic'
5
5
  require 'cbor-canonical'
6
6
 
7
- options = ''
8
- while /\A-([cdpq]+)\z/ === ARGV[0]
9
- options << $1
10
- ARGV.shift
11
- end
7
+ require 'cbor-diagnostic-helper'
8
+ options = cbor_diagnostic_process_args("cdpq")
12
9
 
13
10
  ARGF.binmode
14
11
  i = ARGF.read
15
12
  while i != ''
16
13
  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
+ o = cbor_diagnostic_item_processing(o, options)
21
15
  puts JSON.pretty_generate(o)
22
16
  end
@@ -5,19 +5,14 @@ require 'neatjson'
5
5
  require 'cbor-deterministic'
6
6
  require 'cbor-canonical'
7
7
 
8
- options = ''
9
- while /\A-([cdpq]+)\z/ === ARGV[0]
10
- options << $1
11
- ARGV.shift
12
- end
8
+
9
+ require 'cbor-diagnostic-helper'
10
+ options = cbor_diagnostic_process_args("cdpq")
13
11
 
14
12
  ARGF.binmode
15
13
  i = ARGF.read
16
14
  while i != ''
17
15
  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
16
+ o = cbor_diagnostic_item_processing(o, options)
22
17
  puts JSON.neat_generate(o, after_comma: 1, after_colon: 1)
23
18
  end
data/bin/cborseq2yaml.rb CHANGED
@@ -12,21 +12,17 @@ class Array
12
12
  end
13
13
  end
14
14
 
15
- options = ''
16
- while /\A-([cdpq]+)\z/ === ARGV[0]
17
- options << $1
18
- ARGV.shift
19
- end
15
+
16
+
17
+ require 'cbor-diagnostic-helper'
18
+ options = cbor_diagnostic_process_args("cdpq")
20
19
 
21
20
 
22
21
  ARGF.binmode
23
22
  i = ARGF.read
24
23
  while i != ''
25
24
  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
25
+ o = cbor_diagnostic_item_processing(o, options)
30
26
  puts YAML.dump(o)
31
27
  end
32
28
 
data/bin/diag2cbor.rb CHANGED
@@ -7,6 +7,9 @@ unless ''.respond_to? :b
7
7
  end
8
8
  require 'cbor-pretty'
9
9
 
10
+ require 'cbor-diagnostic-helper'
11
+ options = cbor_diagnostic_process_args("X") # XXX
12
+
10
13
  parser = CBOR_DIAGParser.new
11
14
 
12
15
  $stdout.binmode
data/bin/diag2diag.rb CHANGED
@@ -7,25 +7,9 @@ unless ''.respond_to? :b
7
7
  end
8
8
  require 'cbor-pretty'
9
9
  require 'cbor-diagnostic'
10
- require 'cbor-packed'
11
- require 'cbor-deterministic'
12
- require 'cbor-canonical'
13
10
 
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
11
+ require 'cbor-diagnostic-helper'
12
+ options = cbor_diagnostic_process_args("cdetpqu")
29
13
 
30
14
  parser = CBOR_DIAGParser.new
31
15
 
@@ -37,8 +21,8 @@ if result = parser.parse(i)
37
21
  decoded.elements
38
22
  else
39
23
  [decoded]
40
- end.map {|x| diagnostic(x, options)}.join(", ")
41
- print out
24
+ end.map {|x| cbor_diagnostic_output(x, options)}.join(", ")
25
+ puts out
42
26
  else
43
27
  puts "*** can't parse #{i}"
44
28
  puts "*** #{parser.failure_reason}"
data/bin/diag2pretty.rb CHANGED
@@ -4,6 +4,9 @@ require 'treetop'
4
4
  require 'cbor-diag-parser'
5
5
  require 'cbor-pretty'
6
6
 
7
+ require 'cbor-diagnostic-helper'
8
+ options = cbor_diagnostic_process_args("X") # XXX
9
+
7
10
  parser = CBOR_DIAGParser.new
8
11
 
9
12
  i = ARGF.read
data/bin/json2cbor.rb CHANGED
@@ -5,19 +5,18 @@ require 'cbor-packed'
5
5
  require 'cbor-deterministic'
6
6
  require 'cbor-canonical'
7
7
 
8
- options = ''
9
- while /\A-([cdpqv]+)\z/ === ARGV[0]
10
- options << $1
11
- ARGV.shift
12
- end
8
+
9
+ require 'cbor-diagnostic-helper'
10
+ options = cbor_diagnostic_process_args("cdpqvj")
13
11
 
14
12
  $stdout.binmode
15
13
  i = ARGF.read
16
14
  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
15
+ if /j/ === options
16
+ require 'cbor-transform-j'
17
+ o = CBOR::Transform_jr.new.transform(o)
18
+ end
19
+ o = cbor_diagnostic_item_processing(o, options)
21
20
  o = CBOR.encode(o)
22
21
  print o
23
22
  warn "JSON size: #{i.size} bytes, CBOR size: #{o.size} bytes." if /v/ === options
data/bin/json2json.rb CHANGED
@@ -5,16 +5,10 @@ require 'cbor-packed'
5
5
  require 'cbor-deterministic'
6
6
  require 'cbor-canonical'
7
7
 
8
- options = ''
9
- while /\A-([cdpq]+)\z/ === ARGV[0]
10
- options << $1
11
- ARGV.shift
12
- end
8
+ require 'cbor-diagnostic-helper'
9
+ options = cbor_diagnostic_process_args("cdpq")
13
10
 
14
11
  i = ARGF.read
15
12
  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
13
+ o = cbor_diagnostic_item_processing(o, options)
20
14
  puts JSON.pretty_generate(o)
data/bin/json2neatjson.rb CHANGED
@@ -6,17 +6,10 @@ require 'cbor-packed'
6
6
  require 'cbor-deterministic'
7
7
  require 'cbor-canonical'
8
8
 
9
- options = ''
10
- while /\A-([cdpq]+)\z/ === ARGV[0]
11
- options << $1
12
- ARGV.shift
13
- end
9
+ require 'cbor-diagnostic-helper'
10
+ options = cbor_diagnostic_process_args("cdpq")
14
11
 
15
- $stdout.binmode
16
12
  i = ARGF.read
17
13
  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
14
+ o = cbor_diagnostic_item_processing(o, options)
22
15
  puts JSON.neat_generate(o, after_comma: 1, after_colon: 1)
data/bin/json2yaml.rb CHANGED
@@ -13,16 +13,10 @@ class Array
13
13
  end
14
14
  end
15
15
 
16
- options = ''
17
- while /\A-([cdpq]+)\z/ === ARGV[0]
18
- options << $1
19
- ARGV.shift
20
- end
16
+ require 'cbor-diagnostic-helper'
17
+ options = cbor_diagnostic_process_args("cdpq")
21
18
 
22
19
  i = ARGF.read
23
20
  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
21
+ o = cbor_diagnostic_item_processing(o, options)
28
22
  puts YAML.dump(o)
data/bin/pretty2diag.rb CHANGED
@@ -7,6 +7,11 @@ def extractbytes(s)
7
7
  s.each_line.map {|ln| ln.sub(/#.*/, '')}.join.scan(/[0-9a-fA-F][0-9a-fA-F]/).map {|b| b.to_i(16).chr(Encoding::BINARY)}.join
8
8
  end
9
9
 
10
+
11
+ require 'cbor-diagnostic-helper'
12
+ options = cbor_diagnostic_process_args("cdetpqu")
13
+
14
+
10
15
  i = extractbytes(ARGF)
11
16
  o = CBOR.decode(i)
12
- puts o.cbor_diagnostic
17
+ puts cbor_diagnostic_output(o, options)
data/bin/yaml2cbor.rb CHANGED
@@ -6,19 +6,13 @@ require 'cbor-packed'
6
6
  require 'cbor-deterministic'
7
7
  require 'cbor-canonical'
8
8
 
9
- options = ''
10
- while /\A-([cdpqv]+)\z/ === ARGV[0]
11
- options << $1
12
- ARGV.shift
13
- end
9
+ require 'cbor-diagnostic-helper'
10
+ options = cbor_diagnostic_process_args("cdpqv")
14
11
 
15
12
  $stdout.binmode
16
13
  i = ARGF.read
17
14
  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
15
+ o = cbor_diagnostic_item_processing(o, options)
22
16
  o = CBOR.encode(o)
23
17
  print o
24
18
  warn "YAML size: #{i.size} bytes, CBOR size: #{o.size} bytes." if /v/ === options
data/bin/yaml2json.rb CHANGED
@@ -7,16 +7,10 @@ require 'cbor-packed'
7
7
  require 'cbor-deterministic'
8
8
  require 'cbor-canonical'
9
9
 
10
- options = ''
11
- while /\A-([cdpq]+)\z/ === ARGV[0]
12
- options << $1
13
- ARGV.shift
14
- end
10
+ require 'cbor-diagnostic-helper'
11
+ options = cbor_diagnostic_process_args("cdpq")
15
12
 
16
13
  i = ARGF.read
17
14
  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
15
+ o = cbor_diagnostic_item_processing(o, options)
22
16
  puts JSON.pretty_generate(o)
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.5.20"
3
+ s.version = "0.7.0"
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"
@@ -226,18 +226,24 @@ module CBOR_DIAG
226
226
  r11 = SyntaxNode.new(input, (index-1)...index) if r11 == true
227
227
  r0 = r11
228
228
  else
229
- r12 = _nt_embedded
229
+ r12 = _nt_appstring
230
230
  if r12
231
231
  r12 = SyntaxNode.new(input, (index-1)...index) if r12 == true
232
232
  r0 = r12
233
233
  else
234
- r13 = _nt_streamstring
234
+ r13 = _nt_embedded
235
235
  if r13
236
236
  r13 = SyntaxNode.new(input, (index-1)...index) if r13 == true
237
237
  r0 = r13
238
238
  else
239
- @index = i0
240
- r0 = nil
239
+ r14 = _nt_streamstring
240
+ if r14
241
+ r14 = SyntaxNode.new(input, (index-1)...index) if r14 == true
242
+ r0 = r14
243
+ else
244
+ @index = i0
245
+ r0 = nil
246
+ end
241
247
  end
242
248
  end
243
249
  end
@@ -1519,6 +1525,131 @@ module CBOR_DIAG
1519
1525
  r0
1520
1526
  end
1521
1527
 
1528
+ module Appstring0
1529
+ end
1530
+
1531
+ module Appstring1
1532
+ def a
1533
+ elements[0]
1534
+ end
1535
+
1536
+ def s
1537
+ elements[2]
1538
+ end
1539
+
1540
+ end
1541
+
1542
+ module Appstring2
1543
+ #'
1544
+ def to_rb
1545
+ data = s.elements.map(&:partval).join.b
1546
+ app = a.text_value
1547
+ # Find a better place to put a default initialization
1548
+ CBOR_DIAG::APPS ||= Hash.new { |h, k|
1549
+ h[k] = begin CBOR_DIAG.const_get("App_#{app}")
1550
+ rescue NameError
1551
+ raise ArgumentError.new("cbor-diagnostic: Unknown application-oriented extension #{k}")
1552
+ end
1553
+ }
1554
+ CBOR_DIAG::APPS[app].decode(app, data)
1555
+ end
1556
+ end
1557
+
1558
+ def _nt_appstring
1559
+ start_index = index
1560
+ if node_cache[:appstring].has_key?(index)
1561
+ cached = node_cache[:appstring][index]
1562
+ if cached
1563
+ node_cache[:appstring][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
1564
+ @index = cached.interval.end
1565
+ end
1566
+ return cached
1567
+ end
1568
+
1569
+ i0, s0 = index, []
1570
+ i1, s1 = index, []
1571
+ if has_terminal?(@regexps[gr = '\A[a-z]'] ||= Regexp.new(gr), :regexp, index)
1572
+ r2 = true
1573
+ @index += 1
1574
+ else
1575
+ terminal_parse_failure('[a-z]')
1576
+ r2 = nil
1577
+ end
1578
+ s1 << r2
1579
+ if r2
1580
+ s3, i3 = [], index
1581
+ loop do
1582
+ if has_terminal?(@regexps[gr = '\A[a-z0-9]'] ||= Regexp.new(gr), :regexp, index)
1583
+ r4 = true
1584
+ @index += 1
1585
+ else
1586
+ terminal_parse_failure('[a-z0-9]')
1587
+ r4 = nil
1588
+ end
1589
+ if r4
1590
+ s3 << r4
1591
+ else
1592
+ break
1593
+ end
1594
+ end
1595
+ r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
1596
+ s1 << r3
1597
+ end
1598
+ if s1.last
1599
+ r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
1600
+ r1.extend(Appstring0)
1601
+ else
1602
+ @index = i1
1603
+ r1 = nil
1604
+ end
1605
+ s0 << r1
1606
+ if r1
1607
+ if (match_len = has_terminal?("'", false, index))
1608
+ r5 = true
1609
+ @index += match_len
1610
+ else
1611
+ terminal_parse_failure('"\'"')
1612
+ r5 = nil
1613
+ end
1614
+ s0 << r5
1615
+ if r5
1616
+ s6, i6 = [], index
1617
+ loop do
1618
+ r7 = _nt_bstring_part
1619
+ if r7
1620
+ s6 << r7
1621
+ else
1622
+ break
1623
+ end
1624
+ end
1625
+ r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
1626
+ s0 << r6
1627
+ if r6
1628
+ if (match_len = has_terminal?("'", false, index))
1629
+ r8 = true
1630
+ @index += match_len
1631
+ else
1632
+ terminal_parse_failure('"\'"')
1633
+ r8 = nil
1634
+ end
1635
+ s0 << r8
1636
+ end
1637
+ end
1638
+ end
1639
+ if s0.last
1640
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
1641
+ r0.extend(Appstring1)
1642
+ r0.extend(Appstring2)
1643
+ else
1644
+ @index = i0
1645
+ r0 = nil
1646
+ end
1647
+
1648
+ node_cache[:appstring][start_index] = r0
1649
+
1650
+ r0
1651
+ end
1652
+
1522
1653
  module Bstring0
1523
1654
  def s
1524
1655
  elements[1]
@@ -0,0 +1,17 @@
1
+ require 'time'
2
+
3
+ # Using Time#iso8601 creates the following bugs:
4
+ # * dt'1970-01-01T10:00:00' is accepted and gives local time
5
+ # * dt'1970-01-01T10:00:00.0Z' gives an integer instead of a float
6
+ # Probably should copy over Time#xmlschema and fix that for us.
7
+
8
+ class CBOR_DIAG::App_dt
9
+ def self.decode(_, s)
10
+ t = Time.iso8601(s)
11
+ if t.subsec != 0
12
+ t.to_f
13
+ else
14
+ t.to_i
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,35 @@
1
+ require 'cbor-packed'
2
+ require 'cbor-deterministic'
3
+ require 'cbor-canonical'
4
+
5
+ def cbor_diagnostic_process_args(chars)
6
+ options = ''
7
+ while /\A-(?:([#{chars}]+)|a(.*))\z/ === ARGV[0]
8
+ ARGV.shift
9
+ if $1
10
+ options << $1
11
+ else
12
+ s = $2
13
+ s = ARGV.shift if s == ""
14
+ s.split(",").each do |a|
15
+ require "cbor-diagnostic-app/#{a}"
16
+ end
17
+ end
18
+ end
19
+ options
20
+ end
21
+
22
+ def cbor_diagnostic_item_processing(o, options)
23
+ o = o.to_packed_cbor if /p/ === options
24
+ o = o.to_unpacked_cbor if /q/ === options
25
+ o = o.cbor_pre_canonicalize if /c/ === options
26
+ o = o.cbor_prepare_deterministic if /d/ === options
27
+ o
28
+ end
29
+
30
+ def cbor_diagnostic_output(o, options)
31
+ o = cbor_diagnostic_item_processing(o, options)
32
+ o.cbor_diagnostic(try_decode_embedded: /e/ === options,
33
+ bytes_as_text: /t/ === options,
34
+ utf8: /u/ === options)
35
+ end
@@ -0,0 +1,3 @@
1
+ require 'treetop'
2
+ require 'cbor-diag-parser'
3
+
@@ -0,0 +1,68 @@
1
+ require 'cbor-transform'
2
+ unless defined?(JSON)
3
+ require 'json'
4
+ end
5
+ require 'base64'
6
+
7
+ class CBOR::Transform_j < CBOR::Transform
8
+
9
+ # CBOR::Transform_j.new(1).transform [1, "a", "b".b, CBOR::Simple.new(2), CBOR::Tagged.new(1, 2), {"a"=> 1, 2=> 3}]
10
+
11
+ def transform_simple(obj)
12
+ {'@@!s': obj.value}
13
+ end
14
+
15
+ def transform_bytes(obj)
16
+ {'@@!b': ::Base64.urlsafe_encode64(obj, padding: false)}
17
+ end
18
+
19
+ def transform_hash(obj)
20
+ Hash[obj.map {|k, v| [ (
21
+ kt = transform(k)
22
+ if (String === kt && kt.encoding != Encoding::BINARY)
23
+ kt
24
+ else
25
+ '@@!:' << JSON.generate(kt)
26
+ end
27
+ ),
28
+ transform(v)]}]
29
+ end
30
+
31
+ def transform_tag(obj)
32
+ {"@@!t#{obj.tag}": transform(obj.value)}
33
+ end
34
+
35
+ end
36
+
37
+ class CBOR::Transform_jr < CBOR::Transform
38
+
39
+ # >> CBOR::Transform_jr.new(1).transform(JSON.parse(JSON.generate(a = CBOR::Transform_j.new(1).transform([1, "a", "b".b, CBOR::Simple.new(2), CBOR::Tagged.new(1, 2), {"a"=> 1, 2=> 3, {3=>4}=>5}]))))
40
+ # => [1, "a", "b", #<struct CBOR::Simple value=2>, #<struct CBOR::Tagged tag=1, value=2>, {"a"=>1, 2=>3, {3=>4}=>5}]
41
+ # >> a
42
+ # => [1, "a", {:"@@!b"=>"Yg"}, {:"@@!s"=>2}, {:"@@!t1"=>2}, {"a"=>1, "@@!:2"=>3, "@@!:{\"@@!:3\":4}"=>5}]
43
+
44
+ def transform_hash(obj)
45
+ if obj.size == 1 && obj.keys.first =~ /\A@@!([a-z].*)/
46
+ cookie = $1
47
+ value = obj.values.first
48
+ case cookie
49
+ when "s"
50
+ CBOR::Simple.new(value)
51
+ when "b"
52
+ ::Base64.urlsafe_decode64(value)
53
+ when /\At(\d+)\z/
54
+ CBOR::Tagged.new($1.to_i, value)
55
+ else
56
+ fail ArgumentError.new("Unknown CBOR-JSON encoding @@!#{cookie}")
57
+ end
58
+ else
59
+ Hash[obj.map {|k, v| [ transform(
60
+ if k =~ /\A@@!:(.*)\z/
61
+ JSON.parse($1)
62
+ else
63
+ k
64
+ end), transform(v)]}]
65
+ end
66
+ end
67
+
68
+ end
@@ -0,0 +1,72 @@
1
+ class CBOR::Transform
2
+
3
+ def transform(obj)
4
+ case obj
5
+ when NilClass
6
+ transform_nil(obj)
7
+ when FalseClass, TrueClass
8
+ transform_bool(obj)
9
+ when CBOR::Simple
10
+ transform_simple(obj)
11
+ when Float
12
+ transform_float(obj)
13
+ when Integer
14
+ transform_integer(obj)
15
+ # XXX should probably handle Symbol
16
+ when String
17
+ case obj.encoding
18
+ when Encoding::BINARY
19
+ transform_bytes(obj)
20
+ else
21
+ transform_text(obj)
22
+ end
23
+ when Array
24
+ transform_array(obj)
25
+ when Hash
26
+ transform_hash(obj)
27
+ when CBOR::Tagged
28
+ transform_tag(obj)
29
+ end
30
+ end
31
+
32
+ def transform_nil(obj)
33
+ obj
34
+ end
35
+
36
+ def transform_bool(obj)
37
+ obj
38
+ end
39
+
40
+ def transform_simple(obj)
41
+ obj
42
+ end
43
+
44
+ def transform_float(obj)
45
+ obj
46
+ end
47
+
48
+ def transform_integer(obj)
49
+ obj
50
+ end
51
+
52
+ def transform_bytes(obj)
53
+ obj
54
+ end
55
+
56
+ def transform_text(obj)
57
+ obj
58
+ end
59
+
60
+ def transform_array(obj)
61
+ obj.map {|x| transform(x)}
62
+ end
63
+
64
+ def transform_hash(obj)
65
+ Hash[obj.map {|k, v| [transform(k), transform(v)]}]
66
+ end
67
+
68
+ def transform_tag(obj)
69
+ CBOR::Tagged.new(transform(obj.tag), transform(obj.value))
70
+ end
71
+
72
+ end
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.20
4
+ version: 0.7.0
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-05-04 00:00:00.000000000 Z
11
+ date: 2021-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -162,9 +162,14 @@ files:
162
162
  - bin/yaml2json.rb
163
163
  - cbor-diag.gemspec
164
164
  - lib/cbor-diag-parser.rb
165
+ - lib/cbor-diagnostic-app/dt.rb
166
+ - lib/cbor-diagnostic-helper.rb
167
+ - lib/cbor-diagnostic-parser.rb
165
168
  - lib/cbor-diagnostic.rb
166
169
  - lib/cbor-pretty.rb
167
170
  - lib/cbor-pure.rb
171
+ - lib/cbor-transform-j.rb
172
+ - lib/cbor-transform.rb
168
173
  - lib/half.rb
169
174
  homepage: http://cbor.io/
170
175
  licenses:
@@ -185,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
190
  - !ruby/object:Gem::Version
186
191
  version: '0'
187
192
  requirements: []
188
- rubygems_version: 3.2.15
193
+ rubygems_version: 3.2.22
189
194
  signing_key:
190
195
  specification_version: 4
191
196
  summary: CBOR (Concise Binary Object Representation) diagnostic notation