tinybits 0.2.0 → 0.3.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: 51ab487694dc35eabde1bebda52a2726074ab6c80ef84ce2c845141c9732283c
4
- data.tar.gz: 5c3b2c2eb52a15fb5e32d54c37d705fd41c9ec4759464519c599f83f517b9e2b
3
+ metadata.gz: 340b92ea6c9e9782aa1b63c08c226d23bae56d1d5780dc46fb79f9c0a508b71b
4
+ data.tar.gz: 7fdeb074fe4a24e061834e1084702ee97827698eaa46f907b7b0a756b7ea05be
5
5
  SHA512:
6
- metadata.gz: 65fd3c3a22a67d8a1a6a218644d4ed82171386202de0b09ce86c285501852cf40c71690820defbf811be66db29da6346d9e933878027377e1ac0c680c08cdf60
7
- data.tar.gz: 6d389ea71dac6c417956d98dfe545f3baa015f2947ce968d9f8ec2f0dbe62ffdd5f841fb789658b00a69fe7975b8ed7788b1747a2867440fee10f0c19b05c243
6
+ metadata.gz: 0c286652db3de7817fbea5241f10221f666cc298121348dbe5718f9221c6d9ef4beed593d478851367b877bc3c66bbf1dcc359b4fb5997221790353bf1bbbcb9
7
+ data.tar.gz: 9b67f07cb2c1b656aa7dc843fd8441760473ba8047af09cc220508ed9e604889ab213b2f4c69855c4dbe9114190836b5603c898d0c3c4f8ce9b68b2dd77539c4
@@ -7,19 +7,30 @@ t = [Time.now, nil, true, false]
7
7
 
8
8
 
9
9
 
10
-
10
+ =begin
11
11
  puts packer.dump(t).bytesize
12
12
 
13
13
  puts t
14
14
  puts t2 = unpacker.unpack(packer.pack(t))
15
15
  puts t == t2
16
-
16
+ =end
17
+
18
+ class User
19
+ def initialize(name:, title:)
20
+ @name = name
21
+ @title = title
22
+ end
23
+
24
+ def to_tinybits
25
+ {"name" => @name, "title" => @title}
26
+ end
27
+ end
17
28
 
18
29
  objects = [{"abc": 123}, {"abc": [1, 2, "abc"]}, ["xyz", "abc", "xyz", 7.6] ]
19
30
 
20
31
  puts "----------------"
21
32
 
22
- packer.reset
33
+ #packer.reset
23
34
 
24
35
  objects.each do |obj|
25
36
  puts packer << obj
@@ -31,7 +42,21 @@ puts buffer.bytesize
31
42
 
32
43
  unpacker.buffer = buffer
33
44
 
45
+
34
46
  while(value = unpacker.pop)
35
47
  pp value
36
48
  puts "+++++++++++++++++++++++++"
37
49
  end
50
+
51
+ packer.reset
52
+
53
+ user = User.new(name: "Mohamed", title: "Father")
54
+
55
+ data = { "user" => user, "tags" => ["user", "Father"] }
56
+
57
+ pp user
58
+ pp user.to_tinybits
59
+ packed = packer.pack(data)
60
+ puts packed.bytesize
61
+ pp unpacker.unpack(packed)
62
+
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * TinyBits Amalgamated Header
3
- * Generated on: Sat May 3 09:20:46 PM CEST 2025
3
+ * Generated on: Sun May 4 03:12:10 AM CEST 2025
4
4
  */
5
5
 
6
6
  #ifndef TINY_BITS_H
@@ -90,7 +90,7 @@ typedef struct HashTable {
90
90
  static inline uint32_t fast_hash_32(const char* str, uint16_t len) {
91
91
  uint32_t hash = len;
92
92
  hash = (hash << 16) | (((unsigned char)str[0] << 8) | (unsigned char)str[1]);
93
- hash ^= (((unsigned char)str[len-2] << 8) | (unsigned char)str[len-1]);
93
+ hash ^= (((unsigned char)str[len-2] << 24) | ((unsigned char)str[len-1] << 16));
94
94
  return hash;
95
95
  }
96
96
 
@@ -1052,7 +1052,7 @@ static inline enum tiny_bits_type _unpack_str(tiny_bits_unpacker *decoder, uint8
1052
1052
  }
1053
1053
  value->str_blob_val.id = 0;
1054
1054
  // Handle new string (not deduplicated)
1055
- if(decoder->strings_count < TB_HASH_CACHE_SIZE){
1055
+ if(decoder->strings_count < TB_HASH_CACHE_SIZE && len >= 2 && len <= 128){
1056
1056
  if (decoder->strings_count >= decoder->strings_size) {
1057
1057
  size_t new_size = decoder->strings_size * 2;
1058
1058
  void *new_strings = realloc(decoder->strings, new_size * sizeof(*decoder->strings));
@@ -131,6 +131,10 @@ static inline int pack_ruby_object_recursive(tiny_bits_packer* packer, VALUE obj
131
131
  double unixtime = NUM2DBL(rb_funcall(obj, rb_intern("to_f"), 0));
132
132
  return pack_datetime(packer, unixtime, FIX2INT(rb_time_utc_offset(obj)));
133
133
  }
134
+ if(rb_respond_to(obj, rb_intern("to_tinybits"))){
135
+ VALUE custom_obj = rb_funcall(obj, rb_intern("to_tinybits"), 0);
136
+ return pack_ruby_object_recursive(packer, custom_obj, context);
137
+ }
134
138
  //printf("Unsupported type encountered during packing: %s", rb_obj_classname(obj));
135
139
  rb_warn("Unsupported type encountered during packing: %s", rb_obj_classname(obj));
136
140
  return 0;
@@ -1,3 +1,3 @@
1
1
  module TinyBits
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tinybits
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mohamed Hassan
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-05-03 00:00:00.000000000 Z
10
+ date: 2025-05-04 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: TinyBits is a Ruby gem that wraps the TinyBits C serializartion library,
13
13
  offering Rubyists the power of serializion with intger/float compression and string