cbor-diag 0.10.3 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38def274f572f92dcd5b6cfd02fc4e7b0bc2006f5339f5db046e1b9bb388fcaa
4
- data.tar.gz: f8027b5da38f62e5b0411f55c182fae2025768be56ed978775e491273a19e150
3
+ metadata.gz: 9386c9d64142f904cccc4806ce98863db188e7c730932f40cacfa5968088e43c
4
+ data.tar.gz: 110f77e616a233a503042a0860f5c72007bbb7f7f01ba319343ed328de2ab5aa
5
5
  SHA512:
6
- metadata.gz: 8ad0cd6b46dd03e2fd5457a440bea503ece1e4dc293dde4a701f41f9434092d26e4576711afc321ceddf9a661e81e7b4ada743f37a0c25f4e04c475bbfd9fed0
7
- data.tar.gz: 8a55d75ba512cbceeed3f995d10615a0666d892449c13c1b729d69858fe3180b4fe4eee2ac06dca4bb8a31787a40d0b687f0205df77bd6fae5b6226e194e18cd
6
+ metadata.gz: 5db4dfa3cabd1c3f14a6395558266bbb47beaf603bdbac4ee541d3b66cddca861398ecbc5830ca98b15100658add992845677d987e6db25510b230e2c02f730c
7
+ data.tar.gz: 315b19d49cd07961bb46bc38320310094f0632fc01c40b943ecfe6e8e85a4823c426cda3912a86b7607e6cb2552c20ab4e39d89c4040cef7c8ce2acac8b348df
data/bin/cbor2diag.rb CHANGED
@@ -6,7 +6,7 @@ require 'cbor-canonical'
6
6
 
7
7
 
8
8
  require 'cbor-diagnostic-helper'
9
- options = cbor_diagnostic_process_args("cdetpqunN")
9
+ options = cbor_diagnostic_process_args("cdetpqunNT")
10
10
 
11
11
  ARGF.binmode
12
12
  i = ARGF.read
@@ -5,7 +5,7 @@ require 'cbor-deterministic'
5
5
  require 'cbor-canonical'
6
6
 
7
7
  require 'cbor-diagnostic-helper'
8
- options = cbor_diagnostic_process_args("cdetpqunN")
8
+ options = cbor_diagnostic_process_args("cdetpqunNT")
9
9
 
10
10
  ARGF.binmode
11
11
  i = ARGF.read
data/bin/cborseq2diag.rb CHANGED
@@ -5,7 +5,7 @@ require 'cbor-deterministic'
5
5
  require 'cbor-canonical'
6
6
 
7
7
  require 'cbor-diagnostic-helper'
8
- options = cbor_diagnostic_process_args("cdetpqunN")
8
+ options = cbor_diagnostic_process_args("cdetpqunNT")
9
9
 
10
10
  ARGF.binmode
11
11
  i = ARGF.read
data/bin/diag2diag.rb CHANGED
@@ -9,19 +9,14 @@ require 'cbor-pretty'
9
9
  require 'cbor-diagnostic'
10
10
 
11
11
  require 'cbor-diagnostic-helper'
12
- options = cbor_diagnostic_process_args("cdetpqunN")
12
+ options = cbor_diagnostic_process_args("cdetpqunNT")
13
13
 
14
14
  parser = CBOR_DIAGParser.new
15
15
 
16
16
  i = ARGF.read.b # binary to work around treetop performance bug
17
17
  if result = parser.parse(i)
18
18
  decoded = result.to_rb
19
- out = case decoded
20
- when CBOR::Sequence
21
- decoded.elements
22
- else
23
- [decoded]
24
- end.map {|x| cbor_diagnostic_output(x, options)}.join(", ")
19
+ out = cbor_diagnostic_output(decoded, options)
25
20
  puts out
26
21
  else
27
22
  warn "*** can't parse #{i}"
data/bin/pretty2diag.rb CHANGED
@@ -9,7 +9,7 @@ end
9
9
 
10
10
 
11
11
  require 'cbor-diagnostic-helper'
12
- options = cbor_diagnostic_process_args("cdetpqunN")
12
+ options = cbor_diagnostic_process_args("cdetpqunNT")
13
13
 
14
14
 
15
15
  i = extractbytes(ARGF)
data/cbor-diag.gemspec CHANGED
@@ -1,13 +1,13 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cbor-diag"
3
- s.version = "0.10.3"
3
+ s.version = "0.11.1"
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"
7
7
  s.email = "cabo@tzi.org"
8
8
  s.license = "Apache-2.0"
9
9
  s.homepage = "http://cbor.io/"
10
- s.has_rdoc = false
10
+ # s.has_rdoc = false
11
11
  # s.files = `git ls-files`.split("\n") << "lib/cbor-diag-parser.rb"
12
12
  # s.test_files = `git ls-files -- {test,spec}/*`.split("\n")
13
13
  s.files = Dir['lib/**/*.rb'] + %w(cbor-diag.gemspec) + Dir['bin/**/*.rb']
@@ -4,14 +4,19 @@ require 'cbor-canonical'
4
4
 
5
5
  def cbor_diagnostic_process_args(chars)
6
6
  options = ''
7
- while /\A-(?:([#{chars}]+)|([#{chars}]*)a(.*))\z/ === ARGV[0]
7
+ while /\A-(?:([#{chars}]+)|([#{chars}]*)([aw])(.*))\z/ === ARGV[0]
8
8
  ARGV.shift
9
9
  options << $1 if $1
10
10
  options << $2 if $2
11
- if s = $3
11
+ if (o = $3) && (s = $4)
12
12
  s = ARGV.shift if s == ""
13
- s.split(",").each do |a|
14
- require "cbor-diagnostic-app/#{a}"
13
+ case o
14
+ when "a"
15
+ s.split(",").each do |a|
16
+ require "cbor-diagnostic-app/#{a}"
17
+ end
18
+ when "w"
19
+ options << "w#{s.to_i}"
15
20
  end
16
21
  end
17
22
  end
@@ -32,5 +37,7 @@ def cbor_diagnostic_output(o, options)
32
37
  bytes_as_text: /t/ === options,
33
38
  utf8: /u/ === options,
34
39
  nan: /n/ === options,
35
- no_nan: /N/ === options)
40
+ no_nan: /N/ === options,
41
+ terminator: /T/ === options,
42
+ wrap: if /w([0-9]+)/ === options; $1.to_i; end)
36
43
  end
@@ -9,6 +9,19 @@ class Object
9
9
  def cbor_diagnostic(_=nil)
10
10
  inspect
11
11
  end
12
+ def cbor__indent_helper(options)
13
+ indent = options[:indent] || ''
14
+ indent2 = indent + " "
15
+ indented_options = options.merge({indent: indent2})
16
+ [indent, indent2, indented_options]
17
+ end
18
+
19
+ end
20
+
21
+ class Symbol
22
+ def cbor_diagnostic(_=nil)
23
+ to_s.cbor_diagnostic # TODO add option for tagging
24
+ end
12
25
  end
13
26
 
14
27
  class NilClass
@@ -103,13 +116,29 @@ end
103
116
 
104
117
  class Array
105
118
  def cbor_diagnostic(options = {})
106
- "[#{"_ " if cbor_stream?}#{map {|x| x.cbor_diagnostic(options)}.join(", ")}]"
119
+ indent, indent2, indented_options = cbor__indent_helper(options)
120
+ pieces = map {|x| x.cbor_diagnostic(indented_options)}
121
+ one_line = "[#{"_ " if cbor_stream?}#{pieces.join(", ")}]"
122
+ if !(wrap = options[:wrap]) || pieces == [] || one_line.length + indent.length < wrap # XXX
123
+ one_line
124
+ else
125
+ open, close = options[:terminator] ? ["\n#{indent2}", ",\n#{indent}"] : [" ", " "]
126
+ "[#{"_" if cbor_stream?}#{open}#{pieces.join(",\n#{indent2}")}#{close}]"
127
+ end
107
128
  end
108
129
  end
109
130
 
110
131
  class Hash
111
132
  def cbor_diagnostic(options = {})
112
- "{#{"_ " if cbor_stream?}#{map{ |k, v| %{#{k.cbor_diagnostic(options)}: #{v.cbor_diagnostic(options)}}}.join(", ")}#{cbor_map_lost_warning}}"
133
+ indent, indent2, indented_options = cbor__indent_helper(options)
134
+ pieces = map {|x| x.map {|y| y.cbor_diagnostic(indented_options)}.join(": ")} # XXX key/value split
135
+ one_line = "{#{"_ " if cbor_stream?}#{pieces.join(", ")}#{cbor_map_lost_warning}}"
136
+ if !(wrap = options[:wrap]) || pieces == [] || one_line.length + indent.length < wrap # XXX
137
+ one_line
138
+ else
139
+ open, close = options[:terminator] ? ["\n#{indent2}", ",\n#{indent}"] : [" ", " "]
140
+ "{#{"_" if cbor_stream?}#{open}#{pieces.join(",\n#{indent2}")}#{close}#{cbor_map_lost_warning}}"
141
+ end
113
142
  end
114
143
  end
115
144
 
@@ -124,9 +153,16 @@ class CBOR::Sequence
124
153
  if elements == []
125
154
  "/ empty CBOR sequence /"
126
155
  else
127
- elements.map{ |el|
128
- el.cbor_diagnostic(options)
129
- }.join(", ")
156
+ indent, _indent2, indented_options = cbor__indent_helper(options)
157
+ pieces = elements.map{ |el|
158
+ el.cbor_diagnostic(indented_options)
159
+ }
160
+ one_line = pieces.join(", ")
161
+ if !(wrap = options[:wrap]) || one_line.length + indent.length < wrap # XXX
162
+ one_line
163
+ else
164
+ "#{pieces.join(",\n#{indent}")}#{",\n" if options[:terminator]}"
165
+ end
130
166
  end
131
167
  end
132
168
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cbor-diag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.3
4
+ version: 0.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Bormann
@@ -197,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
197
197
  - !ruby/object:Gem::Version
198
198
  version: '0'
199
199
  requirements: []
200
- rubygems_version: 3.7.2
200
+ rubygems_version: 4.0.2
201
201
  specification_version: 4
202
202
  summary: CBOR (Concise Binary Object Representation) diagnostic notation
203
203
  test_files: []