cbor-diag 0.5.1 → 0.5.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/bin/cbor2diag.rb +7 -1
- data/bin/cborleader2diag.rb +10 -0
- data/bin/cborseq2json.rb +10 -0
- data/bin/cborseq2neatjson.rb +11 -0
- data/bin/cborseq2yaml.rb +18 -0
- data/bin/diag2cbor.rb +1 -1
- data/cbor-diag.gemspec +2 -1
- data/lib/cbor-diag-parser.rb +44 -44
- data/lib/cbor-diagnostic.rb +14 -0
- metadata +28 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0ff7cbffe3a27ed58ea0b1c9478f4f2a30686a92c83acf0f02bd40788cd906e3
|
4
|
+
data.tar.gz: 222e4f6b162f6135858d200177709cdb86bb5483fb0251e38bfec8972d7ecc39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1856ce392669ee1466e28d686fd592fd2e6ea5ebfcbce2d70bb5ed1f128771e21bb6a06144a6e81af486374189b854fc23d51d2d1b9598330dc0eda34b89ddb5
|
7
|
+
data.tar.gz: 6dc160dd22f6a858eb80ce4d77e5888e23a28b9b535bf4008be875721e6d7ee12983f0d3a8bbc69e9521e15a2dcd9ccee41e07169acc996be264f9d1a1bc6233
|
data/bin/cbor2diag.rb
CHANGED
data/bin/cborseq2json.rb
ADDED
data/bin/cborseq2yaml.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'psych.rb' # WTF
|
3
|
+
require 'yaml'
|
4
|
+
require 'cbor-pure'
|
5
|
+
|
6
|
+
class Array
|
7
|
+
def to_yaml_style()
|
8
|
+
all? {|x| Integer === x } && length < 20 ? :inline : super
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
ARGF.binmode
|
13
|
+
i = ARGF.read
|
14
|
+
while i != ''
|
15
|
+
o, i = CBOR.decode_with_rest(i)
|
16
|
+
puts YAML.dump(o)
|
17
|
+
end
|
18
|
+
|
data/bin/diag2cbor.rb
CHANGED
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.
|
3
|
+
s.version = "0.5.7"
|
4
4
|
s.summary = "CBOR (Concise Binary Object Representation) diagnostic notation"
|
5
5
|
s.description = %q{cbor-diag implements diagnostic notation for CBOR, RFC 7049}
|
6
6
|
s.author = "Carsten Bormann"
|
@@ -19,4 +19,5 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.add_development_dependency 'bundler', '~>1'
|
20
20
|
s.add_dependency 'treetop', '~>1'
|
21
21
|
s.add_dependency 'json'
|
22
|
+
s.add_dependency 'neatjson'
|
22
23
|
end
|
data/lib/cbor-diag-parser.rb
CHANGED
@@ -74,62 +74,62 @@ module CBOR_DIAG
|
|
74
74
|
end
|
75
75
|
|
76
76
|
i0 = index
|
77
|
-
r1 =
|
77
|
+
r1 = _nt_string
|
78
78
|
if r1
|
79
79
|
r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
|
80
80
|
r0 = r1
|
81
81
|
else
|
82
|
-
r2 =
|
82
|
+
r2 = _nt_map
|
83
83
|
if r2
|
84
84
|
r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
|
85
85
|
r0 = r2
|
86
86
|
else
|
87
|
-
r3 =
|
87
|
+
r3 = _nt_array
|
88
88
|
if r3
|
89
89
|
r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
|
90
90
|
r0 = r3
|
91
91
|
else
|
92
|
-
r4 =
|
92
|
+
r4 = _nt_tagged
|
93
93
|
if r4
|
94
94
|
r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
|
95
95
|
r0 = r4
|
96
96
|
else
|
97
|
-
r5 =
|
97
|
+
r5 = _nt_hnumber
|
98
98
|
if r5
|
99
99
|
r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
|
100
100
|
r0 = r5
|
101
101
|
else
|
102
|
-
r6 =
|
102
|
+
r6 = _nt_fnumber
|
103
103
|
if r6
|
104
104
|
r6 = SyntaxNode.new(input, (index-1)...index) if r6 == true
|
105
105
|
r0 = r6
|
106
106
|
else
|
107
|
-
r7 =
|
107
|
+
r7 = _nt_infin
|
108
108
|
if r7
|
109
109
|
r7 = SyntaxNode.new(input, (index-1)...index) if r7 == true
|
110
110
|
r0 = r7
|
111
111
|
else
|
112
|
-
r8 =
|
112
|
+
r8 = _nt_simple
|
113
113
|
if r8
|
114
114
|
r8 = SyntaxNode.new(input, (index-1)...index) if r8 == true
|
115
115
|
r0 = r8
|
116
116
|
else
|
117
|
-
r9 =
|
117
|
+
r9 = _nt_hstring
|
118
118
|
if r9
|
119
119
|
r9 = SyntaxNode.new(input, (index-1)...index) if r9 == true
|
120
120
|
r0 = r9
|
121
121
|
else
|
122
|
-
r10 =
|
122
|
+
r10 = _nt_bstring
|
123
123
|
if r10
|
124
124
|
r10 = SyntaxNode.new(input, (index-1)...index) if r10 == true
|
125
125
|
r0 = r10
|
126
126
|
else
|
127
|
-
r11 =
|
127
|
+
r11 = _nt_b64string
|
128
128
|
if r11
|
129
129
|
r11 = SyntaxNode.new(input, (index-1)...index) if r11 == true
|
130
130
|
r0 = r11
|
131
131
|
else
|
132
|
-
r12 =
|
132
|
+
r12 = _nt_embedded
|
133
133
|
if r12
|
134
134
|
r12 = SyntaxNode.new(input, (index-1)...index) if r12 == true
|
135
135
|
r0 = r12
|
@@ -936,7 +936,7 @@ module CBOR_DIAG
|
|
936
936
|
module String1
|
937
937
|
#'
|
938
938
|
def to_rb
|
939
|
-
s.elements.map(&:partval).join
|
939
|
+
s.elements.map(&:partval).join.force_encoding(Encoding::UTF_8)
|
940
940
|
end
|
941
941
|
end
|
942
942
|
|
@@ -1033,7 +1033,7 @@ module CBOR_DIAG
|
|
1033
1033
|
|
1034
1034
|
module StringPart6
|
1035
1035
|
def partval; (((s.text_value.to_i(16) & 0x3FF) << 10) +
|
1036
|
-
(t.text_value.to_i(16) & 0x3FF) + 0x10000).chr(Encoding::UTF_8) end
|
1036
|
+
(t.text_value.to_i(16) & 0x3FF) + 0x10000).chr(Encoding::UTF_8).b end
|
1037
1037
|
end
|
1038
1038
|
|
1039
1039
|
module StringPart7
|
@@ -1049,7 +1049,7 @@ module CBOR_DIAG
|
|
1049
1049
|
end
|
1050
1050
|
|
1051
1051
|
module StringPart10
|
1052
|
-
def partval; s.text_value.to_i(16).chr(Encoding::UTF_8) end
|
1052
|
+
def partval; s.text_value.to_i(16).chr(Encoding::UTF_8).b end
|
1053
1053
|
end
|
1054
1054
|
|
1055
1055
|
def _nt_string_part
|
@@ -1459,7 +1459,7 @@ module CBOR_DIAG
|
|
1459
1459
|
if r1
|
1460
1460
|
s2, i2 = [], index
|
1461
1461
|
loop do
|
1462
|
-
r3 =
|
1462
|
+
r3 = _nt_bstring_part
|
1463
1463
|
if r3
|
1464
1464
|
s2 << r3
|
1465
1465
|
else
|
@@ -1493,17 +1493,17 @@ module CBOR_DIAG
|
|
1493
1493
|
r0
|
1494
1494
|
end
|
1495
1495
|
|
1496
|
-
module
|
1496
|
+
module BstringPart0
|
1497
1497
|
def partval; text_value end
|
1498
1498
|
end
|
1499
1499
|
|
1500
|
-
module
|
1500
|
+
module BstringPart1
|
1501
1501
|
def s
|
1502
1502
|
elements[1]
|
1503
1503
|
end
|
1504
1504
|
end
|
1505
1505
|
|
1506
|
-
module
|
1506
|
+
module BstringPart2
|
1507
1507
|
#"
|
1508
1508
|
def partval
|
1509
1509
|
v = s.text_value
|
@@ -1511,13 +1511,13 @@ module CBOR_DIAG
|
|
1511
1511
|
end
|
1512
1512
|
end
|
1513
1513
|
|
1514
|
-
module
|
1514
|
+
module BstringPart3
|
1515
1515
|
end
|
1516
1516
|
|
1517
|
-
module
|
1517
|
+
module BstringPart4
|
1518
1518
|
end
|
1519
1519
|
|
1520
|
-
module
|
1520
|
+
module BstringPart5
|
1521
1521
|
def s
|
1522
1522
|
elements[1]
|
1523
1523
|
end
|
@@ -1527,33 +1527,33 @@ module CBOR_DIAG
|
|
1527
1527
|
end
|
1528
1528
|
end
|
1529
1529
|
|
1530
|
-
module
|
1530
|
+
module BstringPart6
|
1531
1531
|
def partval; (((s.text_value.to_i(16) & 0x3FF) << 10) +
|
1532
1532
|
(t.text_value.to_i(16) & 0x3FF) + 0x10000).chr(Encoding::UTF_8) end
|
1533
1533
|
end
|
1534
1534
|
|
1535
|
-
module
|
1535
|
+
module BstringPart7
|
1536
1536
|
end
|
1537
1537
|
|
1538
|
-
module
|
1538
|
+
module BstringPart8
|
1539
1539
|
end
|
1540
1540
|
|
1541
|
-
module
|
1541
|
+
module BstringPart9
|
1542
1542
|
def s
|
1543
1543
|
elements[1]
|
1544
1544
|
end
|
1545
1545
|
end
|
1546
1546
|
|
1547
|
-
module
|
1547
|
+
module BstringPart10
|
1548
1548
|
def partval; s.text_value.to_i(16).chr(Encoding::UTF_8) end
|
1549
1549
|
end
|
1550
1550
|
|
1551
|
-
def
|
1551
|
+
def _nt_bstring_part
|
1552
1552
|
start_index = index
|
1553
|
-
if node_cache[:
|
1554
|
-
cached = node_cache[:
|
1553
|
+
if node_cache[:bstring_part].has_key?(index)
|
1554
|
+
cached = node_cache[:bstring_part][index]
|
1555
1555
|
if cached
|
1556
|
-
node_cache[:
|
1556
|
+
node_cache[:bstring_part][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
1557
1557
|
@index = cached.interval.end
|
1558
1558
|
end
|
1559
1559
|
return cached
|
@@ -1580,8 +1580,8 @@ module CBOR_DIAG
|
|
1580
1580
|
r1 = nil
|
1581
1581
|
else
|
1582
1582
|
r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
|
1583
|
-
r1.extend(
|
1584
|
-
r1.extend(
|
1583
|
+
r1.extend(BstringPart0)
|
1584
|
+
r1.extend(BstringPart0)
|
1585
1585
|
end
|
1586
1586
|
if r1
|
1587
1587
|
r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
|
@@ -1608,8 +1608,8 @@ module CBOR_DIAG
|
|
1608
1608
|
end
|
1609
1609
|
if s3.last
|
1610
1610
|
r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
|
1611
|
-
r3.extend(
|
1612
|
-
r3.extend(
|
1611
|
+
r3.extend(BstringPart1)
|
1612
|
+
r3.extend(BstringPart2)
|
1613
1613
|
else
|
1614
1614
|
@index = i3
|
1615
1615
|
r3 = nil
|
@@ -1679,7 +1679,7 @@ module CBOR_DIAG
|
|
1679
1679
|
end
|
1680
1680
|
if s8.last
|
1681
1681
|
r8 = instantiate_node(SyntaxNode,input, i8...index, s8)
|
1682
|
-
r8.extend(
|
1682
|
+
r8.extend(BstringPart3)
|
1683
1683
|
else
|
1684
1684
|
@index = i8
|
1685
1685
|
r8 = nil
|
@@ -1746,7 +1746,7 @@ module CBOR_DIAG
|
|
1746
1746
|
end
|
1747
1747
|
if s14.last
|
1748
1748
|
r14 = instantiate_node(SyntaxNode,input, i14...index, s14)
|
1749
|
-
r14.extend(
|
1749
|
+
r14.extend(BstringPart4)
|
1750
1750
|
else
|
1751
1751
|
@index = i14
|
1752
1752
|
r14 = nil
|
@@ -1757,8 +1757,8 @@ module CBOR_DIAG
|
|
1757
1757
|
end
|
1758
1758
|
if s6.last
|
1759
1759
|
r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
|
1760
|
-
r6.extend(
|
1761
|
-
r6.extend(
|
1760
|
+
r6.extend(BstringPart5)
|
1761
|
+
r6.extend(BstringPart6)
|
1762
1762
|
else
|
1763
1763
|
@index = i6
|
1764
1764
|
r6 = nil
|
@@ -1819,7 +1819,7 @@ module CBOR_DIAG
|
|
1819
1819
|
end
|
1820
1820
|
if s22.last
|
1821
1821
|
r22 = instantiate_node(SyntaxNode,input, i22...index, s22)
|
1822
|
-
r22.extend(
|
1822
|
+
r22.extend(BstringPart7)
|
1823
1823
|
else
|
1824
1824
|
@index = i22
|
1825
1825
|
r22 = nil
|
@@ -1879,7 +1879,7 @@ module CBOR_DIAG
|
|
1879
1879
|
end
|
1880
1880
|
if s26.last
|
1881
1881
|
r26 = instantiate_node(SyntaxNode,input, i26...index, s26)
|
1882
|
-
r26.extend(
|
1882
|
+
r26.extend(BstringPart8)
|
1883
1883
|
else
|
1884
1884
|
@index = i26
|
1885
1885
|
r26 = nil
|
@@ -1896,8 +1896,8 @@ module CBOR_DIAG
|
|
1896
1896
|
end
|
1897
1897
|
if s19.last
|
1898
1898
|
r19 = instantiate_node(SyntaxNode,input, i19...index, s19)
|
1899
|
-
r19.extend(
|
1900
|
-
r19.extend(
|
1899
|
+
r19.extend(BstringPart9)
|
1900
|
+
r19.extend(BstringPart10)
|
1901
1901
|
else
|
1902
1902
|
@index = i19
|
1903
1903
|
r19 = nil
|
@@ -1913,7 +1913,7 @@ module CBOR_DIAG
|
|
1913
1913
|
end
|
1914
1914
|
end
|
1915
1915
|
|
1916
|
-
node_cache[:
|
1916
|
+
node_cache[:bstring_part][start_index] = r0
|
1917
1917
|
|
1918
1918
|
r0
|
1919
1919
|
end
|
data/lib/cbor-diagnostic.rb
CHANGED
@@ -46,6 +46,20 @@ class String
|
|
46
46
|
"(_ #{lengths.map{|l| r = self[pos, l].cbor_diagnostic(options); pos += l; r}.join(", ")})"
|
47
47
|
else
|
48
48
|
if encoding == Encoding::BINARY
|
49
|
+
if options[:try_decode_embedded] && self != ''
|
50
|
+
begin
|
51
|
+
rest = self
|
52
|
+
result = []
|
53
|
+
while rest != ''
|
54
|
+
dv, rest = CBOR.decode_with_rest(rest)
|
55
|
+
result << dv
|
56
|
+
end
|
57
|
+
return "<< #{result.map{|x| x.cbor_diagnostic(options)}.join(", ")} >>"
|
58
|
+
rescue RuntimeError => e
|
59
|
+
# that didn't work out, so continue with other options
|
60
|
+
# puts e.backtrace
|
61
|
+
end
|
62
|
+
end
|
49
63
|
if options[:bytes_as_text] && (u8 = dup.force_encoding(Encoding::UTF_8)).valid_encoding?
|
50
64
|
"'#{u8.cbor_diagnostic(options)[1..-2].gsub("'", "\\\\'")}'" # \' is a backref, so needs \\'
|
51
65
|
else
|
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.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carsten Bormann
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: neatjson
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description: cbor-diag implements diagnostic notation for CBOR, RFC 7049
|
56
70
|
email: cabo@tzi.org
|
57
71
|
executables:
|
@@ -59,6 +73,10 @@ executables:
|
|
59
73
|
- cbor2json.rb
|
60
74
|
- cbor2pretty.rb
|
61
75
|
- cbor2yaml.rb
|
76
|
+
- cborleader2diag.rb
|
77
|
+
- cborseq2json.rb
|
78
|
+
- cborseq2neatjson.rb
|
79
|
+
- cborseq2yaml.rb
|
62
80
|
- diag2cbor.rb
|
63
81
|
- diag2pretty.rb
|
64
82
|
- json2cbor.rb
|
@@ -73,6 +91,10 @@ files:
|
|
73
91
|
- bin/cbor2json.rb
|
74
92
|
- bin/cbor2pretty.rb
|
75
93
|
- bin/cbor2yaml.rb
|
94
|
+
- bin/cborleader2diag.rb
|
95
|
+
- bin/cborseq2json.rb
|
96
|
+
- bin/cborseq2neatjson.rb
|
97
|
+
- bin/cborseq2yaml.rb
|
76
98
|
- bin/diag2cbor.rb
|
77
99
|
- bin/diag2pretty.rb
|
78
100
|
- bin/json2cbor.rb
|
@@ -90,7 +112,7 @@ homepage: http://cbor.io/
|
|
90
112
|
licenses:
|
91
113
|
- Apache-2.0
|
92
114
|
metadata: {}
|
93
|
-
post_install_message:
|
115
|
+
post_install_message:
|
94
116
|
rdoc_options: []
|
95
117
|
require_paths:
|
96
118
|
- lib
|
@@ -105,9 +127,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
127
|
- !ruby/object:Gem::Version
|
106
128
|
version: '0'
|
107
129
|
requirements: []
|
108
|
-
|
109
|
-
|
110
|
-
signing_key:
|
130
|
+
rubygems_version: 3.1.4
|
131
|
+
signing_key:
|
111
132
|
specification_version: 4
|
112
133
|
summary: CBOR (Concise Binary Object Representation) diagnostic notation
|
113
134
|
test_files: []
|