cbor-diag 0.8.8 → 0.9.0

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: 379c2b3b6dfeeea6841c7892dea788a50b2960c511b25a1caece85cdffbe3d42
4
- data.tar.gz: 789d2200064abbc728744bb418027e56b6516d20464a020739de9f12cbb6439e
3
+ metadata.gz: c41a7144e024520508e8b84b485aa53ae8b9e45f26eb60574cec5acef4c97e50
4
+ data.tar.gz: af46eaddb14028e6c54f6d63f261e255b7f629f8089a5d1f228d97ba916368cb
5
5
  SHA512:
6
- metadata.gz: e4e20ee282d15a50654c605137eb8ad0f02b109d368e60a62a38adc3e48d7b00a7736d57dc80f56a745bf0731a0e2decff670a4d960c80eb853cd9c3021ecbf8
7
- data.tar.gz: 40fac29e490c8389573b2ca7c6d0de591228c7dc5721eca5942993726cfd6aba4366220b53d906deb4294e8626a9a2b299e9c507dff6dfe76ed43b681e8c38e1
6
+ metadata.gz: 88cb362411df944ca64d929678f74282ecaa4c91257fe0fb38262789fe360b095e51b5ecaa6fb094f071df179051b96ddfb28b743a72bb80eccc2e6985165732
7
+ data.tar.gz: 3e3fec444f1996f724ea4ef05fa3ddd6ca9fc8edad06a3c85176a023ddb30ae1633c21140e59c1fbe3beb264ed6cf5396e25f8c4d22cd7647cb8f1fc4ebc68bd
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("cdetpqu")
9
+ options = cbor_diagnostic_process_args("cdetpqun")
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("cdetpqu")
8
+ options = cbor_diagnostic_process_args("cdetpqun")
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("cdetpqu")
8
+ options = cbor_diagnostic_process_args("cdetpqun")
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("cdetpqu")
12
+ options = cbor_diagnostic_process_args("cdetpqun")
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("cdetpqu")
12
+ options = cbor_diagnostic_process_args("cdetpqun")
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.8.8"
3
+ s.version = "0.9.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"
@@ -1548,7 +1548,7 @@ module CBOR_DIAG
1548
1548
  CBOR_DIAG.const_set(:APPS, Hash.new { |h, k|
1549
1549
  h[k] = begin CBOR_DIAG.const_get("App_#{app}")
1550
1550
  rescue NameError
1551
- raise ArgumentError.new("cbor-diagnostic: Unknown application-oriented extension #{k}")
1551
+ raise ArgumentError.new("cbor-diagnostic: application-oriented extension #{k}'' unknown or not enabled")
1552
1552
  end
1553
1553
  }) unless CBOR_DIAG.const_defined?(:APPS)
1554
1554
  CBOR_DIAG::APPS[app].decode(app, data)
@@ -0,0 +1,10 @@
1
+ require 'scanf'
2
+
3
+ class CBOR_DIAG::App_nan
4
+ def self.decode(_, s)
5
+ val, = s.scanf("%a")
6
+ raise ArgumentError.new ("nan'#{s}' not valid") unless val &&
7
+ val.abs > 1.0 && val.abs < 2.0
8
+ val.cbor_nan_toggle
9
+ end
10
+ end
@@ -4,12 +4,11 @@ require 'cbor-canonical'
4
4
 
5
5
  def cbor_diagnostic_process_args(chars)
6
6
  options = ''
