slow_blink 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/slow_blink/ext_schema_parser/lexer.c +2793 -839
- data/ext/slow_blink/ext_schema_parser/lexer.h +14 -137
- data/ext/slow_blink/ext_schema_parser/parser.c +616 -670
- data/ext/slow_blink/ext_schema_parser/parser.h +6 -4
- data/ext/slow_blink/message/ext_compact_encoder/blink_compact.c +642 -0
- data/ext/slow_blink/message/ext_compact_encoder/blink_compact.h +411 -0
- data/ext/slow_blink/message/ext_compact_encoder/blink_debug.h +46 -0
- data/ext/slow_blink/message/ext_compact_encoder/blink_stream.c +314 -0
- data/ext/slow_blink/message/ext_compact_encoder/blink_stream.h +185 -0
- data/ext/slow_blink/message/ext_compact_encoder/ext_compact_encoder.c +382 -269
- data/lib/slow_blink/definition.rb +18 -53
- data/lib/slow_blink/dynamic_group.rb +8 -0
- data/lib/slow_blink/enum.rb +101 -0
- data/lib/slow_blink/field.rb +63 -33
- data/lib/slow_blink/generate_c/model.rb +89 -0
- data/lib/slow_blink/group.rb +119 -100
- data/lib/slow_blink/message/binary.rb +3 -4
- data/lib/slow_blink/message/boolean.rb +3 -4
- data/lib/slow_blink/message/date.rb +3 -4
- data/lib/slow_blink/message/decimal.rb +3 -5
- data/lib/slow_blink/message/{enumeration.rb → enum.rb} +17 -17
- data/lib/slow_blink/message/field.rb +77 -27
- data/lib/slow_blink/message/fixed.rb +5 -21
- data/lib/slow_blink/message/floating_point.rb +3 -4
- data/lib/slow_blink/message/group.rb +90 -161
- data/lib/slow_blink/message/integer.rb +24 -32
- data/lib/slow_blink/message/model.rb +50 -110
- data/lib/slow_blink/message/string.rb +3 -4
- data/lib/slow_blink/message/time.rb +5 -5
- data/lib/slow_blink/message/time_of_day.rb +5 -12
- data/lib/slow_blink/ref.rb +22 -71
- data/lib/slow_blink/schema.rb +64 -85
- data/lib/slow_blink/schema_buffer.rb +1 -4
- data/lib/slow_blink/static_group.rb +37 -0
- data/lib/slow_blink/string.rb +4 -5
- data/lib/slow_blink/sym.rb +8 -28
- data/lib/slow_blink/type.rb +10 -19
- data/lib/slow_blink/version.rb +1 -1
- data/lib/slow_blink.rb +1 -0
- data/test/tc_compact_encoder.rb +114 -147
- data/test/tc_inputs.rb +2 -4
- data/test/tc_model_string.rb +29 -0
- data/test/tc_schema_new.rb +212 -0
- metadata +17 -26
- data/ext/slow_blink/ext_schema_parser/common.h +0 -27
- data/ext/slow_blink/message/ext_compact_encoder/compact_encoder.c +0 -258
- data/ext/slow_blink/message/ext_compact_encoder/compact_encoder.h +0 -92
- data/lib/slow_blink/annotatable.rb +0 -48
- data/lib/slow_blink/annotation.rb +0 -47
- data/lib/slow_blink/enumeration.rb +0 -90
- data/lib/slow_blink/incremental_annotation.rb +0 -151
- data/lib/slow_blink/log.rb +0 -51
- data/lib/slow_blink/message/sequence.rb +0 -98
- data/lib/slow_blink/name_with_id.rb +0 -49
- data/lib/slow_blink/namespace.rb +0 -143
- data/lib/slow_blink/sequence.rb +0 -57
- data/test/tc_field.rb +0 -94
- data/test/tc_group.rb +0 -114
- data/test/tc_incr_annote.rb +0 -22
- data/test/tc_namespace.rb +0 -8
- data/test/tc_types.rb +0 -218
@@ -25,31 +25,19 @@
|
|
25
25
|
#include <ruby.h>
|
26
26
|
#include <stdint.h>
|
27
27
|
#include <stdbool.h>
|
28
|
+
#include <stddef.h>
|
28
29
|
#include <assert.h>
|
29
30
|
|
30
|
-
#include "
|
31
|
+
#include "blink_compact.h"
|
32
|
+
#include "blink_stream.h"
|
31
33
|
|
32
34
|
/* defines ************************************************************/
|
33
35
|
|
34
|
-
|
35
|
-
#define MIN8 -128L
|
36
|
-
#define MAX8 127L
|
37
|
-
#define MIN16 -32768L
|
38
|
-
#define MAX16 32767L
|
39
|
-
#define MIN32 -2147483648L
|
40
|
-
#define MAX32 2147483647L
|
41
|
-
#define MIN64 -9223372036854775808L
|
42
|
-
#define MAX64 9223372036854775807L
|
43
|
-
#define MAXU8 0xffUL
|
44
|
-
#define MAXU16 0xffffUL
|
45
|
-
#define MAXU32 0xffffffffUL
|
46
|
-
#define MAXU64 0xffffffffffffffffUL
|
47
|
-
|
48
36
|
/* static function prototypes *****************************************/
|
49
37
|
|
50
38
|
static VALUE putNull(VALUE self);
|
51
39
|
|
52
|
-
static VALUE putPresent(VALUE self
|
40
|
+
static VALUE putPresent(VALUE self);
|
53
41
|
static VALUE getPresent(VALUE self);
|
54
42
|
|
55
43
|
static VALUE putU8(VALUE self, VALUE val);
|
@@ -66,7 +54,6 @@ static VALUE putBool(VALUE self, VALUE val);
|
|
66
54
|
static VALUE putBinary(VALUE self, VALUE val);
|
67
55
|
static VALUE putString(VALUE self, VALUE val);
|
68
56
|
static VALUE putFixed(VALUE self, VALUE val);
|
69
|
-
static VALUE putFixedOptional(VALUE self, VALUE val);
|
70
57
|
|
71
58
|
static VALUE getU8(VALUE self);
|
72
59
|
static VALUE getU16(VALUE self);
|
@@ -82,10 +69,9 @@ static VALUE getBool(VALUE self);
|
|
82
69
|
static VALUE getBinary(VALUE self);
|
83
70
|
static VALUE getString(VALUE self);
|
84
71
|
static VALUE getFixed(VALUE self, VALUE size);
|
85
|
-
static VALUE getFixedOptional(VALUE self, VALUE size);
|
86
72
|
|
87
|
-
static
|
88
|
-
static
|
73
|
+
static bool myRead(void *state, void *buf, size_t nbyte);
|
74
|
+
static bool myWrite(void *state, const void *buf, size_t nbyte);
|
89
75
|
|
90
76
|
/* static variables ***************************************************/
|
91
77
|
|
@@ -96,7 +82,10 @@ static VALUE cWeakError4;
|
|
96
82
|
static VALUE cWeakError9;
|
97
83
|
static VALUE cWeakError11;
|
98
84
|
|
99
|
-
|
85
|
+
static struct blink_stream_user cUserStream = {
|
86
|
+
.read = myRead,
|
87
|
+
.write = myWrite
|
88
|
+
};
|
100
89
|
|
101
90
|
/* functions **********************************************************/
|
102
91
|
|
@@ -104,9 +93,11 @@ void Init_ext_compact_encoder(void)
|
|
104
93
|
{
|
105
94
|
VALUE cSlowBlink;
|
106
95
|
VALUE cMessage;
|
96
|
+
VALUE cStringIO;
|
107
97
|
|
108
98
|
cSlowBlink = rb_define_module("SlowBlink");
|
109
99
|
cMessage = rb_const_get(cSlowBlink, rb_intern("Message"));
|
100
|
+
cStringIO = rb_const_get(rb_cObject, rb_intern("StringIO"));
|
110
101
|
|
111
102
|
cStrongError1 = rb_const_get(cMessage, rb_intern("StrongError1"));
|
112
103
|
|
@@ -117,7 +108,7 @@ void Init_ext_compact_encoder(void)
|
|
117
108
|
|
118
109
|
rb_define_method(rb_cString, "putNull", putNull, 0);
|
119
110
|
rb_define_method(rb_cString, "putPresent", putPresent, 0);
|
120
|
-
rb_define_method(
|
111
|
+
rb_define_method(cStringIO, "getPresent", getPresent, 0);
|
121
112
|
|
122
113
|
rb_define_method(rb_cString, "putU8", putU8, 1);
|
123
114
|
rb_define_method(rb_cString, "putU16", putU16, 1);
|
@@ -135,121 +126,270 @@ void Init_ext_compact_encoder(void)
|
|
135
126
|
rb_define_method(rb_cString, "putString", putString, 1);
|
136
127
|
rb_define_method(rb_cString, "putBinary", putBinary, 1);
|
137
128
|
rb_define_method(rb_cString, "putFixed", putFixed, 1);
|
138
|
-
rb_define_method(rb_cString, "putFixedOptional", putFixedOptional, 1);
|
139
129
|
|
140
|
-
rb_define_method(
|
141
|
-
rb_define_method(
|
142
|
-
rb_define_method(
|
143
|
-
rb_define_method(
|
144
|
-
rb_define_method(
|
145
|
-
rb_define_method(
|
146
|
-
rb_define_method(
|
147
|
-
rb_define_method(
|
130
|
+
rb_define_method(cStringIO, "getU8", getU8, 0);
|
131
|
+
rb_define_method(cStringIO, "getU16", getU16, 0);
|
132
|
+
rb_define_method(cStringIO, "getU32", getU32, 0);
|
133
|
+
rb_define_method(cStringIO, "getU64", getU64, 0);
|
134
|
+
rb_define_method(cStringIO, "getI8", getI8, 0);
|
135
|
+
rb_define_method(cStringIO, "getI16", getI16, 0);
|
136
|
+
rb_define_method(cStringIO, "getI32", getI32, 0);
|
137
|
+
rb_define_method(cStringIO, "getI64", getI64, 0);
|
148
138
|
|
149
|
-
rb_define_method(
|
139
|
+
rb_define_method(cStringIO, "getF64", getF64, 0);
|
150
140
|
|
151
|
-
rb_define_method(
|
141
|
+
rb_define_method(cStringIO, "getBool", getBool, 0);
|
152
142
|
|
153
|
-
rb_define_method(
|
154
|
-
rb_define_method(
|
155
|
-
rb_define_method(
|
156
|
-
rb_define_method(rb_cString, "getFixedOptional!", getFixedOptional, 1);
|
143
|
+
rb_define_method(cStringIO, "getString", getString, 0);
|
144
|
+
rb_define_method(cStringIO, "getBinary", getBinary, 0);
|
145
|
+
rb_define_method(cStringIO, "getFixed", getFixed, 1);
|
157
146
|
}
|
158
147
|
|
159
148
|
/* static functions ***************************************************/
|
160
149
|
|
150
|
+
static bool myRead(void *state, void *buf, size_t nbyte)
|
151
|
+
{
|
152
|
+
bool retval = false;
|
153
|
+
VALUE stringIO = *(VALUE *)state;
|
154
|
+
|
155
|
+
VALUE out = rb_funcall(stringIO, rb_intern("read"), 1, SIZET2NUM(nbyte));
|
156
|
+
|
157
|
+
if((size_t)RSTRING_LEN(out) == nbyte){
|
158
|
+
|
159
|
+
(void)memcpy(buf, RSTRING_PTR(out), (size_t)RSTRING_LEN(out));
|
160
|
+
retval = true;
|
161
|
+
}
|
162
|
+
else{
|
163
|
+
|
164
|
+
rb_raise(cStrongError1, "S1: Group encoding ends prematurely");
|
165
|
+
}
|
166
|
+
|
167
|
+
return retval;
|
168
|
+
}
|
169
|
+
|
170
|
+
static bool myWrite(void *state, const void *buf, size_t nbyte)
|
171
|
+
{
|
172
|
+
return rb_str_buf_cat(*(VALUE *)state, buf, nbyte);
|
173
|
+
}
|
174
|
+
|
161
175
|
static VALUE putU8(VALUE self, VALUE val)
|
162
176
|
{
|
163
|
-
|
177
|
+
if(val == Qnil){
|
178
|
+
|
179
|
+
(void)putNull(self);
|
180
|
+
}
|
181
|
+
else{
|
182
|
+
if(NUM2ULL(val) <= UINT8_MAX){
|
183
|
+
|
184
|
+
struct blink_stream stream;
|
185
|
+
(void)BLINK_Stream_initUser(&stream, &self, cUserStream);
|
186
|
+
(void)BLINK_Compact_encodeU8((uint8_t)NUM2ULL(val), &stream);
|
187
|
+
}
|
188
|
+
else{
|
189
|
+
|
190
|
+
rb_raise(rb_eRangeError, "Input exceeds allowable range of type");
|
191
|
+
}
|
192
|
+
}
|
193
|
+
|
194
|
+
return self;
|
164
195
|
}
|
165
196
|
static VALUE putU16(VALUE self, VALUE val)
|
166
197
|
{
|
167
|
-
|
198
|
+
if(val == Qnil){
|
199
|
+
|
200
|
+
(void)putNull(self);
|
201
|
+
}
|
202
|
+
else{
|
203
|
+
if(NUM2ULL(val) <= UINT16_MAX){
|
204
|
+
|
205
|
+
struct blink_stream stream;
|
206
|
+
(void)BLINK_Stream_initUser(&stream, &self, cUserStream);
|
207
|
+
(void)BLINK_Compact_encodeU16((uint16_t)NUM2ULL(val), &stream);
|
208
|
+
}
|
209
|
+
else{
|
210
|
+
|
211
|
+
rb_raise(rb_eRangeError, "Input exceeds allowable range of type");
|
212
|
+
}
|
213
|
+
}
|
214
|
+
|
215
|
+
return self;
|
168
216
|
}
|
169
217
|
static VALUE putU32(VALUE self, VALUE val)
|
170
218
|
{
|
171
|
-
|
219
|
+
if(val == Qnil){
|
220
|
+
|
221
|
+
(void)putNull(self);
|
222
|
+
}
|
223
|
+
else{
|
224
|
+
if(NUM2ULL(val) <= UINT32_MAX){
|
225
|
+
|
226
|
+
struct blink_stream stream;
|
227
|
+
(void)BLINK_Stream_initUser(&stream, &self, cUserStream);
|
228
|
+
(void)BLINK_Compact_encodeU32((uint32_t)NUM2ULL(val), &stream);
|
229
|
+
}
|
230
|
+
else{
|
231
|
+
|
232
|
+
rb_raise(rb_eRangeError, "Input exceeds allowable range of type");
|
233
|
+
}
|
234
|
+
}
|
235
|
+
|
236
|
+
return self;
|
172
237
|
}
|
173
238
|
static VALUE putU64(VALUE self, VALUE val)
|
174
239
|
{
|
175
|
-
|
240
|
+
if(val == Qnil){
|
241
|
+
|
242
|
+
(void)putNull(self);
|
243
|
+
}
|
244
|
+
else{
|
245
|
+
if(NUM2ULL(val) <= UINT64_MAX){
|
246
|
+
|
247
|
+
struct blink_stream stream;
|
248
|
+
(void)BLINK_Stream_initUser(&stream, &self, cUserStream);
|
249
|
+
(void)BLINK_Compact_encodeU64(NUM2ULL(val), &stream);
|
250
|
+
}
|
251
|
+
else{
|
252
|
+
|
253
|
+
rb_raise(rb_eRangeError, "Input exceeds allowable range of type");
|
254
|
+
}
|
255
|
+
}
|
256
|
+
|
257
|
+
return self;
|
176
258
|
}
|
177
259
|
static VALUE putI8(VALUE self, VALUE val)
|
178
260
|
{
|
179
|
-
|
261
|
+
if(val == Qnil){
|
262
|
+
|
263
|
+
(void)putNull(self);
|
264
|
+
}
|
265
|
+
else{
|
266
|
+
if((NUM2LL(val) >= INT8_MIN) && (NUM2LL(val) <= INT8_MAX)){
|
267
|
+
|
268
|
+
struct blink_stream stream;
|
269
|
+
(void)BLINK_Stream_initUser(&stream, &self, cUserStream);
|
270
|
+
(void)BLINK_Compact_encodeI8((int8_t)NUM2LL(val), &stream);
|
271
|
+
}
|
272
|
+
else{
|
273
|
+
|
274
|
+
rb_raise(rb_eRangeError, "Input exceeds allowable range of type");
|
275
|
+
}
|
276
|
+
}
|
277
|
+
return self;
|
180
278
|
}
|
181
279
|
static VALUE putI16(VALUE self, VALUE val)
|
182
280
|
{
|
183
|
-
|
281
|
+
if(val == Qnil){
|
282
|
+
|
283
|
+
(void)putNull(self);
|
284
|
+
}
|
285
|
+
else{
|
286
|
+
|
287
|
+
if((NUM2LL(val) >= INT16_MIN) && (NUM2LL(val) <= INT16_MAX)){
|
288
|
+
|
289
|
+
struct blink_stream stream;
|
290
|
+
(void)BLINK_Stream_initUser(&stream, &self, cUserStream);
|
291
|
+
(void)BLINK_Compact_encodeI16((int16_t)NUM2LL(val), &stream);
|
292
|
+
}
|
293
|
+
else{
|
294
|
+
|
295
|
+
rb_raise(rb_eRangeError, "Input exceeds allowable range of type");
|
296
|
+
}
|
297
|
+
}
|
298
|
+
return self;
|
184
299
|
}
|
185
300
|
static VALUE putI32(VALUE self, VALUE val)
|
186
301
|
{
|
187
|
-
|
302
|
+
if(val == Qnil){
|
303
|
+
|
304
|
+
(void)putNull(self);
|
305
|
+
}
|
306
|
+
else{
|
307
|
+
|
308
|
+
if((NUM2LL(val) >= INT32_MIN) && (NUM2LL(val) <= INT32_MAX)){
|
309
|
+
|
310
|
+
struct blink_stream stream;
|
311
|
+
(void)BLINK_Stream_initUser(&stream, &self, cUserStream);
|
312
|
+
(void)BLINK_Compact_encodeI32((int32_t)NUM2LL(val), &stream);
|
313
|
+
}
|
314
|
+
else{
|
315
|
+
|
316
|
+
rb_raise(rb_eRangeError, "Input exceeds allowable range of type");
|
317
|
+
}
|
318
|
+
}
|
319
|
+
return self;
|
188
320
|
}
|
189
321
|
static VALUE putI64(VALUE self, VALUE val)
|
190
322
|
{
|
191
|
-
return putInt(self, val, MIN64, MAX64, true);
|
192
|
-
}
|
193
|
-
static VALUE putF64(VALUE self, VALUE val)
|
194
|
-
{
|
195
|
-
VALUE retval;
|
196
|
-
uint8_t out[10U];
|
197
|
-
|
198
323
|
if(val == Qnil){
|
199
324
|
|
200
|
-
|
325
|
+
(void)putNull(self);
|
201
326
|
}
|
202
327
|
else{
|
203
328
|
|
204
|
-
|
205
|
-
|
329
|
+
if((NUM2LL(val) >= INT64_MIN) && (NUM2LL(val) <= INT64_MAX)){
|
330
|
+
|
331
|
+
struct blink_stream stream;
|
332
|
+
(void)BLINK_Stream_initUser(&stream, &self, cUserStream);
|
333
|
+
(void)BLINK_Compact_encodeI64(NUM2LL(val), &stream);
|
334
|
+
}
|
335
|
+
else{
|
336
|
+
|
337
|
+
rb_raise(rb_eRangeError, "Input exceeds allowable range of type");
|
338
|
+
}
|
206
339
|
}
|
340
|
+
return self;
|
341
|
+
}
|
342
|
+
static VALUE putF64(VALUE self, VALUE val)
|
343
|
+
{
|
344
|
+
if(val == Qnil){
|
207
345
|
|
208
|
-
|
346
|
+
(void)putNull(self);
|
347
|
+
}
|
348
|
+
else{
|
349
|
+
|
350
|
+
struct blink_stream stream;
|
351
|
+
(void)BLINK_Stream_initUser(&stream, &self, cUserStream);
|
352
|
+
(void)BLINK_Compact_encodeF64(NUM2DBL(val), &stream);
|
353
|
+
}
|
354
|
+
return self;
|
209
355
|
}
|
210
356
|
|
211
357
|
static VALUE putBool(VALUE self, VALUE val)
|
212
358
|
{
|
213
|
-
VALUE retval;
|
214
|
-
|
215
359
|
if(val == Qnil){
|
216
360
|
|
217
|
-
|
361
|
+
(void)putNull(self);
|
218
362
|
}
|
219
363
|
else{
|
220
364
|
|
221
|
-
|
365
|
+
struct blink_stream stream;
|
366
|
+
(void)BLINK_Stream_initUser(&stream, &self, cUserStream);
|
367
|
+
(void)BLINK_Compact_encodeBool((val == Qfalse) ? false : true, &stream);
|
222
368
|
}
|
223
|
-
|
224
|
-
return retval;
|
369
|
+
return self;
|
225
370
|
}
|
226
371
|
|
227
372
|
static VALUE putNull(VALUE self)
|
228
373
|
{
|
229
|
-
|
230
|
-
|
374
|
+
struct blink_stream stream;
|
375
|
+
(void)BLINK_Stream_initUser(&stream, &self, cUserStream);
|
376
|
+
(void)BLINK_Compact_encodeNull(&stream);
|
377
|
+
return self;
|
231
378
|
}
|
232
379
|
|
233
|
-
static VALUE putPresent(VALUE self
|
380
|
+
static VALUE putPresent(VALUE self)
|
234
381
|
{
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
retval = putNull(self);
|
240
|
-
}
|
241
|
-
else{
|
242
|
-
|
243
|
-
uint8_t str[] = {0x1};
|
244
|
-
retval = rb_str_buf_cat(self, (const char *)str, sizeof(str));
|
245
|
-
}
|
246
|
-
|
247
|
-
return retval;
|
382
|
+
struct blink_stream stream;
|
383
|
+
(void)BLINK_Stream_initUser(&stream, &self, cUserStream);
|
384
|
+
(void)BLINK_Compact_encodePresent(&stream);
|
385
|
+
return self;
|
248
386
|
}
|
249
387
|
|
250
388
|
static VALUE putBinary(VALUE self, VALUE val)
|
251
|
-
{
|
252
|
-
VALUE retval;
|
389
|
+
{
|
390
|
+
VALUE retval = Qnil;
|
391
|
+
struct blink_stream stream;
|
392
|
+
(void)BLINK_Stream_initUser(&stream, &self, cUserStream);
|
253
393
|
|
254
394
|
if(val == Qnil){
|
255
395
|
|
@@ -257,11 +397,17 @@ static VALUE putBinary(VALUE self, VALUE val)
|
|
257
397
|
}
|
258
398
|
else{
|
259
399
|
|
260
|
-
|
261
|
-
|
400
|
+
if(RSTRING_LEN(val) <= UINT32_MAX){
|
401
|
+
|
402
|
+
(void)BLINK_Compact_encodeU32((uint32_t)RSTRING_LEN(val), &stream);
|
403
|
+
retval = rb_str_buf_cat(self, RSTRING_PTR(val), RSTRING_LEN(val));
|
404
|
+
}
|
405
|
+
else{
|
262
406
|
|
407
|
+
rb_raise(rb_eRangeError, "String is too long");
|
408
|
+
}
|
263
409
|
}
|
264
|
-
|
410
|
+
|
265
411
|
return retval;
|
266
412
|
}
|
267
413
|
|
@@ -271,300 +417,267 @@ static VALUE putString(VALUE self, VALUE val)
|
|
271
417
|
return putBinary(self, val);
|
272
418
|
}
|
273
419
|
|
274
|
-
static VALUE
|
420
|
+
static VALUE putFixed(VALUE self, VALUE val)
|
275
421
|
{
|
276
|
-
|
422
|
+
return rb_str_buf_cat(self, RSTRING_PTR(val), (size_t)RSTRING_LEN(val));
|
423
|
+
}
|
277
424
|
|
278
|
-
|
425
|
+
static VALUE getU8(VALUE self)
|
426
|
+
{
|
427
|
+
VALUE retval = Qnil;
|
428
|
+
uint8_t val;
|
429
|
+
bool isNull;
|
430
|
+
struct blink_stream stream;
|
431
|
+
(void)BLINK_Stream_initUser(&stream, &self, cUserStream);
|
432
|
+
if(BLINK_Compact_decodeU8(&stream, &val, &isNull)){
|
279
433
|
|
280
|
-
retval =
|
434
|
+
retval = (isNull) ? Qnil : UINT2NUM(val);
|
281
435
|
}
|
282
436
|
else{
|
283
437
|
|
284
|
-
|
285
|
-
retval = rb_str_new((const char *)str, sizeof(str));
|
286
|
-
rb_str_concat(retval, val);
|
438
|
+
rb_raise(rb_eRangeError, "out of range");
|
287
439
|
}
|
288
|
-
|
440
|
+
|
289
441
|
return retval;
|
290
442
|
}
|
291
443
|
|
292
|
-
static VALUE
|
293
|
-
{
|
294
|
-
return rb_str_dup(val);
|
295
|
-
}
|
296
|
-
|
297
|
-
static VALUE putInt(VALUE self, VALUE val, int64_t min, int64_t max, bool isSigned)
|
444
|
+
static VALUE getU16(VALUE self)
|
298
445
|
{
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
446
|
+
VALUE retval = Qnil;
|
447
|
+
uint16_t val;
|
448
|
+
bool isNull;
|
449
|
+
struct blink_stream stream;
|
450
|
+
(void)BLINK_Stream_initUser(&stream, &self, cUserStream);
|
451
|
+
if(BLINK_Compact_decodeU16(&stream, &val, &isNull)){
|
303
452
|
|
304
|
-
retval =
|
453
|
+
retval = (isNull) ? Qnil : UINT2NUM(val);
|
305
454
|
}
|
306
455
|
else{
|
307
456
|
|
308
|
-
|
309
|
-
|
310
|
-
int64_t value = NUM2LL(val);
|
311
|
-
|
312
|
-
if((value < min) || (value > max)){
|
313
|
-
|
314
|
-
rb_raise(rb_eRangeError, "Input exceeds allowable range of type");
|
315
|
-
}
|
316
|
-
|
317
|
-
retval = rb_str_buf_cat(self, (const char *)out, BLINK_putVLC((uint64_t)value, true, out, sizeof(out)));
|
318
|
-
}
|
319
|
-
else{
|
320
|
-
|
321
|
-
uint64_t value = NUM2ULL(val);
|
322
|
-
|
323
|
-
if(value > (uint64_t)max){
|
324
|
-
|
325
|
-
rb_raise(rb_eRangeError, "Input exceeds allowable range of type");
|
326
|
-
}
|
327
|
-
|
328
|
-
retval = rb_str_buf_cat(self, (const char *)out, BLINK_putVLC(value, false, out, sizeof(out)));
|
329
|
-
}
|
457
|
+
rb_raise(rb_eRangeError, "out of range");
|
330
458
|
}
|
331
|
-
|
459
|
+
|
332
460
|
return retval;
|
333
461
|
}
|
334
462
|
|
335
|
-
static VALUE
|
463
|
+
static VALUE getU32(VALUE self)
|
336
464
|
{
|
337
|
-
|
338
|
-
|
465
|
+
VALUE retval = Qnil;
|
466
|
+
uint32_t val;
|
467
|
+
bool isNull;
|
468
|
+
struct blink_stream stream;
|
469
|
+
(void)BLINK_Stream_initUser(&stream, &self, cUserStream);
|
470
|
+
if(BLINK_Compact_decodeU32(&stream, &val, &isNull)){
|
339
471
|
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
}
|
472
|
+
retval = (isNull) ? Qnil : UINT2NUM(val);
|
473
|
+
}
|
474
|
+
else{
|
344
475
|
|
345
|
-
|
346
|
-
|
347
|
-
|
476
|
+
rb_raise(rb_eRangeError, "out of range");
|
477
|
+
}
|
478
|
+
|
479
|
+
return retval;
|
348
480
|
}
|
349
481
|
|
350
482
|
static VALUE getU64(VALUE self)
|
351
483
|
{
|
352
|
-
|
353
|
-
|
484
|
+
VALUE retval = Qnil;
|
485
|
+
uint64_t val;
|
486
|
+
bool isNull;
|
487
|
+
struct blink_stream stream;
|
488
|
+
(void)BLINK_Stream_initUser(&stream, &self, cUserStream);
|
489
|
+
if(BLINK_Compact_decodeU64(&stream, &val, &isNull)){
|
354
490
|
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
}
|
491
|
+
retval = (isNull) ? Qnil : ULL2NUM(val);
|
492
|
+
}
|
493
|
+
else{
|
359
494
|
|
360
|
-
|
361
|
-
|
362
|
-
|
495
|
+
rb_raise(rb_eRangeError, "out of range");
|
496
|
+
}
|
497
|
+
|
498
|
+
return retval;
|
363
499
|
}
|
364
500
|
|
365
|
-
static VALUE
|
501
|
+
static VALUE getI8(VALUE self)
|
366
502
|
{
|
367
|
-
|
368
|
-
|
503
|
+
VALUE retval = Qnil;
|
504
|
+
int8_t val;
|
505
|
+
bool isNull;
|
506
|
+
struct blink_stream stream;
|
507
|
+
(void)BLINK_Stream_initUser(&stream, &self, cUserStream);
|
508
|
+
if(BLINK_Compact_decodeI8(&stream, &val, &isNull)){
|
369
509
|
|
370
|
-
|
371
|
-
|
372
|
-
|
510
|
+
retval = (isNull) ? Qnil : INT2NUM(val);
|
511
|
+
}
|
512
|
+
else{
|
513
|
+
|
514
|
+
rb_raise(rb_eRangeError, "out of range");
|
515
|
+
}
|
516
|
+
|
517
|
+
return retval;
|
373
518
|
}
|
374
519
|
|
375
|
-
static VALUE
|
520
|
+
static VALUE getI16(VALUE self)
|
376
521
|
{
|
377
|
-
bool isNull;
|
378
|
-
double out;
|
379
|
-
uint32_t ret;
|
380
522
|
VALUE retval = Qnil;
|
523
|
+
int16_t val;
|
524
|
+
bool isNull;
|
525
|
+
struct blink_stream stream;
|
526
|
+
(void)BLINK_Stream_initUser(&stream, &self, cUserStream);
|
527
|
+
if(BLINK_Compact_decodeI16(&stream, &val, &isNull)){
|
381
528
|
|
382
|
-
|
383
|
-
|
384
|
-
if(ret > 0){
|
385
|
-
|
386
|
-
rb_str_drop_bytes(self, ret);
|
387
|
-
if(!isNull){
|
388
|
-
|
389
|
-
retval = rb_float_new(out);
|
390
|
-
}
|
529
|
+
retval = (isNull) ? Qnil : INT2NUM(val);
|
391
530
|
}
|
392
531
|
else{
|
393
532
|
|
394
|
-
rb_raise(
|
533
|
+
rb_raise(rb_eRangeError, "out of range");
|
395
534
|
}
|
396
|
-
|
535
|
+
|
397
536
|
return retval;
|
398
537
|
}
|
399
538
|
|
400
|
-
static VALUE
|
539
|
+
static VALUE getI32(VALUE self)
|
401
540
|
{
|
402
|
-
VALUE retval =
|
403
|
-
|
404
|
-
|
541
|
+
VALUE retval = Qnil;
|
542
|
+
int32_t val;
|
543
|
+
bool isNull;
|
544
|
+
struct blink_stream stream;
|
545
|
+
(void)BLINK_Stream_initUser(&stream, &self, cUserStream);
|
546
|
+
if(BLINK_Compact_decodeI32(&stream, &val, &isNull)){
|
405
547
|
|
406
|
-
retval =
|
548
|
+
retval = (isNull) ? Qnil : INT2NUM(val);
|
407
549
|
}
|
550
|
+
else{
|
408
551
|
|
409
|
-
|
552
|
+
rb_raise(rb_eRangeError, "out of range");
|
553
|
+
}
|
554
|
+
|
555
|
+
return retval;
|
410
556
|
}
|
411
557
|
|
412
|
-
static VALUE
|
558
|
+
static VALUE getI64(VALUE self)
|
413
559
|
{
|
414
|
-
VALUE retval;
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
}
|
421
|
-
else if(value == UINT2NUM(1)){
|
560
|
+
VALUE retval = Qnil;
|
561
|
+
int64_t val;
|
562
|
+
bool isNull;
|
563
|
+
struct blink_stream stream;
|
564
|
+
(void)BLINK_Stream_initUser(&stream, &self, cUserStream);
|
565
|
+
if(BLINK_Compact_decodeI64(&stream, &val, &isNull)){
|
422
566
|
|
423
|
-
retval =
|
567
|
+
retval = (isNull) ? Qnil : LL2NUM(val);
|
424
568
|
}
|
425
569
|
else{
|
426
570
|
|
427
|
-
rb_raise(
|
571
|
+
rb_raise(rb_eRangeError, "out of range");
|
428
572
|
}
|
429
|
-
|
573
|
+
|
430
574
|
return retval;
|
431
575
|
}
|
432
576
|
|
433
|
-
static VALUE
|
577
|
+
static VALUE getF64(VALUE self)
|
434
578
|
{
|
435
579
|
VALUE retval = Qnil;
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
rb_raise(cStrongError1, "S1: Group encoding ends prematurely");
|
442
|
-
}
|
580
|
+
double val;
|
581
|
+
bool isNull;
|
582
|
+
struct blink_stream stream;
|
583
|
+
(void)BLINK_Stream_initUser(&stream, &self, cUserStream);
|
584
|
+
if(BLINK_Compact_decodeF64(&stream, &val, &isNull)){
|
443
585
|
|
444
|
-
retval =
|
445
|
-
rb_str_drop_bytes(self, NUM2UINT(size));
|
586
|
+
retval = (isNull) ? Qnil : DBL2NUM(val);
|
446
587
|
}
|
588
|
+
else{
|
447
589
|
|
590
|
+
rb_raise(rb_eRangeError, "out of range");
|
591
|
+
}
|
592
|
+
|
448
593
|
return retval;
|
449
594
|
}
|
450
595
|
|
451
|
-
static VALUE
|
596
|
+
static VALUE getPresent(VALUE self)
|
452
597
|
{
|
453
|
-
VALUE retval =
|
454
|
-
|
455
|
-
|
598
|
+
VALUE retval = Qnil;
|
599
|
+
bool val;
|
600
|
+
struct blink_stream stream;
|
601
|
+
(void)BLINK_Stream_initUser(&stream, &self, cUserStream);
|
602
|
+
if(BLINK_Compact_decodePresent(&stream, &val)){
|
456
603
|
|
457
|
-
|
604
|
+
retval = (val) ? Qtrue : Qfalse;
|
458
605
|
}
|
606
|
+
else{
|
459
607
|
|
608
|
+
rb_raise(rb_eRangeError, "out of range");
|
609
|
+
}
|
610
|
+
|
460
611
|
return retval;
|
461
612
|
}
|
462
613
|
|
463
|
-
static VALUE
|
614
|
+
static VALUE getBool(VALUE self)
|
464
615
|
{
|
465
|
-
VALUE retval;
|
466
|
-
|
467
|
-
|
616
|
+
VALUE retval = Qnil;
|
617
|
+
bool val;
|
618
|
+
bool isNull;
|
619
|
+
struct blink_stream stream;
|
620
|
+
(void)BLINK_Stream_initUser(&stream, &self, cUserStream);
|
621
|
+
if(BLINK_Compact_decodeBool(&stream, &val, &isNull)){
|
468
622
|
|
469
|
-
|
623
|
+
retval = (val) ? Qtrue : Qfalse;
|
470
624
|
}
|
625
|
+
else{
|
471
626
|
|
472
|
-
|
473
|
-
|
474
|
-
|
627
|
+
rb_raise(cWeakError11, "out of range");
|
628
|
+
}
|
629
|
+
|
475
630
|
return retval;
|
476
631
|
}
|
477
632
|
|
478
|
-
static VALUE
|
633
|
+
static VALUE getBinary(VALUE self)
|
479
634
|
{
|
480
635
|
VALUE retval = Qnil;
|
481
|
-
uint32_t
|
636
|
+
uint32_t size;
|
482
637
|
bool isNull;
|
483
|
-
|
638
|
+
struct blink_stream stream;
|
639
|
+
(void)BLINK_Stream_initUser(&stream, &self, cUserStream);
|
484
640
|
|
485
|
-
|
641
|
+
if(BLINK_Compact_decodeU32(&stream, &size, &isNull)){
|
486
642
|
|
487
|
-
|
488
|
-
|
489
|
-
rb_str_drop_bytes(self, ret);
|
490
|
-
|
491
|
-
if(isNull){
|
492
|
-
|
493
|
-
retval = Qnil;
|
494
|
-
}
|
495
|
-
else if(present == 0x01){
|
643
|
+
if(!isNull){
|
496
644
|
|
497
|
-
retval =
|
645
|
+
retval = rb_funcall(self, rb_intern("read"), 1, UINT2NUM(size));
|
498
646
|
|
499
|
-
if(
|
647
|
+
if((retval == Qnil) || ((uint32_t)NUM2UINT(rb_funcall(retval, rb_intern("size"), 0)) != size)){
|
500
648
|
|
501
649
|
rb_raise(cStrongError1, "S1: Group encoding ends prematurely");
|
502
650
|
}
|
503
|
-
|
504
|
-
rb_str_drop_bytes(self, NUM2UINT(size));
|
505
651
|
}
|
506
|
-
else{
|
507
|
-
|
508
|
-
rb_raise(cWeakError9, "W9: Presence flag is not 0xC0 or 0x01");
|
509
|
-
}
|
510
652
|
}
|
511
653
|
else{
|
512
654
|
|
513
|
-
rb_raise(
|
655
|
+
rb_raise(rb_eRangeError, "out of range");
|
514
656
|
}
|
515
|
-
|
657
|
+
|
516
658
|
return retval;
|
517
659
|
}
|
518
660
|
|
519
|
-
static VALUE
|
661
|
+
static VALUE getString(VALUE self)
|
520
662
|
{
|
521
|
-
|
522
|
-
uint64_t out;
|
523
|
-
VALUE retval = Qnil;
|
524
|
-
uint32_t ret;
|
525
|
-
|
526
|
-
ret = BLINK_getVLC((const uint8_t *)RSTRING_PTR(input), RSTRING_LEN(input), isSigned, &out, &isNull);
|
527
|
-
|
528
|
-
if(ret > 0){
|
529
|
-
|
530
|
-
rb_str_drop_bytes(input, ret);
|
531
|
-
|
532
|
-
if(!isNull){
|
533
|
-
|
534
|
-
if(isSigned){
|
535
|
-
|
536
|
-
if(((int64_t)out < min) || ((int64_t)out > max)){
|
537
|
-
|
538
|
-
rb_raise(cWeakError3, "W3: Decoded value overflows range");
|
539
|
-
}
|
540
|
-
|
541
|
-
if(BLINK_getSizeSigned((int64_t)out) != ret){
|
542
|
-
|
543
|
-
rb_raise(cWeakError4, "W4: VLC entity contains more bytes than needed to express full width of type");
|
544
|
-
}
|
663
|
+
VALUE retval = getBinary(self);
|
545
664
|
|
546
|
-
|
547
|
-
}
|
548
|
-
else{
|
549
|
-
|
550
|
-
if(out > (uint64_t)max){
|
665
|
+
if(retval != Qnil){
|
551
666
|
|
552
|
-
|
553
|
-
|
667
|
+
//todo: test UTF8 encoding here
|
668
|
+
}
|
554
669
|
|
555
|
-
|
670
|
+
return retval;
|
671
|
+
}
|
556
672
|
|
557
|
-
|
558
|
-
|
673
|
+
static VALUE getFixed(VALUE self, VALUE size)
|
674
|
+
{
|
675
|
+
VALUE retval = rb_funcall(self, rb_intern("read"), 1, UINT2NUM(size));
|
559
676
|
|
560
|
-
|
561
|
-
}
|
562
|
-
}
|
563
|
-
}
|
564
|
-
else{
|
677
|
+
if((retval == Qnil) || ((uint32_t)NUM2UINT(rb_funcall(retval, rb_intern("size"), 0)) != NUM2UINT(size))){
|
565
678
|
|
566
679
|
rb_raise(cStrongError1, "S1: Group encoding ends prematurely");
|
567
680
|
}
|
568
681
|
|
569
|
-
return retval;
|
682
|
+
return retval;
|
570
683
|
}
|