cddl 0.10.7 → 0.11.2
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 +4 -4
- data/cddl.gemspec +1 -1
- data/data/cddl.abnf +3 -2
- data/lib/cddl.rb +60 -16
- data/test-data/dotplus1.cddl +3 -0
- data/test-data/dotplus2.cddl +3 -0
- data/test-data/dotplus3.cddl +3 -0
- data/test-data/dotplus4.cddl +3 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73391c15e100fe86614bce5277a63cf8d7032754e7a7e05f8eb4cc1ce074beae
|
4
|
+
data.tar.gz: 26734d7b7677595eb88b9f970b5d4986991cc1afc9841bc9c3c1f3bc5237c4a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 151f3e6374672a6b1c4211363ac90a7fb46814639f45d65a7fc85722c9b48cbc73d4e1919a8a3ddba574e4957f1b74b9d8105fdb0bb697f351a9069af222d742
|
7
|
+
data.tar.gz: 5d33838dfc0ff62d14f736d14108936100e638f5a1b73c5af9119a81a1ab7264369ce8059c95223347c756d4e73e7d38cd975ac8ae3387ed259e65edeee75610
|
data/cddl.gemspec
CHANGED
data/data/cddl.abnf
CHANGED
@@ -13,7 +13,8 @@ genericarg = "<" S type1 S *("," S type1 S ) ">"
|
|
13
13
|
type = type1 S *("/" S type1 S)
|
14
14
|
|
15
15
|
type1 = type2 [S (rangeop / annotator) S type2]
|
16
|
-
/ "#" "6" ["."
|
16
|
+
/ "#" "6" ["." headnumber] "(" S type S ")" ; note no space!
|
17
|
+
/ "#" "7" ["." headnumber] ; note no space!
|
17
18
|
/ "#" DIGIT ["." uint] ; major/ai
|
18
19
|
/ "#" ; any
|
19
20
|
/ "~" S typename [genericarg]
|
@@ -22,7 +23,7 @@ type1 = type2 [S (rangeop / annotator) S type2]
|
|
22
23
|
/ "&" S "(" S group S ")"
|
23
24
|
/ "&" S groupname [genericarg]
|
24
25
|
|
25
|
-
|
26
|
+
headnumber = uint / ("<" type ">")
|
26
27
|
|
27
28
|
type2 = value
|
28
29
|
/ typename [genericarg]
|
data/lib/cddl.rb
CHANGED
@@ -2,6 +2,7 @@ require 'abnc'
|
|
2
2
|
require 'pp'
|
3
3
|
require 'pathname'
|
4
4
|
require 'cbor-pure' unless defined?(CBOR::Tagged)
|
5
|
+
require 'half'
|
5
6
|
require 'cbor-deterministic'
|
6
7
|
require 'regexp-examples'
|
7
8
|
require 'abnftt'
|
@@ -429,7 +430,11 @@ module CDDL
|
|
429
430
|
end
|
430
431
|
CBOR::Tagged.new(tn, generate1(where[3]))
|
431
432
|
when 7
|
432
|
-
|
433
|
+
w2 = where[2]
|
434
|
+
if Array === w2
|
435
|
+
w2 = generate1(w2)
|
436
|
+
end
|
437
|
+
case w2
|
433
438
|
when nil
|
434
439
|
Math::PI
|
435
440
|
when 20
|
@@ -439,9 +444,21 @@ module CDDL
|
|
439
444
|
when 22
|
440
445
|
nil
|
441
446
|
when 0..19, 23, 32..255
|
442
|
-
CBOR::Simple.new(
|
443
|
-
when 25
|
444
|
-
rand()
|
447
|
+
CBOR::Simple.new(w2)
|
448
|
+
when 25
|
449
|
+
while !(hs = Half.encode_from_single_bytes([rand()].pack("g")))
|
450
|
+
end
|
451
|
+
Half.decode(hs)
|
452
|
+
when 26
|
453
|
+
while (a = [rand()].pack("g").unpack("g").first).to_cbor.size != 5
|
454
|
+
end
|
455
|
+
a
|
456
|
+
when 27
|
457
|
+
while (a = rand()).to_cbor.size != 9
|
458
|
+
end
|
459
|
+
a
|
460
|
+
else
|
461
|
+
fail "Can't generate prim #7.#{where[2].inspect}" # XXX retry array generate
|
445
462
|
end
|
446
463
|
else
|
447
464
|
fail "Can't generate prim #{where[1]}"
|
@@ -710,17 +727,24 @@ module CDDL
|
|
710
727
|
[:prim, 7, 22] => [true, nil, :nil],
|
711
728
|
}
|
712
729
|
SIMPLE_VALUE_SIMPLE = Set[23] + (0..19) + (32..255)
|
713
|
-
SIMPLE_VALUE.default_proc = proc { |hash, t|
|
714
|
-
if t[0] == :prim && t[1] == 7 && SIMPLE_VALUE_SIMPLE.include?(t[2])
|
715
|
-
[true, CBOR::Simple.new(t[2]), :simple]
|
716
|
-
end
|
717
|
-
}
|
718
730
|
|
719
731
|
def extract_value(t) # []
|
720
732
|
if vt = VALUE_TYPE[t[0]]
|
721
733
|
[true, t[1], vt]
|
722
|
-
elsif
|
723
|
-
|
734
|
+
elsif t[0] == :prim && t[1] == 7
|
735
|
+
case t2 = t[2]
|
736
|
+
when Integer
|
737
|
+
when Array
|
738
|
+
a, b, c = extract_value(t2)
|
739
|
+
if a && c == Integer
|
740
|
+
t2 = b
|
741
|
+
end
|
742
|
+
end
|
743
|
+
if v = SIMPLE_VALUE[[:prim, 7, t2]]
|
744
|
+
v
|
745
|
+
elsif SIMPLE_VALUE_SIMPLE === t2
|
746
|
+
[true, CBOR::Simple.new(t2), :simple]
|
747
|
+
end
|
724
748
|
elsif t[0] == :anno
|
725
749
|
_, conop, target, control = t
|
726
750
|
# warn ["EXV0", conop, target, control].inspect
|
@@ -968,6 +992,7 @@ module CDDL
|
|
968
992
|
end
|
969
993
|
|
970
994
|
OPERATORS = {lt: :<, le: :<=, gt: :>, ge: :>=, eq: :==, ne: :!=}
|
995
|
+
FLOAT_AI_FROM_SIZE = {3 => 25, 5 => 26, 9 => 27}
|
971
996
|
|
972
997
|
def validate1(d, where)
|
973
998
|
if ENV["CDDL_TRACE"]
|
@@ -1023,6 +1048,12 @@ module CDDL
|
|
1023
1048
|
end
|
1024
1049
|
# warn ["ANNO", ok1, v1, vt1, ok2, v2, vt2, d].inspect
|
1025
1050
|
[] if d == v1 + v2 # XXX Focus ArgumentError
|
1051
|
+
elsif conop == :plus && Integer === d
|
1052
|
+
if ok1 && vt1 == Integer
|
1053
|
+
validate1a(d - Integer(v1), control)
|
1054
|
+
elsif ok2 && vt2 == Integer
|
1055
|
+
validate1a(d - Integer(v2), target)
|
1056
|
+
end
|
1026
1057
|
end
|
1027
1058
|
elsif ann = validate1a(d, target)
|
1028
1059
|
case conop
|
@@ -1235,12 +1266,25 @@ module CDDL
|
|
1235
1266
|
if t
|
1236
1267
|
v.eql? d
|
1237
1268
|
else
|
1238
|
-
case where[2]
|
1269
|
+
case w2 = where[2]
|
1239
1270
|
when nil
|
1240
|
-
|
1241
|
-
|
1271
|
+
Float === d || CBOR::Simple === d || [false, true, nil].include?(d)
|
1272
|
+
when Array
|
1273
|
+
headnum = case d
|
1274
|
+
when Float
|
1275
|
+
FLOAT_AI_FROM_SIZE[d.to_cbor.size]
|
1276
|
+
when false
|
1277
|
+
20
|
1278
|
+
when true
|
1279
|
+
21
|
1280
|
+
when nil
|
1281
|
+
22
|
1282
|
+
when CBOR::Simple
|
1283
|
+
d.value
|
1284
|
+
end
|
1285
|
+
validate1a(headnum, w2)
|
1242
1286
|
when 25, 26, 27
|
1243
|
-
Float === d
|
1287
|
+
Float === d && FLOAT_AI_FROM_SIZE[d.to_cbor.size] == w2
|
1244
1288
|
else
|
1245
1289
|
fail [:val7, d, where].inspect
|
1246
1290
|
end
|
@@ -1589,7 +1633,7 @@ module CDDL
|
|
1589
1633
|
when /\A#(\d+)/
|
1590
1634
|
maj = $1.to_i
|
1591
1635
|
s = [:prim, maj, *n.children(:uint).map(&:to_s).map(&:to_i)]
|
1592
|
-
if tn = n.
|
1636
|
+
if tn = n.headnumber
|
1593
1637
|
if ui = tn.uint
|
1594
1638
|
s << ui.to_s.to_i
|
1595
1639
|
elsif tt = tn.type
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cddl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.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: 2024-
|
11
|
+
date: 2024-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cbor-diag
|
@@ -185,6 +185,10 @@ files:
|
|
185
185
|
- test-data/decimal.cddl
|
186
186
|
- test-data/decimal2.cddl
|
187
187
|
- test-data/det1.cddl
|
188
|
+
- test-data/dotplus1.cddl
|
189
|
+
- test-data/dotplus2.cddl
|
190
|
+
- test-data/dotplus3.cddl
|
191
|
+
- test-data/dotplus4.cddl
|
188
192
|
- test-data/dotsize.cddl
|
189
193
|
- test-data/extractor-demo.cddl
|
190
194
|
- test-data/feat1.cddl
|