cbor-diag 0.8.8 → 0.9.0
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 +1 -1
- data/bin/cborleader2diag.rb +1 -1
- data/bin/cborseq2diag.rb +1 -1
- data/bin/diag2diag.rb +1 -1
- data/bin/pretty2diag.rb +1 -1
- data/cbor-diag.gemspec +1 -1
- data/lib/cbor-diag-parser.rb +1 -1
- data/lib/cbor-diagnostic-app/nan.rb +10 -0
- data/lib/cbor-diagnostic-helper.rb +6 -6
- data/lib/cbor-diagnostic.rb +6 -1
- data/lib/cbor-nan.rb +7 -0
- data/lib/cbor-pure.rb +15 -1
- data/lib/half.rb +3 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c41a7144e024520508e8b84b485aa53ae8b9e45f26eb60574cec5acef4c97e50
|
4
|
+
data.tar.gz: af46eaddb14028e6c54f6d63f261e255b7f629f8089a5d1f228d97ba916368cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88cb362411df944ca64d929678f74282ecaa4c91257fe0fb38262789fe360b095e51b5ecaa6fb094f071df179051b96ddfb28b743a72bb80eccc2e6985165732
|
7
|
+
data.tar.gz: 3e3fec444f1996f724ea4ef05fa3ddd6ca9fc8edad06a3c85176a023ddb30ae1633c21140e59c1fbe3beb264ed6cf5396e25f8c4d22cd7647cb8f1fc4ebc68bd
|
data/bin/cbor2diag.rb
CHANGED
data/bin/cborleader2diag.rb
CHANGED
data/bin/cborseq2diag.rb
CHANGED
data/bin/diag2diag.rb
CHANGED
data/bin/pretty2diag.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.
|
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"
|
data/lib/cbor-diag-parser.rb
CHANGED
@@ -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:
|
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)
|
@@ -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
|
-
|
11
|
-
|
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
|
data/lib/cbor-diagnostic.rb
CHANGED
@@ -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(
|
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
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
|
-
|
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 :
|
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.
|
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-
|
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
|