cbor-diag 0.5.17 → 0.6.2
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 +4 -1
- data/bin/cbor2json.rb +8 -1
- data/bin/cbor2yaml.rb +4 -1
- data/bin/cborleader2diag.rb +4 -1
- data/bin/cborseq2diag.rb +11 -2
- data/bin/cborseq2json.rb +3 -1
- data/bin/cborseq2neatjson.rb +3 -1
- data/bin/cborseq2yaml.rb +4 -1
- data/bin/diag2diag.rb +45 -0
- data/bin/json2cbor.rb +8 -1
- data/bin/json2json.rb +4 -1
- data/bin/json2neatjson.rb +4 -1
- data/bin/json2yaml.rb +4 -1
- data/bin/yaml2cbor.rb +4 -1
- data/bin/yaml2json.rb +4 -1
- data/cbor-diag.gemspec +2 -1
- data/lib/cbor-transform-j.rb +68 -0
- data/lib/cbor-transform.rb +72 -0
- metadata +21 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec43541ce38545a4f655d2850def66df52e470aeacd8619606d3f93d67b1c754
|
4
|
+
data.tar.gz: b9775671d09e6d633857c05dacb9eca09d58549b1f3610a2522950611e2335df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e3d37804d954244631ef72c5e1adb278ab014d1e0b5f202bd624d036c06e6ec9e89955022acc1b0e58305ff0ef121f933761229026c84ebb2e084c896c5e47d
|
7
|
+
data.tar.gz: 3ecad4f3ae9bc6f146c8e0c02558c2dfa05a4c8a5fe19a648e4b64b95431e5d2c1ab335f5143783652e25a5b6b054eefbe88ebb747212ce209a124ddd9d087fd
|
data/bin/cbor2diag.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'cbor-diagnostic'
|
3
|
+
require 'cbor-packed'
|
3
4
|
require 'cbor-deterministic'
|
4
5
|
require 'cbor-canonical'
|
5
6
|
|
6
7
|
options = ''
|
7
|
-
while /\A-([
|
8
|
+
while /\A-([cdetpqu]+)\z/ === ARGV[0]
|
8
9
|
options << $1
|
9
10
|
ARGV.shift
|
10
11
|
end
|
@@ -12,6 +13,8 @@ end
|
|
12
13
|
ARGF.binmode
|
13
14
|
i = ARGF.read
|
14
15
|
o = CBOR.decode(i)
|
16
|
+
o = o.to_packed_cbor if /p/ === options
|
17
|
+
o = o.to_unpacked_cbor if /q/ === options
|
15
18
|
o = o.cbor_pre_canonicalize if /c/ === options
|
16
19
|
o = o.cbor_prepare_deterministic if /d/ === options
|
17
20
|
puts o.cbor_diagnostic(try_decode_embedded: /e/ === options,
|
data/bin/cbor2json.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'json'
|
3
3
|
require 'cbor-pure'
|
4
|
+
require 'cbor-packed'
|
4
5
|
require 'cbor-deterministic'
|
5
6
|
require 'cbor-canonical'
|
6
7
|
|
7
8
|
options = ''
|
8
|
-
while /\A-([
|
9
|
+
while /\A-([cdpqj]+)\z/ === ARGV[0]
|
9
10
|
options << $1
|
10
11
|
ARGV.shift
|
11
12
|
end
|
@@ -13,6 +14,12 @@ end
|
|
13
14
|
ARGF.binmode
|
14
15
|
i = ARGF.read
|
15
16
|
o = CBOR.decode(i)
|
17
|
+
o = o.to_packed_cbor if /p/ === options
|
18
|
+
o = o.to_unpacked_cbor if /q/ === options
|
16
19
|
o = o.cbor_pre_canonicalize if /c/ === options
|
17
20
|
o = o.cbor_prepare_deterministic if /d/ === options
|
21
|
+
if /j/ === options
|
22
|
+
require 'cbor-transform-j'
|
23
|
+
o = CBOR::Transform_j.new.transform(o)
|
24
|
+
end
|
18
25
|
puts JSON.pretty_generate(o)
|
data/bin/cbor2yaml.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
require 'psych.rb' # WTF
|
3
3
|
require 'yaml'
|
4
4
|
require 'cbor-pure'
|
5
|
+
require 'cbor-packed'
|
5
6
|
require 'cbor-deterministic'
|
6
7
|
require 'cbor-canonical'
|
7
8
|
|
@@ -12,7 +13,7 @@ class Array
|
|
12
13
|
end
|
13
14
|
|
14
15
|
options = ''
|
15
|
-
while /\A-([
|
16
|
+
while /\A-([cdpq]+)\z/ === ARGV[0]
|
16
17
|
options << $1
|
17
18
|
ARGV.shift
|
18
19
|
end
|
@@ -20,6 +21,8 @@ end
|
|
20
21
|
ARGF.binmode
|
21
22
|
i = ARGF.read
|
22
23
|
o = CBOR.decode(i)
|
24
|
+
o = o.to_packed_cbor if /p/ === options
|
25
|
+
o = o.to_unpacked_cbor if /q/ === options
|
23
26
|
o = o.cbor_prepare_deterministic if /d/ === options
|
24
27
|
o = o.cbor_pre_canonicalize if /c/ === options
|
25
28
|
puts YAML.dump(o)
|
data/bin/cborleader2diag.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'cbor-diagnostic'
|
3
|
+
require 'cbor-packed'
|
3
4
|
require 'cbor-deterministic'
|
4
5
|
require 'cbor-canonical'
|
5
6
|
|
6
7
|
options = ''
|
7
|
-
while /\A-([
|
8
|
+
while /\A-([cdetpqu]+)\z/ === ARGV[0]
|
8
9
|
options << $1
|
9
10
|
ARGV.shift
|
10
11
|
end
|
@@ -15,6 +16,8 @@ o,r = CBOR.decode_with_rest(i)
|
|
15
16
|
if r != ''
|
16
17
|
warn "** ignoring rest of #{r.bytesize} bytes after first CBOR data item"
|
17
18
|
end
|
19
|
+
o = o.to_packed_cbor if /p/ === options
|
20
|
+
o = o.to_unpacked_cbor if /q/ === options
|
18
21
|
o = o.cbor_prepare_deterministic if /d/ === options
|
19
22
|
o = o.cbor_pre_canonicalize if /c/ === options
|
20
23
|
puts o.cbor_diagnostic(try_decode_embedded: /e/ === options,
|
data/bin/cborseq2diag.rb
CHANGED
@@ -1,18 +1,27 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'cbor-diagnostic'
|
3
|
+
require 'cbor-packed'
|
3
4
|
require 'cbor-deterministic'
|
4
5
|
require 'cbor-canonical'
|
5
6
|
|
6
7
|
options = ''
|
7
|
-
while /\A-([
|
8
|
+
while /\A-([cdetpqu]+)\z/ === ARGV[0]
|
8
9
|
options << $1
|
9
10
|
ARGV.shift
|
10
11
|
end
|
11
12
|
|
12
13
|
ARGF.binmode
|
13
14
|
i = ARGF.read
|
15
|
+
totalsize = i.bytesize
|
14
16
|
while !i.empty?
|
15
|
-
|
17
|
+
begin
|
18
|
+
o, i = CBOR.decode_with_rest(i)
|
19
|
+
rescue Exception => e
|
20
|
+
puts "/ *** Garbage at byte #{totalsize-i.bytesize}: #{e.message} /"
|
21
|
+
break
|
22
|
+
end
|
23
|
+
o = o.to_packed_cbor if /p/ === options
|
24
|
+
o = o.to_unpacked_cbor if /q/ === options
|
16
25
|
o = o.cbor_pre_canonicalize if /c/ === options
|
17
26
|
o = o.cbor_prepare_deterministic if /d/ === options
|
18
27
|
out = o.cbor_diagnostic(try_decode_embedded: /e/ === options,
|
data/bin/cborseq2json.rb
CHANGED
@@ -5,7 +5,7 @@ require 'cbor-deterministic'
|
|
5
5
|
require 'cbor-canonical'
|
6
6
|
|
7
7
|
options = ''
|
8
|
-
while /\A-([
|
8
|
+
while /\A-([cdpq]+)\z/ === ARGV[0]
|
9
9
|
options << $1
|
10
10
|
ARGV.shift
|
11
11
|
end
|
@@ -14,6 +14,8 @@ ARGF.binmode
|
|
14
14
|
i = ARGF.read
|
15
15
|
while i != ''
|
16
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
|
17
19
|
o = o.cbor_pre_canonicalize if /c/ === options
|
18
20
|
o = o.cbor_prepare_deterministic if /d/ === options
|
19
21
|
puts JSON.pretty_generate(o)
|
data/bin/cborseq2neatjson.rb
CHANGED
@@ -6,7 +6,7 @@ require 'cbor-deterministic'
|
|
6
6
|
require 'cbor-canonical'
|
7
7
|
|
8
8
|
options = ''
|
9
|
-
while /\A-([
|
9
|
+
while /\A-([cdpq]+)\z/ === ARGV[0]
|
10
10
|
options << $1
|
11
11
|
ARGV.shift
|
12
12
|
end
|
@@ -15,6 +15,8 @@ ARGF.binmode
|
|
15
15
|
i = ARGF.read
|
16
16
|
while i != ''
|
17
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
|
18
20
|
o = o.cbor_pre_canonicalize if /c/ === options
|
19
21
|
o = o.cbor_prepare_deterministic if /d/ === options
|
20
22
|
puts JSON.neat_generate(o, after_comma: 1, after_colon: 1)
|
data/bin/cborseq2yaml.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
require 'psych.rb' # WTF
|
3
3
|
require 'yaml'
|
4
4
|
require 'cbor-pure'
|
5
|
+
require 'cbor-packed'
|
5
6
|
require 'cbor-deterministic'
|
6
7
|
require 'cbor-canonical'
|
7
8
|
|
@@ -12,7 +13,7 @@ class Array
|
|
12
13
|
end
|
13
14
|
|
14
15
|
options = ''
|
15
|
-
while /\A-([
|
16
|
+
while /\A-([cdpq]+)\z/ === ARGV[0]
|
16
17
|
options << $1
|
17
18
|
ARGV.shift
|
18
19
|
end
|
@@ -22,6 +23,8 @@ ARGF.binmode
|
|
22
23
|
i = ARGF.read
|
23
24
|
while i != ''
|
24
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
|
25
28
|
o = o.cbor_pre_canonicalize if /c/ === options
|
26
29
|
o = o.cbor_prepare_deterministic if /d/ === options
|
27
30
|
puts YAML.dump(o)
|
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/json2cbor.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'json'
|
3
3
|
require 'cbor-pure'
|
4
|
+
require 'cbor-packed'
|
4
5
|
require 'cbor-deterministic'
|
5
6
|
require 'cbor-canonical'
|
6
7
|
|
7
8
|
options = ''
|
8
|
-
while /\A-([
|
9
|
+
while /\A-([cdpqvj]+)\z/ === ARGV[0]
|
9
10
|
options << $1
|
10
11
|
ARGV.shift
|
11
12
|
end
|
@@ -13,6 +14,12 @@ end
|
|
13
14
|
$stdout.binmode
|
14
15
|
i = ARGF.read
|
15
16
|
o = JSON.load(i)
|
17
|
+
if /j/ === options
|
18
|
+
require 'cbor-transform-j'
|
19
|
+
o = CBOR::Transform_jr.new.transform(o)
|
20
|
+
end
|
21
|
+
o = o.to_packed_cbor if /p/ === options
|
22
|
+
o = o.to_unpacked_cbor if /q/ === options
|
16
23
|
o = o.cbor_pre_canonicalize if /c/ === options
|
17
24
|
o = o.cbor_prepare_deterministic if /d/ === options
|
18
25
|
o = CBOR.encode(o)
|
data/bin/json2json.rb
CHANGED
@@ -1,17 +1,20 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'json'
|
3
3
|
require 'cbor-pure'
|
4
|
+
require 'cbor-packed'
|
4
5
|
require 'cbor-deterministic'
|
5
6
|
require 'cbor-canonical'
|
6
7
|
|
7
8
|
options = ''
|
8
|
-
while /\A-([
|
9
|
+
while /\A-([cdpq]+)\z/ === ARGV[0]
|
9
10
|
options << $1
|
10
11
|
ARGV.shift
|
11
12
|
end
|
12
13
|
|
13
14
|
i = ARGF.read
|
14
15
|
o = JSON.load(i)
|
16
|
+
o = o.to_packed_cbor if /p/ === options
|
17
|
+
o = o.to_unpacked_cbor if /q/ === options
|
15
18
|
o = o.cbor_pre_canonicalize if /c/ === options
|
16
19
|
o = o.cbor_prepare_deterministic if /d/ === options
|
17
20
|
puts JSON.pretty_generate(o)
|
data/bin/json2neatjson.rb
CHANGED
@@ -2,11 +2,12 @@
|
|
2
2
|
require 'json'
|
3
3
|
require 'cbor-pure'
|
4
4
|
require 'neatjson'
|
5
|
+
require 'cbor-packed'
|
5
6
|
require 'cbor-deterministic'
|
6
7
|
require 'cbor-canonical'
|
7
8
|
|
8
9
|
options = ''
|
9
|
-
while /\A-([
|
10
|
+
while /\A-([cdpq]+)\z/ === ARGV[0]
|
10
11
|
options << $1
|
11
12
|
ARGV.shift
|
12
13
|
end
|
@@ -14,6 +15,8 @@ end
|
|
14
15
|
$stdout.binmode
|
15
16
|
i = ARGF.read
|
16
17
|
o = JSON.load(i)
|
18
|
+
o = o.to_packed_cbor if /p/ === options
|
19
|
+
o = o.to_unpacked_cbor if /q/ === options
|
17
20
|
o = o.cbor_pre_canonicalize if /c/ === options
|
18
21
|
o = o.cbor_prepare_deterministic if /d/ === options
|
19
22
|
puts JSON.neat_generate(o, after_comma: 1, after_colon: 1)
|
data/bin/json2yaml.rb
CHANGED
@@ -3,6 +3,7 @@ require 'psych.rb' # WTF
|
|
3
3
|
require 'yaml'
|
4
4
|
require 'json'
|
5
5
|
require 'cbor-pure'
|
6
|
+
require 'cbor-packed'
|
6
7
|
require 'cbor-deterministic'
|
7
8
|
require 'cbor-canonical'
|
8
9
|
|
@@ -13,13 +14,15 @@ class Array
|
|
13
14
|
end
|
14
15
|
|
15
16
|
options = ''
|
16
|
-
while /\A-([
|
17
|
+
while /\A-([cdpq]+)\z/ === ARGV[0]
|
17
18
|
options << $1
|
18
19
|
ARGV.shift
|
19
20
|
end
|
20
21
|
|
21
22
|
i = ARGF.read
|
22
23
|
o = JSON.load(i)
|
24
|
+
o = o.to_packed_cbor if /p/ === options
|
25
|
+
o = o.to_unpacked_cbor if /q/ === options
|
23
26
|
o = o.cbor_pre_canonicalize if /c/ === options
|
24
27
|
o = o.cbor_prepare_deterministic if /d/ === options
|
25
28
|
puts YAML.dump(o)
|
data/bin/yaml2cbor.rb
CHANGED
@@ -2,11 +2,12 @@
|
|
2
2
|
require 'psych.rb' # WTF
|
3
3
|
require 'yaml'
|
4
4
|
require 'cbor-pure'
|
5
|
+
require 'cbor-packed'
|
5
6
|
require 'cbor-deterministic'
|
6
7
|
require 'cbor-canonical'
|
7
8
|
|
8
9
|
options = ''
|
9
|
-
while /\A-([
|
10
|
+
while /\A-([cdpqv]+)\z/ === ARGV[0]
|
10
11
|
options << $1
|
11
12
|
ARGV.shift
|
12
13
|
end
|
@@ -14,6 +15,8 @@ end
|
|
14
15
|
$stdout.binmode
|
15
16
|
i = ARGF.read
|
16
17
|
o = YAML.load(i)
|
18
|
+
o = o.to_packed_cbor if /p/ === options
|
19
|
+
o = o.to_unpacked_cbor if /q/ === options
|
17
20
|
o = o.cbor_pre_canonicalize if /c/ === options
|
18
21
|
o = o.cbor_prepare_deterministic if /d/ === options
|
19
22
|
o = CBOR.encode(o)
|
data/bin/yaml2json.rb
CHANGED
@@ -3,17 +3,20 @@ require 'json'
|
|
3
3
|
require 'psych.rb' # WTF
|
4
4
|
require 'yaml'
|
5
5
|
require 'cbor-pure'
|
6
|
+
require 'cbor-packed'
|
6
7
|
require 'cbor-deterministic'
|
7
8
|
require 'cbor-canonical'
|
8
9
|
|
9
10
|
options = ''
|
10
|
-
while /\A-([
|
11
|
+
while /\A-([cdpq]+)\z/ === ARGV[0]
|
11
12
|
options << $1
|
12
13
|
ARGV.shift
|
13
14
|
end
|
14
15
|
|
15
16
|
i = ARGF.read
|
16
17
|
o = YAML.load(i)
|
18
|
+
o = o.to_packed_cbor if /p/ === options
|
19
|
+
o = o.to_unpacked_cbor if /q/ === options
|
17
20
|
o = o.cbor_pre_canonicalize if /c/ === options
|
18
21
|
o = o.cbor_prepare_deterministic if /d/ === options
|
19
22
|
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.
|
3
|
+
s.version = "0.6.2"
|
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"
|
@@ -22,4 +22,5 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.add_dependency 'neatjson'
|
23
23
|
s.add_dependency 'cbor-deterministic'
|
24
24
|
s.add_dependency 'cbor-canonical'
|
25
|
+
s.add_dependency 'cbor-packed'
|
25
26
|
end
|
@@ -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.
|
4
|
+
version: 0.6.2
|
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-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
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'
|
97
111
|
description: cbor-diag implements diagnostic notation for CBOR, RFC 8949 and RFC 8742
|
98
112
|
email: cabo@tzi.org
|
99
113
|
executables:
|
@@ -109,6 +123,7 @@ executables:
|
|
109
123
|
- cborseq2pretty.rb
|
110
124
|
- cborseq2yaml.rb
|
111
125
|
- diag2cbor.rb
|
126
|
+
- diag2diag.rb
|
112
127
|
- diag2pretty.rb
|
113
128
|
- json2cbor.rb
|
114
129
|
- json2json.rb
|
@@ -134,6 +149,7 @@ files:
|
|
134
149
|
- bin/cborseq2pretty.rb
|
135
150
|
- bin/cborseq2yaml.rb
|
136
151
|
- bin/diag2cbor.rb
|
152
|
+
- bin/diag2diag.rb
|
137
153
|
- bin/diag2pretty.rb
|
138
154
|
- bin/json2cbor.rb
|
139
155
|
- bin/json2json.rb
|
@@ -149,6 +165,8 @@ files:
|
|
149
165
|
- lib/cbor-diagnostic.rb
|
150
166
|
- lib/cbor-pretty.rb
|
151
167
|
- lib/cbor-pure.rb
|
168
|
+
- lib/cbor-transform-j.rb
|
169
|
+
- lib/cbor-transform.rb
|
152
170
|
- lib/half.rb
|
153
171
|
homepage: http://cbor.io/
|
154
172
|
licenses:
|
@@ -169,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
187
|
- !ruby/object:Gem::Version
|
170
188
|
version: '0'
|
171
189
|
requirements: []
|
172
|
-
rubygems_version: 3.2.
|
190
|
+
rubygems_version: 3.2.22
|
173
191
|
signing_key:
|
174
192
|
specification_version: 4
|
175
193
|
summary: CBOR (Concise Binary Object Representation) diagnostic notation
|