listpack 0.0.1.beta3 → 0.0.1.beta4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf0000e6a9319e810ad90290e80bb6375bcaf8c91407f01d0caeb05bdca53ffd
4
- data.tar.gz: d6e9fc6e06ac5ebbca6242e60bd5d1cca12a57b2bbcc6620d369179c1c32253f
3
+ metadata.gz: 4f59538906cf18c4c70e63a44cb070015653a8a3d0d7733707806fa83be30a01
4
+ data.tar.gz: 2400a85a4523e03df4ac447e768ae1c01a84b78fb00b14a28cec18a443d9cc54
5
5
  SHA512:
6
- metadata.gz: 8c823632a71f7e2a334ac0cd2b8d437243103c31e034b3e3393c14f526d108fc7ada25fcc93bb9d6dc5447d7dd78073e204659e203839c81e095146fd1529361
7
- data.tar.gz: 640eae14403530aaaf6ecf5a0de107edd839576a80be8f8aa5f2ae3f47faf431479cb4039776d669fc26ee949eeae22ab3f9673b390941ecef52c2ade68c4fcb
6
+ metadata.gz: 1a3430297a5b914fdcf4d174f7e541bdf681bca55ea92512f4e7416730ce6b3fd1be763219fc983c869bbe7d9e5b85dde5611d46e141b2ba4dad586b534cb539
7
+ data.tar.gz: 72b24a42842d6de03fde63303c5c1602d6693e59712646e1e708f961c62935255841d327fa3d621a775d38632a7cd505fd232e2eaa2d3711a429b9e0618f217f
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- listpack (0.0.1.beta3)
4
+ listpack (0.0.1.beta4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  Ruby wrapper for [Redis listpack](https://gist.github.com/antirez/66ffab20190ece8a7485bd9accfbc175) data structure
4
4
 
5
-
6
5
  ## Installation
7
6
 
8
7
  Add this line to your application's Gemfile:
@@ -22,29 +21,24 @@ Or install it yourself as:
22
21
  ## Usage
23
22
 
24
23
  ```ruby
25
- lp = Listpack.new
26
-
27
- lp.append('1234')
28
- lp.append('string')
24
+ # Strings containing number are automatically converted to integers
25
+ ary = ['1234', 'string']
26
+ lp = Listpack.dump(ary)
27
+ # => "\x12\x00\x00\x00\x02\x00\xC4\xD2\x02\x86string\a\xFF"
29
28
 
30
- lp.to_s
29
+ # This will be the same as the above
30
+ ary = [1234, 'string']
31
+ lp = Listpack.dump(ary)
31
32
  # => "\x12\x00\x00\x00\x02\x00\xC4\xD2\x02\x86string\a\xFF"
32
33
  ```
33
34
 
34
35
  #### Load a serialized listpack
35
36
 
36
37
  ```ruby
37
- data = "\x12\x00\x00\x00\x02\x00\xC4\xD2\x02\x86string\a\xFF"
38
-
39
- lp = Listpack.new(data)
40
-
41
- lp.size
42
- # => 2
38
+ lp = "\x12\x00\x00\x00\x02\x00\xC4\xD2\x02\x86string\a\xFF"
43
39
 
44
- lp.next
45
- # => 1234
46
- lp.next
47
- # => "string"
40
+ ary = Listpack.load(lp)
41
+ # => [1234, "string"]
48
42
  ```
49
43
 
50
44
  ## Development
@@ -200,18 +200,28 @@ VALUE rb_class_listpack_dump(VALUE self, VALUE rb_ary)
200
200
  unsigned char *lp = lpNew();
201
201
  unsigned int i = 0;
202
202
  VALUE current;
203
+ VALUE retval;
203
204
 
204
205
  for (i = 0; i < len; i++) {
205
- current = rb_ary_entry(rb_ary, i);
206
- // TODO: convert integer to string if necessary
207
- Check_Type(current, T_STRING);
208
- lp = lpAppend(lp, (unsigned char *) RSTRING_PTR(current), RSTRING_LENINT(current));
209
- if (lp == NULL) {
210
- rb_raise(rb_eNoMemError, "no memory for listpack");
211
- }
206
+ current = rb_ary_entry(rb_ary, i);
207
+
208
+ if (rb_type(current) == T_FIXNUM) {
209
+ current = rb_funcall(current, rb_intern("to_s"), 0);
210
+ } else if (rb_type(current) != T_STRING) {
211
+ lpFree(lp);
212
+ rb_raise(rb_eArgError, "wrong type");
213
+ }
214
+
215
+ lp = lpAppend(lp, (unsigned char *) RSTRING_PTR(current), RSTRING_LENINT(current));
216
+
217
+ if (lp == NULL) {
218
+ rb_raise(rb_eNoMemError, "no memory for listpack");
219
+ }
212
220
  }
213
221
 
214
- return rb_str_new((char *) lp, lpBytes(lp));
222
+ retval = rb_str_new((char *) lp, lpBytes(lp));
223
+ lpFree(lp);
224
+ return retval;
215
225
  }
216
226
 
217
227
  VALUE rb_class_listpack_load(VALUE self, VALUE rb_str)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Listpack
4
- VERSION = '0.0.1.beta3'
4
+ VERSION = '0.0.1.beta4'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: listpack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.beta3
4
+ version: 0.0.1.beta4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Wallin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-05 00:00:00.000000000 Z
11
+ date: 2018-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler