wankel 0.4.0 → 0.5.0

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
  SHA1:
3
- metadata.gz: d39a95397c69844f5192789cd5df648a8e9a8b47
4
- data.tar.gz: 62d409b5d77f50cb3747ea8bf2cc18e38fa271a0
3
+ metadata.gz: f6571c0e2472dab431e07ca8ee912e4a88b5319d
4
+ data.tar.gz: 50aeba78c777dd142181126b1fefba3480a200e1
5
5
  SHA512:
6
- metadata.gz: efd5c840d75fef714ed9f3483107f3ab18938630f21f025567586496afb3f92067842e2694c79b59ff3b42d2425177a3ab1cf9c6482ddc19c635819886622976
7
- data.tar.gz: be6ee04733bc4f3a02e1402fba54ec017559a258564b4da7768c77b5925b40cb800d17f5f33739dd74a62081ba84ae3446c171089df3bd1973c3f6f019e41a80
6
+ metadata.gz: 7d49e4dc10b8a3cccdfec412531226b5e4ccbba35a30c9b148edda091c42ef7c54aa7b368aef8930f46bd6b1fbf4214f1e29414e459d8078ae17ae7756b00433
7
+ data.tar.gz: 8e0a6915521e4d9c7d5d27f580324a60074fe17d3e38078b2c9225e33b188c7abe4b88668fa8021d7827e4474f4afd67ef920847d65c34c44e101daab40fdcd4
@@ -2,6 +2,21 @@
2
2
 
3
3
  New Features:
4
4
 
5
+ Major Changes:
6
+
7
+ Minor Changes:
8
+
9
+ Bugfixes:
10
+
11
+ ## 0.5.0 (December 24th, 2014)
12
+
13
+ - Renaming of `Wankel::SaxEncoder` and `Wankel::SaxParser` to
14
+ `Wankel::StreamEncoder` and `Wankel::StreamParser`.
15
+
16
+ ## 0.4.0 (December 23rd, 2014)
17
+
18
+ New Features:
19
+
5
20
  - Added `Wankel::SaxEncoder#value(VALUE)`
6
21
  - Abilitly to change the output stream of a `Wankel::SaxEncoder` during generation
7
22
  via `Wankel::SaxEncoder#output=`
@@ -10,10 +25,6 @@ Major Changes:
10
25
 
11
26
  - `Wankel::SaxEncoder#complete` changed to `Wankel::SaxEncoder#flush`
12
27
 
13
- Minor Changes:
14
-
15
- Bugfixes:
16
-
17
28
  ## 0.3.0 (August 18th, 2014)
18
29
 
19
30
  Major Changes:
data/README.md CHANGED
@@ -1,18 +1,19 @@
1
1
  <a href="http://wanklerb.com">![Wankel](/logo.png)</a>
2
2
 
3
- [![Circle CI](https://circleci.com/gh/malomalo/wankel/tree/master.svg?style=svg)](https://circleci.com/gh/malomalo/wankel/tree/master)
3
+
4
+ Wankel [![Build Status](https://travis-ci.org/malomalo/wankel.svg?branch=master)](https://travis-ci.org/malomalo/wankel)
5
+ --------
4
6
 
5
7
  **Wankel** is a Ruby gem that provides C bindings to the
6
8
  [YAJL 2](http://lloyd.github.io/yajl/) C Library.
7
9
 
8
10
  Wankel provides gerneral parsing and encoding to and from
9
- [JSON](http://json.org/), but also a SAX style parser and encoder for streaming
10
- parsing and generation.
11
+ [JSON](http://json.org/), but also a streaming parser and encoder.
11
12
 
12
13
  Features
13
14
  --------
14
15
 
15
- * SAX style JSON parsing and encoding
16
+ * Streaming JSON parsing and encoding
16
17
  * JSON parsing and encoding directly to and from an IO stream (file, socket, etc)
17
18
  or String.
18
19
  * Parse and encode *multiple* JSON objects to and from streams or strings
@@ -53,10 +54,10 @@ Wankel.encode({"key" => "value"})
53
54
  # => '{"key":"value"}'
54
55
  ```
55
56
 
56
- #### Sax Parser Example
57
+ #### Streaming Parser Example
57
58
 
58
59
  ```ruby
59
- class SimpleParser < Wankel::SaxParser
60
+ class SimpleParser < Wankel::StreamParser
60
61
  def on_array_start
61
62
  puts "Array start"
62
63
  end
@@ -72,11 +73,11 @@ parser.parse('["string1", null, "string2"]')
72
73
  # => "string2"
73
74
  ```
74
75
 
75
- #### Sax Encoder Example
76
+ #### Streaming Encoder Example
76
77
 
77
78
  ```ruby
78
79
  output = StringIO.new
79
- encoder = Wankel::SaxEncoder.new(output)
80
+ encoder = Wankel::StreamEncoder.new(output)
80
81
  encoder.map_open
81
82
  encoder.string("key")
82
83
  encoder.number(123)
@@ -44,7 +44,7 @@ void Init_wankel() {
44
44
 
45
45
  c_wankelParser = Init_wankel_parser();
46
46
  c_wankelEncoder = Init_wankel_encoder();
47
- Init_wankel_sax_parser();
48
- Init_wankel_sax_encoder();
47
+ Init_wankel_stream_parser();
48
+ Init_wankel_stream_encoder();
49
49
  Init_yajl_helpers();
50
50
  }
@@ -8,8 +8,8 @@
8
8
 
9
9
  #include "wankel_parser.h"
10
10
  #include "wankel_encoder.h"
11
- #include "wankel_sax_parser.h"
12
- #include "wankel_sax_encoder.h"
11
+ #include "wankel_stream_parser.h"
12
+ #include "wankel_stream_encoder.h"
13
13
  #include "yajl_helpers.h"
14
14
 
15
15
  void Init_wankel();
@@ -1,4 +1,4 @@
1
- // TODO: i should use the Wankel::SaxEncoder?
1
+ // TODO: i should use the Wankel::StreamEncoder?
2
2
  #include "wankel_encoder.h"
3
3
 
4
4
  static VALUE c_wankel, c_wankelEncoder, e_encodeError;
@@ -1,4 +1,4 @@
1
- #include "wankel_sax_encoder.h"
1
+ #include "wankel_stream_encoder.h"
2
2
 
3
3
  typedef struct {
4
4
  yajl_gen g;
@@ -6,22 +6,22 @@ typedef struct {
6
6
  int write_buffer_size;
7
7
  } wankel_encoder;
8
8
 
9
- static VALUE wankelSaxEncoder_initialize(int argc, VALUE * argv, VALUE self);
10
- static VALUE wankelSaxEncoder_number(VALUE self, VALUE number);
11
- static VALUE wankelSaxEncoder_string(VALUE self, VALUE string);
12
- static VALUE wankelSaxEncoder_null(VALUE self);
13
- static VALUE wankelSaxEncoder_boolean(VALUE self, VALUE b);
14
- static VALUE wankelSaxEncoder_map_open(VALUE self);
15
- static VALUE wankelSaxEncoder_map_close(VALUE self);
16
- static VALUE wankelSaxEncoder_array_open(VALUE self);
17
- static VALUE wankelSaxEncoder_array_close(VALUE self);
18
- static VALUE wankelSaxEncoder_flush(VALUE self);
19
- static void wankelSaxEncoder_write_buffer(wankel_encoder * p);
20
- static VALUE wankel_sax_encoder_alloc(VALUE klass);
21
- static void wankel_sax_encoder_free(void * handle);
22
- static void wankel_sax_encoder_mark(void * handle);
23
-
24
- static VALUE c_wankel, c_wankelSaxEncoder, e_encodeError;
9
+ static VALUE wankelStreamEncoder_initialize(int argc, VALUE * argv, VALUE self);
10
+ static VALUE wankelStreamEncoder_number(VALUE self, VALUE number);
11
+ static VALUE wankelStreamEncoder_string(VALUE self, VALUE string);
12
+ static VALUE wankelStreamEncoder_null(VALUE self);
13
+ static VALUE wankelStreamEncoder_boolean(VALUE self, VALUE b);
14
+ static VALUE wankelStreamEncoder_map_open(VALUE self);
15
+ static VALUE wankelStreamEncoder_map_close(VALUE self);
16
+ static VALUE wankelStreamEncoder_array_open(VALUE self);
17
+ static VALUE wankelStreamEncoder_array_close(VALUE self);
18
+ static VALUE wankelStreamEncoder_flush(VALUE self);
19
+ static void wankelStreamEncoder_write_buffer(wankel_encoder * p);
20
+ static VALUE wankel_stream_encoder_alloc(VALUE klass);
21
+ static void wankel_stream_encoder_free(void * handle);
22
+ static void wankel_stream_encoder_mark(void * handle);
23
+
24
+ static VALUE c_wankel, c_wankelStreamEncoder, e_encodeError;
25
25
 
26
26
  static ID intern_to_s, intern_keys, intern_io_write, intern_to_json, intern_clone, intern_merge, intern_DEFAULTS;
27
27
 
@@ -47,7 +47,7 @@ static ID sym_beautify, sym_indent_string, sym_validate_utf8, sym_escape_solidus
47
47
  * it in the iterest of saving bytes. Setting this flag will
48
48
  * cause YAJL to always escape '/' in generated JSON strings.
49
49
  */
50
- static VALUE wankelSaxEncoder_initialize(int argc, VALUE * argv, VALUE self) {
50
+ static VALUE wankelStreamEncoder_initialize(int argc, VALUE * argv, VALUE self) {
51
51
  VALUE defaults = rb_const_get(c_wankel, intern_DEFAULTS);
52
52
  VALUE io, options;
53
53
  wankel_encoder * p;
@@ -80,7 +80,7 @@ static VALUE wankelSaxEncoder_initialize(int argc, VALUE * argv, VALUE self) {
80
80
  return self;
81
81
  }
82
82
 
83
- static VALUE wankelSaxEncoder_change_io(VALUE self, VALUE io) {
83
+ static VALUE wankelStreamEncoder_change_io(VALUE self, VALUE io) {
84
84
  wankel_encoder * p;
85
85
 
86
86
  if (!rb_respond_to(io, intern_io_write)) {
@@ -89,13 +89,13 @@ static VALUE wankelSaxEncoder_change_io(VALUE self, VALUE io) {
89
89
 
90
90
  Data_Get_Struct(self, wankel_encoder, p);
91
91
 
92
- wankelSaxEncoder_flush(self);
92
+ wankelStreamEncoder_flush(self);
93
93
  p->output = io;
94
94
 
95
95
  return Qnil;
96
96
  }
97
97
 
98
- static VALUE wankelSaxEncoder_number(VALUE self, VALUE number) {
98
+ static VALUE wankelStreamEncoder_number(VALUE self, VALUE number) {
99
99
  size_t len;
100
100
  const char * cptr;
101
101
  wankel_encoder * p;
@@ -113,12 +113,12 @@ static VALUE wankelSaxEncoder_number(VALUE self, VALUE number) {
113
113
  status = yajl_gen_number(p->g, cptr, len);
114
114
  yajl_helper_check_gen_status(status);
115
115
 
116
- wankelSaxEncoder_write_buffer(p);
116
+ wankelStreamEncoder_write_buffer(p);
117
117
 
118
118
  return Qnil;
119
119
  }
120
120
 
121
- static VALUE wankelSaxEncoder_string(VALUE self, VALUE string) {
121
+ static VALUE wankelStreamEncoder_string(VALUE self, VALUE string) {
122
122
  size_t len;
123
123
  const char * cptr;
124
124
  wankel_encoder * p;
@@ -133,12 +133,12 @@ static VALUE wankelSaxEncoder_string(VALUE self, VALUE string) {
133
133
  status = yajl_gen_string(p->g, (const unsigned char *)cptr, len);
134
134
  yajl_helper_check_gen_status(status);
135
135
 
136
- wankelSaxEncoder_write_buffer(p);
136
+ wankelStreamEncoder_write_buffer(p);
137
137
 
138
138
  return Qnil;
139
139
  }
140
140
 
141
- static VALUE wankelSaxEncoder_null(VALUE self) {
141
+ static VALUE wankelStreamEncoder_null(VALUE self) {
142
142
  wankel_encoder * p;
143
143
  yajl_gen_status status;
144
144
  Data_Get_Struct(self, wankel_encoder, p);
@@ -146,12 +146,12 @@ static VALUE wankelSaxEncoder_null(VALUE self) {
146
146
  status = yajl_gen_null(p->g);
147
147
  yajl_helper_check_gen_status(status);
148
148
 
149
- wankelSaxEncoder_write_buffer(p);
149
+ wankelStreamEncoder_write_buffer(p);
150
150
 
151
151
  return Qnil;
152
152
  }
153
153
 
154
- static VALUE wankelSaxEncoder_boolean(VALUE self, VALUE b) {
154
+ static VALUE wankelStreamEncoder_boolean(VALUE self, VALUE b) {
155
155
  wankel_encoder * p;
156
156
  yajl_gen_status status;
157
157
  Data_Get_Struct(self, wankel_encoder, p);
@@ -159,12 +159,12 @@ static VALUE wankelSaxEncoder_boolean(VALUE self, VALUE b) {
159
159
  status = yajl_gen_bool(p->g, RTEST(b));
160
160
  yajl_helper_check_gen_status(status);
161
161
 
162
- wankelSaxEncoder_write_buffer(p);
162
+ wankelStreamEncoder_write_buffer(p);
163
163
 
164
164
  return Qnil;
165
165
  }
166
166
 
167
- static VALUE wankelSaxEncoder_map_open(VALUE self) {
167
+ static VALUE wankelStreamEncoder_map_open(VALUE self) {
168
168
  wankel_encoder * p;
169
169
  yajl_gen_status status;
170
170
  Data_Get_Struct(self, wankel_encoder, p);
@@ -172,12 +172,12 @@ static VALUE wankelSaxEncoder_map_open(VALUE self) {
172
172
  status = yajl_gen_map_open(p->g);
173
173
  yajl_helper_check_gen_status(status);
174
174
 
175
- wankelSaxEncoder_write_buffer(p);
175
+ wankelStreamEncoder_write_buffer(p);
176
176
 
177
177
  return Qnil;
178
178
  }
179
179
 
180
- static VALUE wankelSaxEncoder_map_close(VALUE self) {
180
+ static VALUE wankelStreamEncoder_map_close(VALUE self) {
181
181
  wankel_encoder * p;
182
182
  yajl_gen_status status;
183
183
  Data_Get_Struct(self, wankel_encoder, p);
@@ -185,12 +185,12 @@ static VALUE wankelSaxEncoder_map_close(VALUE self) {
185
185
  status = yajl_gen_map_close(p->g);
186
186
  yajl_helper_check_gen_status(status);
187
187
 
188
- wankelSaxEncoder_write_buffer(p);
188
+ wankelStreamEncoder_write_buffer(p);
189
189
 
190
190
  return Qnil;
191
191
  }
192
192
 
193
- static VALUE wankelSaxEncoder_array_open(VALUE self) {
193
+ static VALUE wankelStreamEncoder_array_open(VALUE self) {
194
194
  wankel_encoder * p;
195
195
  yajl_gen_status status;
196
196
  Data_Get_Struct(self, wankel_encoder, p);
@@ -198,12 +198,12 @@ static VALUE wankelSaxEncoder_array_open(VALUE self) {
198
198
  status = yajl_gen_array_open(p->g);
199
199
  yajl_helper_check_gen_status(status);
200
200
 
201
- wankelSaxEncoder_write_buffer(p);
201
+ wankelStreamEncoder_write_buffer(p);
202
202
 
203
203
  return Qnil;
204
204
  }
205
205
 
206
- static VALUE wankelSaxEncoder_array_close(VALUE self) {
206
+ static VALUE wankelStreamEncoder_array_close(VALUE self) {
207
207
  wankel_encoder * p;
208
208
  yajl_gen_status status;
209
209
  Data_Get_Struct(self, wankel_encoder, p);
@@ -211,12 +211,12 @@ static VALUE wankelSaxEncoder_array_close(VALUE self) {
211
211
  status = yajl_gen_array_close(p->g);
212
212
  yajl_helper_check_gen_status(status);
213
213
 
214
- wankelSaxEncoder_write_buffer(p);
214
+ wankelStreamEncoder_write_buffer(p);
215
215
 
216
216
  return Qnil;
217
217
  }
218
218
 
219
- static VALUE wankelSaxEncoder_flush(VALUE self) {
219
+ static VALUE wankelStreamEncoder_flush(VALUE self) {
220
220
  size_t len;
221
221
  VALUE rbBuffer;
222
222
  wankel_encoder * p;
@@ -235,7 +235,7 @@ static VALUE wankelSaxEncoder_flush(VALUE self) {
235
235
  return Qnil;
236
236
  }
237
237
 
238
- void wankelSaxEncoder_write_buffer(wankel_encoder * p) {
238
+ void wankelStreamEncoder_write_buffer(wankel_encoder * p) {
239
239
  VALUE rbBuffer;
240
240
  yajl_gen_status status;
241
241
  const unsigned char * buffer;
@@ -252,23 +252,23 @@ void wankelSaxEncoder_write_buffer(wankel_encoder * p) {
252
252
  }
253
253
  }
254
254
 
255
- void Init_wankel_sax_encoder() {
255
+ void Init_wankel_stream_encoder() {
256
256
  c_wankel = rb_const_get(rb_cObject, rb_intern("Wankel"));
257
- c_wankelSaxEncoder = rb_define_class_under(c_wankel, "SaxEncoder", rb_cObject);
257
+ c_wankelStreamEncoder = rb_define_class_under(c_wankel, "StreamEncoder", rb_cObject);
258
258
  e_encodeError = rb_const_get(c_wankel, rb_intern("EncodeError"));
259
259
 
260
- rb_define_alloc_func(c_wankelSaxEncoder, wankel_sax_encoder_alloc);
261
- rb_define_method(c_wankelSaxEncoder, "initialize", wankelSaxEncoder_initialize, -1);
262
- rb_define_method(c_wankelSaxEncoder, "number", wankelSaxEncoder_number, 1);
263
- rb_define_method(c_wankelSaxEncoder, "string", wankelSaxEncoder_string, 1);
264
- rb_define_method(c_wankelSaxEncoder, "null", wankelSaxEncoder_null, 0);
265
- rb_define_method(c_wankelSaxEncoder, "boolean", wankelSaxEncoder_boolean, 1);
266
- rb_define_method(c_wankelSaxEncoder, "map_open", wankelSaxEncoder_map_open, 0);
267
- rb_define_method(c_wankelSaxEncoder, "map_close", wankelSaxEncoder_map_close, 0);
268
- rb_define_method(c_wankelSaxEncoder, "array_open", wankelSaxEncoder_array_open, 0);
269
- rb_define_method(c_wankelSaxEncoder, "array_close", wankelSaxEncoder_array_close, 0);
270
- rb_define_method(c_wankelSaxEncoder, "flush", wankelSaxEncoder_flush, 0);
271
- rb_define_method(c_wankelSaxEncoder, "output=", wankelSaxEncoder_change_io, 1);
260
+ rb_define_alloc_func(c_wankelStreamEncoder, wankel_stream_encoder_alloc);
261
+ rb_define_method(c_wankelStreamEncoder, "initialize", wankelStreamEncoder_initialize, -1);
262
+ rb_define_method(c_wankelStreamEncoder, "number", wankelStreamEncoder_number, 1);
263
+ rb_define_method(c_wankelStreamEncoder, "string", wankelStreamEncoder_string, 1);
264
+ rb_define_method(c_wankelStreamEncoder, "null", wankelStreamEncoder_null, 0);
265
+ rb_define_method(c_wankelStreamEncoder, "boolean", wankelStreamEncoder_boolean, 1);
266
+ rb_define_method(c_wankelStreamEncoder, "map_open", wankelStreamEncoder_map_open, 0);
267
+ rb_define_method(c_wankelStreamEncoder, "map_close", wankelStreamEncoder_map_close, 0);
268
+ rb_define_method(c_wankelStreamEncoder, "array_open", wankelStreamEncoder_array_open, 0);
269
+ rb_define_method(c_wankelStreamEncoder, "array_close", wankelStreamEncoder_array_close, 0);
270
+ rb_define_method(c_wankelStreamEncoder, "flush", wankelStreamEncoder_flush, 0);
271
+ rb_define_method(c_wankelStreamEncoder, "output=", wankelStreamEncoder_change_io, 1);
272
272
 
273
273
 
274
274
  intern_to_s = rb_intern("to_s");
@@ -285,22 +285,22 @@ void Init_wankel_sax_encoder() {
285
285
  }
286
286
 
287
287
  // Ruby GC ===================================================================
288
- static VALUE wankel_sax_encoder_alloc(VALUE klass) {
288
+ static VALUE wankel_stream_encoder_alloc(VALUE klass) {
289
289
  VALUE self;
290
290
  wankel_encoder * p;
291
- self = Data_Make_Struct(klass, wankel_encoder, wankel_sax_encoder_mark, wankel_sax_encoder_free, p);
291
+ self = Data_Make_Struct(klass, wankel_encoder, wankel_stream_encoder_mark, wankel_stream_encoder_free, p);
292
292
  p->g = 0;
293
293
  return self;
294
294
  }
295
295
 
296
- static void wankel_sax_encoder_free(void * handle) {
296
+ static void wankel_stream_encoder_free(void * handle) {
297
297
  wankel_encoder * p = handle;
298
298
  if (p->g){
299
299
  yajl_gen_free(p->g);
300
300
  }
301
301
  }
302
302
 
303
- static void wankel_sax_encoder_mark(void * handle) {
303
+ static void wankel_stream_encoder_mark(void * handle) {
304
304
  wankel_encoder * p = handle;
305
305
  rb_gc_mark(p->output);
306
306
  }
@@ -1,5 +1,5 @@
1
- #ifndef WANKEL_SAX_ENCODER
2
- #define WANKEL_SAX_ENCODER
1
+ #ifndef WANKEL_STREAM_ENCODER
2
+ #define WANKEL_STREAM_ENCODER
3
3
 
4
4
  #include <ruby.h>
5
5
  #include <ruby/encoding.h>
@@ -8,6 +8,6 @@
8
8
 
9
9
  #include "yajl_helpers.h"
10
10
 
11
- void Init_wankel_sax_encoder();
11
+ void Init_wankel_stream_encoder();
12
12
 
13
13
  #endif
@@ -1,6 +1,6 @@
1
- #include "wankel_sax_parser.h"
1
+ #include "wankel_stream_parser.h"
2
2
 
3
- static VALUE sax_parser_initialize(int argc, VALUE * argv, VALUE self);
3
+ static VALUE stream_parser_initialize(int argc, VALUE * argv, VALUE self);
4
4
 
5
5
  static ID sym_read_buffer_size, sym_symbolize_keys;
6
6
 
@@ -10,30 +10,30 @@ static ID intern_on_null, intern_on_boolean, intern_on_integer,
10
10
  intern_on_double, intern_on_string, intern_on_map_start, intern_on_map_key,
11
11
  intern_on_map_end, intern_on_array_start, intern_on_array_end;
12
12
 
13
- static VALUE c_wankel, c_wankelParser, c_saxParser, e_parseError, e_encodeError;
13
+ static VALUE c_wankel, c_wankelParser, c_streamParser, e_parseError, e_encodeError;
14
14
 
15
15
  // Callbacks =================================================================
16
- yajl_callbacks sax_parser_callbacks(VALUE self);
17
- int sax_parser_callback_on_null(void *ctx);
18
- int sax_parser_callback_on_boolean(void *ctx, int boolVal);
19
- int sax_parser_callback_on_number(void *ctx, const char * numberVal, size_t numberLen);
20
- int sax_parser_callback_on_string(void *ctx, const unsigned char * stringVal, size_t stringLen);
21
- int sax_parser_callback_on_map_start(void *ctx);
22
- int sax_parser_callback_on_map_key(void *ctx, const unsigned char * key, size_t keyLen);
23
- int sax_parser_callback_on_map_end(void *ctx);
24
- int sax_parser_callback_on_array_start(void *ctx);
25
- int sax_parser_callback_on_array_end(void *ctx);
16
+ yajl_callbacks stream_parser_callbacks(VALUE self);
17
+ int stream_parser_callback_on_null(void *ctx);
18
+ int stream_parser_callback_on_boolean(void *ctx, int boolVal);
19
+ int stream_parser_callback_on_number(void *ctx, const char * numberVal, size_t numberLen);
20
+ int stream_parser_callback_on_string(void *ctx, const unsigned char * stringVal, size_t stringLen);
21
+ int stream_parser_callback_on_map_start(void *ctx);
22
+ int stream_parser_callback_on_map_key(void *ctx, const unsigned char * key, size_t keyLen);
23
+ int stream_parser_callback_on_map_end(void *ctx);
24
+ int stream_parser_callback_on_array_start(void *ctx);
25
+ int stream_parser_callback_on_array_end(void *ctx);
26
26
 
27
27
  // Ruby GC ===================================================================
28
- VALUE sax_parser_alloc(VALUE);
29
- //void sax_parser_mark(void *);
30
- void sax_parser_free(void * parser);
28
+ VALUE stream_parser_alloc(VALUE);
29
+ //void stream_parser_mark(void *);
30
+ void stream_parser_free(void * parser);
31
31
 
32
- VALUE sax_parser_initialize(int argc, VALUE * argv, VALUE self) {
32
+ VALUE stream_parser_initialize(int argc, VALUE * argv, VALUE self) {
33
33
  VALUE defaults = rb_const_get(c_wankel, intern_DEFAULTS);
34
34
  VALUE klass = rb_funcall(self, rb_intern("class"), 0);
35
35
  VALUE options, rbufsize;
36
- sax_parser * p;
36
+ stream_parser * p;
37
37
 
38
38
  rb_scan_args(argc, argv, "01", &options);
39
39
  if (rb_const_defined(klass, intern_DEFAULTS)) {
@@ -47,8 +47,8 @@ VALUE sax_parser_initialize(int argc, VALUE * argv, VALUE self) {
47
47
  }
48
48
  options = rb_iv_get(self, "@options");
49
49
 
50
- Data_Get_Struct(self, sax_parser, p);
51
- p->callbacks = sax_parser_callbacks(self);
50
+ Data_Get_Struct(self, stream_parser, p);
51
+ p->callbacks = stream_parser_callbacks(self);
52
52
  p->alloc_funcs.malloc = yajl_helper_malloc;
53
53
  p->alloc_funcs.realloc = yajl_helper_realloc;
54
54
  p->alloc_funcs.free = yajl_helper_free;
@@ -69,13 +69,13 @@ VALUE sax_parser_initialize(int argc, VALUE * argv, VALUE self) {
69
69
  return self;
70
70
  }
71
71
 
72
- static VALUE sax_parser_parse(int argc, VALUE * argv, VALUE self) {
72
+ static VALUE stream_parser_parse(int argc, VALUE * argv, VALUE self) {
73
73
  const char * cptr;
74
74
  size_t len;
75
75
  yajl_status status;
76
- sax_parser * p;
76
+ stream_parser * p;
77
77
  VALUE input;
78
- Data_Get_Struct(self, sax_parser, p);
78
+ Data_Get_Struct(self, stream_parser, p);
79
79
 
80
80
  rb_scan_args(argc, argv, "10", &input);
81
81
  if (TYPE(input) == T_STRING) {
@@ -101,12 +101,12 @@ static VALUE sax_parser_parse(int argc, VALUE * argv, VALUE self) {
101
101
  return Qnil;
102
102
  }
103
103
 
104
- static VALUE sax_parser_write(VALUE self, VALUE input) {
104
+ static VALUE stream_parser_write(VALUE self, VALUE input) {
105
105
  const char * cptr;
106
106
  size_t len;
107
107
  yajl_status status;
108
- sax_parser * p;
109
- Data_Get_Struct(self, sax_parser, p);
108
+ stream_parser * p;
109
+ Data_Get_Struct(self, stream_parser, p);
110
110
 
111
111
  Check_Type(input, T_STRING);
112
112
  cptr = RSTRING_PTR(input);
@@ -117,10 +117,10 @@ static VALUE sax_parser_write(VALUE self, VALUE input) {
117
117
  return Qnil;
118
118
  }
119
119
 
120
- static VALUE sax_parser_complete(VALUE self) {
120
+ static VALUE stream_parser_complete(VALUE self) {
121
121
  yajl_status status;
122
- sax_parser * p;
123
- Data_Get_Struct(self, sax_parser, p);
122
+ stream_parser * p;
123
+ Data_Get_Struct(self, stream_parser, p);
124
124
 
125
125
 
126
126
  status = yajl_complete_parse(p->h);
@@ -129,20 +129,20 @@ static VALUE sax_parser_complete(VALUE self) {
129
129
  return Qnil;
130
130
  }
131
131
 
132
- void Init_wankel_sax_parser() {
132
+ void Init_wankel_stream_parser() {
133
133
  c_wankel = rb_const_get(rb_cObject, rb_intern("Wankel"));
134
134
  c_wankelParser = rb_const_get(c_wankel, rb_intern("Parser"));
135
- c_saxParser = rb_define_class_under(c_wankel, "SaxParser", rb_cObject);
135
+ c_streamParser = rb_define_class_under(c_wankel, "StreamParser", rb_cObject);
136
136
  e_parseError = rb_const_get(c_wankel, rb_intern("ParseError"));
137
137
  e_encodeError = rb_const_get(c_wankel, rb_intern("EncodeError"));
138
138
 
139
- rb_define_alloc_func(c_saxParser, sax_parser_alloc);
140
- rb_define_method(c_saxParser, "initialize", sax_parser_initialize, -1);
141
- rb_define_method(c_saxParser, "parse", sax_parser_parse, -1);
142
- rb_define_method(c_saxParser, "write", sax_parser_write, 1);
143
- rb_define_method(c_saxParser, "complete", sax_parser_complete, 0);
139
+ rb_define_alloc_func(c_streamParser, stream_parser_alloc);
140
+ rb_define_method(c_streamParser, "initialize", stream_parser_initialize, -1);
141
+ rb_define_method(c_streamParser, "parse", stream_parser_parse, -1);
142
+ rb_define_method(c_streamParser, "write", stream_parser_write, 1);
143
+ rb_define_method(c_streamParser, "complete", stream_parser_complete, 0);
144
144
 
145
- rb_define_alias(c_saxParser, "<<", "write");
145
+ rb_define_alias(c_streamParser, "<<", "write");
146
146
 
147
147
  intern_merge = rb_intern("merge");
148
148
  intern_clone = rb_intern("clone");
@@ -164,52 +164,52 @@ void Init_wankel_sax_parser() {
164
164
  }
165
165
 
166
166
  // Callbacks =================================================================
167
- yajl_callbacks sax_parser_callbacks(VALUE self) {
167
+ yajl_callbacks stream_parser_callbacks(VALUE self) {
168
168
  yajl_callbacks callbacks = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
169
169
 
170
170
  if(rb_respond_to(self, intern_on_null)) {
171
- callbacks.yajl_null = sax_parser_callback_on_null;
171
+ callbacks.yajl_null = stream_parser_callback_on_null;
172
172
  }
173
173
  if(rb_respond_to(self, intern_on_boolean)) {
174
- callbacks.yajl_boolean = sax_parser_callback_on_boolean;
174
+ callbacks.yajl_boolean = stream_parser_callback_on_boolean;
175
175
  }
176
176
  if(rb_respond_to(self, intern_on_integer) || rb_respond_to(self, intern_on_double)) {
177
- callbacks.yajl_number = sax_parser_callback_on_number;
177
+ callbacks.yajl_number = stream_parser_callback_on_number;
178
178
  }
179
179
  if(rb_respond_to(self, intern_on_string)) {
180
- callbacks.yajl_string = sax_parser_callback_on_string;
180
+ callbacks.yajl_string = stream_parser_callback_on_string;
181
181
  }
182
182
 
183
183
  if(rb_respond_to(self, intern_on_map_start)) {
184
- callbacks.yajl_start_map = sax_parser_callback_on_map_start;
184
+ callbacks.yajl_start_map = stream_parser_callback_on_map_start;
185
185
  }
186
186
  if(rb_respond_to(self, intern_on_map_key)) {
187
- callbacks.yajl_map_key = sax_parser_callback_on_map_key;
187
+ callbacks.yajl_map_key = stream_parser_callback_on_map_key;
188
188
  }
189
189
  if(rb_respond_to(self, intern_on_map_end)) {
190
- callbacks.yajl_end_map = sax_parser_callback_on_map_end;
190
+ callbacks.yajl_end_map = stream_parser_callback_on_map_end;
191
191
  }
192
192
  if(rb_respond_to(self, intern_on_array_start)) {
193
- callbacks.yajl_start_array = sax_parser_callback_on_array_start;
193
+ callbacks.yajl_start_array = stream_parser_callback_on_array_start;
194
194
  }
195
195
  if(rb_respond_to(self, intern_on_array_end)) {
196
- callbacks.yajl_end_array = sax_parser_callback_on_array_end;
196
+ callbacks.yajl_end_array = stream_parser_callback_on_array_end;
197
197
  }
198
198
 
199
199
  return callbacks;
200
200
  }
201
201
 
202
- int sax_parser_callback_on_null(void *ctx) {
202
+ int stream_parser_callback_on_null(void *ctx) {
203
203
  rb_funcall((VALUE)ctx, intern_on_null, 0);
204
204
  return 1;
205
205
  }
206
206
 
207
- int sax_parser_callback_on_boolean(void *ctx, int boolVal) {
207
+ int stream_parser_callback_on_boolean(void *ctx, int boolVal) {
208
208
  rb_funcall((VALUE)ctx, intern_on_boolean, 1, (boolVal ? Qtrue : Qfalse));
209
209
  return 1;
210
210
  }
211
211
 
212
- int sax_parser_callback_on_number(void *ctx, const char * numberVal, size_t numberLen) {
212
+ int stream_parser_callback_on_number(void *ctx, const char * numberVal, size_t numberLen) {
213
213
  char buf[numberLen+1];
214
214
  buf[numberLen] = 0;
215
215
  memcpy(buf, numberVal, numberLen);
@@ -227,38 +227,38 @@ int sax_parser_callback_on_number(void *ctx, const char * numberVal, size_t numb
227
227
  return 1;
228
228
  }
229
229
 
230
- int sax_parser_callback_on_string(void *ctx, const unsigned char * stringVal, size_t stringLen) {
230
+ int stream_parser_callback_on_string(void *ctx, const unsigned char * stringVal, size_t stringLen) {
231
231
  rb_funcall((VALUE)ctx, intern_on_string, 1, rb_str_new((const char *) stringVal, stringLen));
232
232
  return 1;
233
233
  }
234
- int sax_parser_callback_on_map_start(void *ctx) {
234
+ int stream_parser_callback_on_map_start(void *ctx) {
235
235
  rb_funcall((VALUE)ctx, intern_on_map_start, 0);
236
236
  return 1;
237
237
  }
238
- int sax_parser_callback_on_map_key(void *ctx, const unsigned char * key, size_t keyLen) {
238
+ int stream_parser_callback_on_map_key(void *ctx, const unsigned char * key, size_t keyLen) {
239
239
  rb_funcall((VALUE)ctx, intern_on_map_key, 1, rb_str_new((const char *)key, keyLen));
240
240
  return 1;
241
241
  }
242
- int sax_parser_callback_on_map_end(void *ctx) {
242
+ int stream_parser_callback_on_map_end(void *ctx) {
243
243
  rb_funcall((VALUE)ctx, intern_on_map_end, 0);
244
244
  return 1;
245
245
  }
246
- int sax_parser_callback_on_array_start(void *ctx) {
246
+ int stream_parser_callback_on_array_start(void *ctx) {
247
247
  rb_funcall((VALUE)ctx, intern_on_array_start, 0);
248
248
  return 1;
249
249
  }
250
- int sax_parser_callback_on_array_end(void *ctx) {
250
+ int stream_parser_callback_on_array_end(void *ctx) {
251
251
  rb_funcall((VALUE)ctx, intern_on_array_end, 0);
252
252
  return 1;
253
253
  }
254
254
 
255
255
  // Ruby GC ===================================================================
256
- VALUE sax_parser_alloc(VALUE klass) {
257
- sax_parser * p;
258
- return Data_Make_Struct(klass, sax_parser, 0, sax_parser_free, p);
256
+ VALUE stream_parser_alloc(VALUE klass) {
257
+ stream_parser * p;
258
+ return Data_Make_Struct(klass, stream_parser, 0, stream_parser_free, p);
259
259
  }
260
260
 
261
- void sax_parser_free(void * handle) {
262
- sax_parser * p = handle;
261
+ void stream_parser_free(void * handle) {
262
+ stream_parser * p = handle;
263
263
  yajl_free(p->h);
264
264
  }
@@ -1,5 +1,5 @@
1
- #ifndef WANKEL_SAX_PARSER
2
- #define WANKEL_SAX_PARSER
1
+ #ifndef WANKEL_STREAM_PARSER
2
+ #define WANKEL_STREAM_PARSER
3
3
 
4
4
  #include <ruby.h>
5
5
  #include <ruby/encoding.h>
@@ -9,7 +9,7 @@
9
9
  #include "wankel.h"
10
10
  #include "yajl_helpers.h"
11
11
 
12
- void Init_wankel_sax_parser();
12
+ void Init_wankel_stream_parser();
13
13
 
14
14
  typedef struct {
15
15
  yajl_handle h;
@@ -17,7 +17,7 @@ typedef struct {
17
17
  yajl_alloc_funcs alloc_funcs;
18
18
  int symbolize_keys;
19
19
  VALUE rbufsize;
20
- } sax_parser;
20
+ } stream_parser;
21
21
 
22
22
 
23
23
  #endif
@@ -18,7 +18,7 @@ class Wankel
18
18
  }
19
19
  end
20
20
 
21
- class Wankel::SaxEncoder
21
+ class Wankel::StreamEncoder
22
22
 
23
23
  def value(val)
24
24
  case val
@@ -1,11 +1,11 @@
1
1
  require 'test_helper'
2
2
  require 'stringio'
3
3
 
4
- class Wankel::SaxEncoderTest < Minitest::Test
4
+ class Wankel::StreamEncoderTest < Minitest::Test
5
5
 
6
6
  def setup
7
7
  @output = StringIO.new
8
- @encoder = Wankel::SaxEncoder.new(@output)
8
+ @encoder = Wankel::StreamEncoder.new(@output)
9
9
  end
10
10
 
11
11
  def assert_output(value)
@@ -13,12 +13,12 @@ class Wankel::SaxEncoderTest < Minitest::Test
13
13
  end
14
14
 
15
15
  test 'default inherited from Wankel' do
16
- encoder = Wankel::SaxEncoder.new(StringIO.new)
16
+ encoder = Wankel::StreamEncoder.new(StringIO.new)
17
17
  assert_equal(Wankel::DEFAULTS, encoder.instance_variable_get("@options"))
18
18
  end
19
19
 
20
20
  test 'default options merged with options inherited from Wankel && Class' do
21
- encoder = Wankel::SaxEncoder.new(StringIO.new, :hello => true, :metoo => false)
21
+ encoder = Wankel::StreamEncoder.new(StringIO.new, :hello => true, :metoo => false)
22
22
  assert_equal(Wankel::DEFAULTS.merge({:hello => true, :metoo => false}), encoder.instance_variable_get("@options"))
23
23
  end
24
24
 
@@ -146,7 +146,7 @@ class Wankel::SaxEncoderTest < Minitest::Test
146
146
  output = StringIO.new
147
147
 
148
148
  # Set large write_buffer_size to test flush
149
- encoder = Wankel::SaxEncoder.new(output, :write_buffer_size => 1_000_000)
149
+ encoder = Wankel::StreamEncoder.new(output, :write_buffer_size => 1_000_000)
150
150
  encoder.value({key: "value"})
151
151
 
152
152
  assert_equal("", output.string)
@@ -159,7 +159,7 @@ class Wankel::SaxEncoderTest < Minitest::Test
159
159
  output2 = StringIO.new
160
160
 
161
161
  # Set large write_buffer_size to test flush
162
- encoder = Wankel::SaxEncoder.new(output1, :write_buffer_size => 1_000_000)
162
+ encoder = Wankel::StreamEncoder.new(output1, :write_buffer_size => 1_000_000)
163
163
  encoder.map_open
164
164
  encoder.string("key")
165
165
  encoder.string("value")
@@ -1,7 +1,7 @@
1
1
  # encoding: UTF-8
2
2
  require 'test_helper'
3
3
 
4
- class TestParser < Wankel::SaxParser
4
+ class TestParser < Wankel::StreamParser
5
5
  def on_map_start
6
6
  end
7
7
  def on_map_end
@@ -24,7 +24,7 @@ class TestParser < Wankel::SaxParser
24
24
  end
25
25
  end
26
26
 
27
- class Wankel::SaxParserTest < Minitest::Test
27
+ class Wankel::StreamParserTest < Minitest::Test
28
28
 
29
29
  test 'default inherited from Wankel' do
30
30
  parser = TestParser.new
@@ -32,7 +32,7 @@ class Wankel::SaxParserTest < Minitest::Test
32
32
  end
33
33
 
34
34
  test 'default inherited from Wankel && Class' do
35
- class TestParser2 < Wankel::SaxParser
35
+ class TestParser2 < Wankel::StreamParser
36
36
  DEFAULTS = {:hello => true}
37
37
  end
38
38
 
@@ -41,7 +41,7 @@ class Wankel::SaxParserTest < Minitest::Test
41
41
  end
42
42
 
43
43
  test 'default options merged with options inherited from Wankel && Class' do
44
- class TestParser3 < Wankel::SaxParser
44
+ class TestParser3 < Wankel::StreamParser
45
45
  DEFAULTS = {:hello => true}
46
46
  end
47
47
 
@@ -1,11 +1,11 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'wankel'
3
- s.version = '0.4.0'
3
+ s.version = '0.5.0'
4
4
  s.licenses = ['MIT']
5
5
  s.authors = ['Jon Bracy']
6
6
  s.email = ['jonbracy@gmail.com']
7
7
  s.homepage = 'http://wankelrb.com'
8
- s.summary = 'SAX based JSON parser and encoder'
8
+ s.summary = 'Streaming JSON parser and encoder'
9
9
  s.description = 'A JSON parser that enables streaming parsing and encoding of JSON'
10
10
 
11
11
  s.files = `git ls-files`.split("\n")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wankel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Bracy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-23 00:00:00.000000000 Z
11
+ date: 2014-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -93,10 +93,10 @@ files:
93
93
  - ext/wankel/wankel_encoder.h
94
94
  - ext/wankel/wankel_parser.c
95
95
  - ext/wankel/wankel_parser.h
96
- - ext/wankel/wankel_sax_encoder.c
97
- - ext/wankel/wankel_sax_encoder.h
98
- - ext/wankel/wankel_sax_parser.c
99
- - ext/wankel/wankel_sax_parser.h
96
+ - ext/wankel/wankel_stream_encoder.c
97
+ - ext/wankel/wankel_stream_encoder.h
98
+ - ext/wankel/wankel_stream_parser.c
99
+ - ext/wankel/wankel_stream_parser.h
100
100
  - ext/wankel/yajl_helpers.c
101
101
  - ext/wankel/yajl_helpers.h
102
102
  - lib/wankel.rb
@@ -192,7 +192,7 @@ rubyforge_project:
192
192
  rubygems_version: 2.2.2
193
193
  signing_key:
194
194
  specification_version: 4
195
- summary: SAX based JSON parser and encoder
195
+ summary: Streaming JSON parser and encoder
196
196
  test_files:
197
197
  - test/encoding/encoding_test.rb
198
198
  - test/encoding/sax_encoder_test.rb