cbor-diag 0.9.8 → 0.10.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: ae0f990a039f1c2b0c08af5ff06a25868210f0aaf219810674e254fb3e1dabe9
4
- data.tar.gz: 812d69e74907bb80861a277c60f58a17522fa14869eeddc8b2ecfcd78533cb12
3
+ metadata.gz: 56baddf10e207846f9ef83665454cf578d5ba570523d62f56a5912138096fded
4
+ data.tar.gz: 19f2e413f8be97389c6663c225d0ba3a5152e1732d600a26beb81a140b9ba346
5
5
  SHA512:
6
- metadata.gz: 40d28a0d95ffdfcf1badd9dda4d1200385306fe5ceb53492ec6ed246ffe08b763583a0c364d33714c174ffcea4002e57ff46448a0d82a52de5fc7c1247b72a60
7
- data.tar.gz: 42c5aaa0fcb2600d6ef515db1d8e9739ba769c2d4ba65e8b4d9948932b08e532f20edee1ed7f7ecbf883186b6f744a404d519fc1f5cb9d03f447fc73172146e8
6
+ metadata.gz: 94ec9f6276a20a619ccc9e6453e342738ce856ab6d7cba72f9a9d5f16c1b75ce91d7438dbace16ebca9636838e78a5477c764ec65bd0d2ad4f60e2a994d1dee1
7
+ data.tar.gz: 37c410853afacedda5b238d83c4792781a4bf7a7007f5792222cf64a37beb9000b3375b79d9022ec69ff534ec1f8151ea06155f352b435ad2eab5ba8d3ba0945
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("cdetpqun")
9
+ options = cbor_diagnostic_process_args("cdetpqunN")
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("cdetpqun")
8
+ options = cbor_diagnostic_process_args("cdetpqunN")
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("cdetpqun")
8
+ options = cbor_diagnostic_process_args("cdetpqunN")
9
9
 
10
10
  ARGF.binmode
11
11
  i = ARGF.read
data/bin/diag2diag.rb CHANGED
@@ -9,7 +9,7 @@ require 'cbor-pretty'
9
9
  require 'cbor-diagnostic'
10
10
 
11
11
  require 'cbor-diagnostic-helper'
12
- options = cbor_diagnostic_process_args("cdetpqun")
12
+ options = cbor_diagnostic_process_args("cdetpqunN")
13
13
 
14
14
  parser = CBOR_DIAGParser.new
15
15
 
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("cdetpqun")
12
+ options = cbor_diagnostic_process_args("cdetpqunN")
13
13
 
14
14
 
15
15
  i = extractbytes(ARGF)
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.9.8"
3
+ s.version = "0.10.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"
@@ -1542,7 +1542,7 @@ module CBOR_DIAG
1542
1542
  module Appstring2
1543
1543
  #'
1544
1544
  def to_rb
1545
- data = s.elements.map(&:partval).join.b
1545
+ data = s.elements.map(&:partval).join.force_encoding(Encoding::UTF_8)
1546
1546
  app = a.text_value
1547
1547
  # Find a better place to put a default initialization
