cbor-packed 0.1.3 → 0.1.5
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/cbor-packed.gemspec +1 -1
- data/lib/cbor-packed.rb +37 -10
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aac07ac277ddc9d142fcfd1d2b6b6b07279522354e3f72b4cbec52466e94b6c3
|
4
|
+
data.tar.gz: 7963b3afd7a8e205b65b5e4fb4a69496aa358e29aac1c1cc126fa4b14db38b20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e25f214b1944aa20817ee2e4fc9640c7d2c8f698bb22fb9e207aa22d2ba7adb78a32fb8b2ef51e8b7d8c981e3d0b29b8aca97f932ca54cc70ad14268756f797
|
7
|
+
data.tar.gz: 1200e4a27c0e2063ed4073406a0e55f4a12eb0efec213b5e26b069924a4a699a450e180c80302cba144883e5cafad31b6fab11a3b8e7e3ce6e2b2c87003ee2d2
|
data/cbor-packed.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "cbor-packed"
|
3
|
-
s.version = "0.1.
|
3
|
+
s.version = "0.1.5"
|
4
4
|
s.summary = "CBOR (Concise Binary Object Representation) packer"
|
5
5
|
s.description = %q{cbor-packed implements packed encoding for CBOR, RFC 7049 Section 3.9}
|
6
6
|
s.author = "Carsten Bormann"
|
data/lib/cbor-packed.rb
CHANGED
@@ -9,6 +9,8 @@ module CBOR
|
|
9
9
|
PACKED_TAG = 51
|
10
10
|
REF_TAG = 6
|
11
11
|
|
12
|
+
REF_SIZE = [*Array.new(16, 1), *Array.new(48, 2), *Array.new(512-48, 3)]
|
13
|
+
|
12
14
|
class Packer
|
13
15
|
def self.from_item(item)
|
14
16
|
count = Hash.new(0)
|
@@ -29,8 +31,16 @@ module CBOR
|
|
29
31
|
# pp better_count
|
30
32
|
|
31
33
|
# now: take the best out???; re-visit that reducing by n; re-sort and filter???
|
32
|
-
|
33
|
-
|
34
|
+
|
35
|
+
# sort by descending number of references we'll get
|
36
|
+
# -- the higher reference counts go first
|
37
|
+
# then filter out the entries that actually improve
|
38
|
+
|
39
|
+
match_array = []
|
40
|
+
|
41
|
+
better_count.sort_by {|a| -a[1]}.each {|a|
|
42
|
+
match_array << a[0] if (REF_SIZE[match_array.size] || 4) < a[2]
|
43
|
+
}
|
34
44
|
# pp match_array
|
35
45
|
|
36
46
|
# XXX the below needs to be done with arrays and (hard!) maps as well
|
@@ -145,8 +155,12 @@ module CBOR
|
|
145
155
|
def unsimple(sv)
|
146
156
|
@simple_array[sv]
|
147
157
|
end
|
148
|
-
def untag(
|
149
|
-
@tagged_array[(i << 1) ^ (i >> 63)]
|
158
|
+
def untag(i)
|
159
|
+
# @tagged_array[(i << 1) ^ (i >> 63)]
|
160
|
+
ix = (i << 1) ^ (i >> 63)
|
161
|
+
ret = @tagged_array[ix]
|
162
|
+
# warn "** UNTAG i=#{i} ix=#{ix} ret=#{ret}"
|
163
|
+
ret
|
150
164
|
end
|
151
165
|
def unprefix(n)
|
152
166
|
@prefix_array[n]
|
@@ -193,7 +207,16 @@ module CBOR
|
|
193
207
|
module String_Packed_CBOR
|
194
208
|
def packed_merge(other, unpacker)
|
195
209
|
# add checks
|
196
|
-
|
210
|
+
lhs = to_unpacked_cbor1(unpacker)
|
211
|
+
rhs = other.to_unpacked_cbor1(unpacker)
|
212
|
+
begin
|
213
|
+
lhs + rhs
|
214
|
+
rescue => detail
|
215
|
+
warn "** lhs = #{lhs.inspect}"
|
216
|
+
warn "** rhs = #{rhs.inspect}"
|
217
|
+
warn "** error: #{detail}"
|
218
|
+
lhs + rhs.to_s
|
219
|
+
end
|
197
220
|
end
|
198
221
|
end
|
199
222
|
String.send(:include, String_Packed_CBOR)
|
@@ -211,7 +234,7 @@ module CBOR
|
|
211
234
|
end
|
212
235
|
def to_packed_cbor1(packer = Packer.from_item(self))
|
213
236
|
if c = packer.has(self)
|
214
|
-
c.
|
237
|
+
c.to_packed_cbor1(packer)
|
215
238
|
else
|
216
239
|
# TODO: Find useful prefixes
|
217
240
|
map {|x| x.to_packed_cbor1(packer)}
|
@@ -238,7 +261,7 @@ module CBOR
|
|
238
261
|
end
|
239
262
|
def to_packed_cbor1(packer = Packer.from_item(self))
|
240
263
|
if c = packer.has(self)
|
241
|
-
c.
|
264
|
+
c.to_packed_cbor1(packer)
|
242
265
|
else
|
243
266
|
# TODO: Find useful prefixes
|
244
267
|
Hash[map {|k, v| [k.to_packed_cbor1(packer), v.to_packed_cbor1(packer)]}]
|
@@ -271,10 +294,14 @@ module CBOR
|
|
271
294
|
def to_unpacked_cbor1(unpacker)
|
272
295
|
case tag
|
273
296
|
when REF_TAG
|
274
|
-
|
275
|
-
|
297
|
+
# warn "** REF_TAG1 value #{value.class.inspect} #{value.inspect}"
|
298
|
+
unpacked_value = value.to_unpacked_cbor1(unpacker)
|
299
|
+
# warn "** REF_TAG2 value #{unpacked_value.class.inspect} #{unpacked_value.inspect}"
|
300
|
+
if Integer === unpacked_value
|
301
|
+
# warn "** I REF_TAG value #{value.class.inspect} #{value.inspect}"
|
302
|
+
unpacker.untag(unpacked_value)
|
276
303
|
else
|
277
|
-
unpacker.unprefix(0).packed_merge
|
304
|
+
unpacker.unprefix(0).packed_merge unpacked_value, unpacker
|
278
305
|
end
|
279
306
|
when 225...256
|
280
307
|
unpacker.unprefix(tag-(256-32)).packed_merge value, unpacker
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cbor-packed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carsten Bormann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: cbor-packed implements packed encoding for CBOR, RFC 7049 Section 3.9
|
14
14
|
email: cabo@tzi.org
|
@@ -40,7 +40,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
42
|
requirements: []
|
43
|
-
rubygems_version: 3.
|
43
|
+
rubygems_version: 3.3.7
|
44
44
|
signing_key:
|
45
45
|
specification_version: 4
|
46
46
|
summary: CBOR (Concise Binary Object Representation) packer
|