sereal 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/rsrl +5 -3
- data/ext/sereal/buffer.h +133 -57
- data/ext/sereal/decode.c +224 -187
- data/ext/sereal/encode.c +187 -184
- data/ext/sereal/proto.h +1 -1
- data/ext/sereal/sereal.c +18 -2
- data/ext/sereal/sereal.h +34 -23
- metadata +2 -2
data/ext/sereal/sereal.c
CHANGED
@@ -19,13 +19,29 @@ void Init_sereal();
|
|
19
19
|
*
|
20
20
|
* If the blob contains multiple compressed
|
21
21
|
* sub-blobs you should call it with:
|
22
|
-
*
|
22
|
+
*
|
23
23
|
* Sereal.decode(blob) do |decoded|
|
24
|
-
* # do something with the decoded object
|
24
|
+
* # do something with the decoded object
|
25
25
|
* end
|
26
|
+
*
|
26
27
|
* otherwise only the first decoded object will be returned
|
28
|
+
* there is also streaming support which takes any kind of IO object
|
29
|
+
* like socket, or just regular File, and it is really easy to use:
|
30
|
+
*
|
31
|
+
* Sereal.decode(STDIN) do |decoded|
|
32
|
+
* # do something with the decoded object
|
33
|
+
* end
|
34
|
+
*
|
35
|
+
* it works both with `incremental snappy` and with just combined sereal packets.
|
36
|
+
* another example but with TCPSocket:
|
37
|
+
*
|
38
|
+
* s = TCPSocket.new 'localhost', 2000
|
39
|
+
* Sereal.decode(s) do |decoded|
|
40
|
+
* # do something with the decoded object
|
41
|
+
* end
|
27
42
|
*
|
28
43
|
*/
|
44
|
+
|
29
45
|
void Init_sereal() {
|
30
46
|
Sereal = rb_define_class("Sereal", rb_cObject);
|
31
47
|
rb_define_singleton_method(Sereal, "encode", method_sereal_encode, -2);
|
data/ext/sereal/sereal.h
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
#define _MAIN_H
|
3
3
|
#include <ruby.h>
|
4
4
|
#include <ruby/encoding.h>
|
5
|
+
#include <ruby/io.h>
|
5
6
|
#include <ruby/st.h>
|
6
7
|
#include <string.h> /* memcpy,memset */
|
7
8
|
#include "proto.h"
|
@@ -29,17 +30,21 @@ typedef struct _track_entry track_t;
|
|
29
30
|
|
30
31
|
#define SRL_HDR_SYM SRL_HDR_RESERVED_LOW
|
31
32
|
#define SRL_HDR_RB_OBJ (SRL_HDR_RESERVED_LOW+1)
|
32
|
-
#define _D(fmt,arg...) fprintf(stderr,"%s(): " fmt "\n",__func__,##arg)
|
33
33
|
|
34
34
|
#ifdef ONIGURUMA_H
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
#define IGNORECASE ONIG_OPTION_IGNORECASE
|
36
|
+
#define MULTILINE ONIG_OPTION_MULTILINE
|
37
|
+
#define EXTENDED ONIG_OPTION_EXTEND
|
38
38
|
#else
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
#define IGNORECASE RE_OPTION_IGNORECASE
|
40
|
+
#define MULTILINE RE_OPTION_MULTILINE
|
41
|
+
#define EXTENDED RE_OPTION_EXTENDED
|
42
42
|
#endif
|
43
|
+
|
44
|
+
#define FORMAT(fmt,arg...) fmt " [%s():%s:%d @ %u]\n",##arg,__func__,__FILE__,__LINE__,(unsigned int) time(NULL)
|
45
|
+
#define E(fmt,arg...) fprintf(stderr,FORMAT(fmt,##arg))
|
46
|
+
#define D(fmt,arg...) printf(FORMAT(fmt,##arg))
|
47
|
+
|
43
48
|
#define s_raise(what,ex,arg...) \
|
44
49
|
do { \
|
45
50
|
s_destroy(what); \
|
@@ -47,30 +52,36 @@ do { \
|
|
47
52
|
} while(0);
|
48
53
|
|
49
54
|
#define FLAG_NOT_MINE 1
|
55
|
+
#define FLAG_STREAM 2
|
50
56
|
struct _sereal {
|
51
|
-
|
52
|
-
|
57
|
+
u8 *data;
|
58
|
+
u32 size;
|
59
|
+
u32 pos;
|
60
|
+
u32 rsize;
|
61
|
+
u32 level;
|
62
|
+
u8 flags;
|
63
|
+
VALUE tracked;
|
64
|
+
u32 hdr_end;
|
65
|
+
int fd;
|
66
|
+
struct buffer {
|
67
|
+
u8 data[BUFSIZ];
|
53
68
|
u32 pos;
|
54
|
-
u32
|
55
|
-
|
56
|
-
u8 flags;
|
57
|
-
VALUE tracked;
|
58
|
-
u32 hdr_end;
|
69
|
+
u32 size;
|
70
|
+
} buffer;
|
59
71
|
};
|
60
72
|
|
61
73
|
VALUE method_sereal_encode(VALUE self, VALUE args);
|
62
74
|
VALUE method_sereal_decode(VALUE self, VALUE payload);
|
63
75
|
|
64
|
-
#define S_RECURSE_INC(s)
|
65
|
-
do {
|
66
|
-
if((s)->level++ > MAX_RECURSION_DEPTH)
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
} while(0);
|
76
|
+
#define S_RECURSE_INC(s) \
|
77
|
+
do { \
|
78
|
+
if((s)->level++ > MAX_RECURSION_DEPTH) \
|
79
|
+
s_raise((s),rb_eArgError, \
|
80
|
+
"max recursion depth reached: %d (level: %d)", \
|
81
|
+
MAX_RECURSION_DEPTH, s->level); \
|
82
|
+
} while(0);
|
71
83
|
|
72
84
|
#define S_RECURSE_DEC(s) ((s)->level--)
|
73
|
-
|
74
85
|
#ifndef HAVE_RB_INTERN_STR
|
75
86
|
#define rb_intern_str(string) SYM2ID(rb_str_intern(string))
|
76
87
|
#endif
|
@@ -81,5 +92,5 @@ do { \
|
|
81
92
|
#define __RAW 0
|
82
93
|
#define __SNAPPY 1
|
83
94
|
#define __SNAPPY_INCR 2
|
84
|
-
|
95
|
+
#define __MIN_SIZE 6
|
85
96
|
#endif
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sereal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Borislav Nikolov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|