1548
1548
  CBOR_DIAG.const_set(:APPS, Hash.new { |h, k|
@@ -3507,9 +3507,11 @@ module CBOR_DIAG
3507
3507
  r0
3508
3508
  end
3509
3509
 
3510
- end
3511
3510
 
3512
- class CBOR_DIAGParser < Treetop::Runtime::CompiledParser
3513
- include CBOR_DIAG
3511
+ class Parser < Treetop::Runtime::CompiledParser
3512
+ include CBOR_DIAG
3513
+ end
3514
3514
  end
3515
3515
 
3516
+ CBOR_DIAGParser = CBOR_DIAG::Parser
3517
+
@@ -0,0 +1,27 @@
1
+ class CBOR_DIAG::App_float
2
+ SIZES = {
3
+ 2 => "\xf9".b.freeze,
4
+ 4 => "\xfa".b.freeze,
5
+ 8 => "\xfb".b.freeze,
6
+ }
7
+
8
+ def self.decode(_, s)
9
+ if CBOR::Sequence === s
10
+ if s.elements.size != 1
11
+ raise ArgumentError.new("cbor-diagnostic: float<< #{s.inspect[1...-1]} >>: Argument Error")
12
+ end
13
+ s = s.first
14
+ end
15
+ unless String === s
16
+ raise ArgumentError.new("cbor-diagnostic: float<< #{s.inspect} >>: Argument Error")
17
+ end
18
+ if s.encoding != Encoding::BINARY
19
+ s = s.gsub(/\s/, "").chars.each_slice(2).map{ |x| Integer(x.join, 16).chr("BINARY") }.join
20
+ end
21
+ ssize = SIZES[s.size]
22
+ unless ssize
23
+ raise ArgumentError.new("cbor-diagnostic: float<< #{s.inspect} >> size #{s.size} mismatch: Argument Error")
24
+ end
25
+ CBOR::decode(ssize + s)
26
+ end
27
+ end
@@ -31,5 +31,6 @@ def cbor_diagnostic_output(o, options)
31
31
  o.cbor_diagnostic(try_decode_embedded: /e/ === options,
32
32
  bytes_as_text: /t/ === options,
33
33
  utf8: /u/ === options,
34
- nan: /n/ === options)
34
+ nan: /n/ === options,
35
+ no_nan: /N/ === options)
35
36
  end
@@ -19,9 +19,14 @@ end
19
19
 
20
20
  class Float
21
21
  def cbor_diagnostic(options = {}) # do a little bit of JSON.stringify gaming (ECMA-262, 9.8.1)
22
- if options[:nan] && nan?
23
- pl = cbor_nan_toggle
24
- return "nan'#{('%a' % pl).gsub("+", "")}'"
22
+ if nan?
23
+ if options[:nan]
24
+ pl = cbor_nan_toggle
25
+ return "nan'#{('%a' % pl).gsub("+", "")}'"
26
+ elsif !options[:no_nan]
27
+ hex = to_cbor[1..-1].bytes.map{|x| "%02x" % x}.join
28
+ return "float'#{hex}'" unless hex == "7e00"
29
+ end
25
30
  end
26
31
  a = abs
27
32
  if a < 1 && a >= 1e-6
data/lib/cbor-pure.rb CHANGED
@@ -302,8 +302,18 @@ module CBOR
302
302
  raise "two-byte simple is #{val} but must be between 32 and 255" unless val >= 32;
303
303
  Simple.new(val)
304
304
  when 25; Half.decode(val)
305
- when 26; s.unpack("g").first # cannot go directly from val
306
- when 27; s.unpack("G").first # in Ruby
305
+ when 26;
306
+ v = s.unpack("g").first # cannot go directly from val in Ruby
307
+ if v.nan?
308
+ # work around quiet bit always set with unpack("g"):
309
+ # https://bugs.ruby-lang.org/issues/20662
310
+ qbit = s.getbyte(1)[6]
311
+ vbytes = [v].pack("G")
312
+ vbytes.setbyte(1, vbytes.getbyte(1) & 0xf7 | qbit << 3)
313
+ v = vbytes.unpack("G").first
314
+ end
315
+ v
316
+ when 27; s.unpack("G").first # cannot go directly from val in Ruby
307
317
  else
308
318
  Simple.new(val)
309
319
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cbor-diag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.8
4
+ version: 0.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Bormann
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-07-03 00:00:00.000000000 Z
10
+ date: 2025-08-07 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: bundler
@@ -167,6 +167,7 @@ files:
167
167
  - lib/cbor-diag-parser.rb
168
168
  - lib/cbor-diagnostic-app/0.rb
169
169
  - lib/cbor-diagnostic-app/dt.rb
170
+ - lib/cbor-diagnostic-app/float.rb
170
171
  - lib/cbor-diagnostic-app/hash.rb
171
172
  - lib/cbor-diagnostic-app/nan.rb
172
173
  - lib/cbor-diagnostic-helper.rb