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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +10 -16
- data/ext/listpack/listpack_rb.c +18 -8
- data/lib/listpack/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f59538906cf18c4c70e63a44cb070015653a8a3d0d7733707806fa83be30a01
|
4
|
+
data.tar.gz: 2400a85a4523e03df4ac447e768ae1c01a84b78fb00b14a28cec18a443d9cc54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a3430297a5b914fdcf4d174f7e541bdf681bca55ea92512f4e7416730ce6b3fd1be763219fc983c869bbe7d9e5b85dde5611d46e141b2ba4dad586b534cb539
|
7
|
+
data.tar.gz: 72b24a42842d6de03fde63303c5c1602d6693e59712646e1e708f961c62935255841d327fa3d621a775d38632a7cd505fd232e2eaa2d3711a429b9e0618f217f
|
data/Gemfile.lock
CHANGED
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
|
-
|
26
|
-
|
27
|
-
lp.
|
28
|
-
|
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
|
-
|
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
|
-
|
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
|
45
|
-
# => 1234
|
46
|
-
lp.next
|
47
|
-
# => "string"
|
40
|
+
ary = Listpack.load(lp)
|
41
|
+
# => [1234, "string"]
|
48
42
|
```
|
49
43
|
|
50
44
|
## Development
|
data/ext/listpack/listpack_rb.c
CHANGED
@@ -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
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
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
|
-
|
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)
|
data/lib/listpack/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2018-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|