7
- while /\A-(?:([#{chars}]+)|a(.*))\z/ === ARGV[0]
7
+ while /\A-(?:([#{chars}]+)|([#{chars}]*)a(.*))\z/ === ARGV[0]
8
8
  ARGV.shift
9
- if $1
10
- options << $1
11
- else
12
- s = $2
9
+ options << $1 if $1
10
+ options << $2 if $2
11
+ if s = $3
13
12
  s = ARGV.shift if s == ""
14
13
  s.split(",").each do |a|
15
14
  require "cbor-diagnostic-app/#{a}"
@@ -31,5 +30,6 @@ def cbor_diagnostic_output(o, options)
31
30
  o = cbor_diagnostic_item_processing(o, options)
32
31
  o.cbor_diagnostic(try_decode_embedded: /e/ === options,
33
32
  bytes_as_text: /t/ === options,
34
- utf8: /u/ === options)
33
+ utf8: /u/ === options,
34
+ nan: /n/ === options)
35
35
  end
@@ -2,6 +2,7 @@
2
2
  unless defined?(CBOR)
3
3
  require 'cbor-pure'
4
4
  end
5
+ require 'cbor-nan'
5
6
  require 'json'
6
7
 
7
8
  class Object
@@ -17,7 +18,11 @@ class NilClass
17
18
  end
18
19
 
19
20
  class Float
20
- def cbor_diagnostic(_=nil) # do a little bit of JSON.stringify gaming (ECMA-262, 9.8.1)
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}'"
25
+ end
21
26
  a = abs
22
27
  if a < 1 && a >= 1e-6
23
28
  inspect.sub(/(\d)[.](\d+)e-(\d+)/) {"0.#{"0" * ($3.to_i - 1)}#{$1}#{$2}"}
data/lib/cbor-nan.rb ADDED
@@ -0,0 +1,7 @@
1
+ class Float
2
+ def cbor_nan_toggle # precondition: 1.0 < |self| < 2.0 or nan?
3
+ a = [self].pack("G")
4
+ a.setbyte(0, a.getbyte(0) ^ 0x40)
5
+ a.unpack("G").first
6
+ end
7
+ end
data/lib/cbor-pure.rb CHANGED
@@ -124,7 +124,21 @@ module CBOR
124
124
 
125
125
  def addfloat(fv)
126
126
  if fv.nan?
127
- @buffer << HALF_NAN_BYTES
127
+ # | Format | Sign bit | Exponent | Significand | Zero
128
+ # | binary16 | 1 | 5 | 10 | 42
129
+ # | binary32 | 1 | 8 | 23 | 29
130
+ # | binary64 | 1 | 11 | 52 | 0
131
+ ds = [fv].pack("G")
132
+ firstword = ds.unpack("n").first
133
+ raise "NaN exponent error #{firstword}" unless firstword & 0x7FF0 == 0x7FF0
134
+ iv = ds.unpack("Q>").first
135
+ if iv & 0x3ffffffffff == 0 # 42 zero, 10 bits fit in half
136
+ @buffer << [0xf9, (firstword & 0xFC00) + ((iv >> 42) & 0x3ff)].pack("Cn")
137
+ elsif iv & 0x1fffffff == 0 # 29 zero, 23 bits fit in single
138
+ @buffer << [0xfa, (ds.getbyte(0) << 24) + ((iv >> 29) & 0xffffff)].pack("CN")
139
+ else
140
+ @buffer << 0xfb << ds
141
+ end
128
142
  else
129
143
  ss = [fv].pack("g") # single-precision
130
144
  if ss.unpack("g").first == fv
data/lib/half.rb CHANGED
@@ -13,6 +13,8 @@
13
13
  # IEEE 754 can be found at:
14
14
  # http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=4610935
15
15
 
16
+ require 'cbor-nan'
17
+
16
18
  module Half
17
19
  NAN_BYTES = "\x7e\x00"
18
20
 
@@ -27,7 +29,7 @@ module Half
27
29
  if exp == 0
28
30
  Math.ldexp(mant, -24)
29
31
  elsif exp == 31
30
- mant == 0 ? Float::INFINITY : Float::NAN
32
+ mant == 0 ? Float::INFINITY : Math.ldexp(0x400 + mant, -10).cbor_nan_toggle
31
33
  else
32
34
  Math.ldexp(0x400 + mant, exp-25)
33
35
  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.8.8
4
+ version: 0.9.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: 2024-07-29 00:00:00.000000000 Z
11
+ date: 2024-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -163,9 +163,11 @@ files:
163
163
  - cbor-diag.gemspec
164
164
  - lib/cbor-diag-parser.rb
165
165
  - lib/cbor-diagnostic-app/dt.rb
166
+ - lib/cbor-diagnostic-app/nan.rb
166
167
  - lib/cbor-diagnostic-helper.rb
167
168
  - lib/cbor-diagnostic-parser.rb
168
169
  - lib/cbor-diagnostic.rb
170
+ - lib/cbor-nan.rb
169
171
  - lib/cbor-pretty.rb
170
172
  - lib/cbor-pure.rb
171
173
  - lib/cbor-transform-j.rb