slow_blink 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/ext/slow_blink/ext_schema_parser/extconf.rb +1 -0
  3. data/ext/slow_blink/ext_schema_parser/lexer.c +6 -8
  4. data/ext/slow_blink/ext_schema_parser/lexer.h +1 -1
  5. data/ext/slow_blink/ext_schema_parser/parser.c +3 -1
  6. data/ext/slow_blink/message/ext_compact_encoder/ext_compact_encoder.c +46 -24
  7. data/ext/slow_blink/message/ext_compact_encoder/extconf.rb +9 -2
  8. data/lib/slow_blink/enum.rb +4 -1
  9. data/lib/slow_blink/field.rb +1 -1
  10. data/lib/slow_blink/generate_c/model.rb +119 -12
  11. data/lib/slow_blink/message/binary.rb +9 -1
  12. data/lib/slow_blink/message/boolean.rb +12 -3
  13. data/lib/slow_blink/message/date.rb +9 -1
  14. data/lib/slow_blink/message/decimal.rb +9 -1
  15. data/lib/slow_blink/message/dynamic_group.rb +132 -0
  16. data/lib/slow_blink/message/enum.rb +6 -2
  17. data/lib/slow_blink/message/field.rb +67 -43
  18. data/lib/slow_blink/message/fixed.rb +5 -1
  19. data/lib/slow_blink/message/floating_point.rb +9 -1
  20. data/lib/slow_blink/message/group.rb +54 -197
  21. data/lib/slow_blink/message/integer.rb +16 -8
  22. data/lib/slow_blink/message/model.rb +20 -18
  23. data/lib/slow_blink/message/static_group.rb +63 -0
  24. data/lib/slow_blink/message/string.rb +9 -1
  25. data/lib/slow_blink/message/test_data.rb +126 -0
  26. data/lib/slow_blink/message/time.rb +10 -2
  27. data/lib/slow_blink/message/time_of_day.rb +18 -2
  28. data/lib/slow_blink/schema.rb +2 -2
  29. data/lib/slow_blink/type.rb +3 -3
  30. data/lib/slow_blink/version.rb +1 -1
  31. data/test/tc_inputs.rb +34 -25
  32. data/test/tc_model_enum.rb +47 -0
  33. data/test/tc_model_inputs.rb +47 -0
  34. metadata +9 -7
  35. data/ext/slow_blink/message/ext_compact_encoder/blink_compact.c +0 -642
  36. data/ext/slow_blink/message/ext_compact_encoder/blink_compact.h +0 -411
  37. data/ext/slow_blink/message/ext_compact_encoder/blink_debug.h +0 -46
  38. data/ext/slow_blink/message/ext_compact_encoder/blink_stream.c +0 -314
  39. data/ext/slow_blink/message/ext_compact_encoder/blink_stream.h +0 -185
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2e5c8703fac5df385bd6aa4356424bba69f17545
4
- data.tar.gz: c39e33c756d2d1894da535a9fbac5e27e5d78836
3
+ metadata.gz: c5455bc952a75dc80f05313682d5346fe76410a5
4
+ data.tar.gz: f8f43a1ed8bb7ee180573a4e526331ab20b051ff
5
5
  SHA512:
6
- metadata.gz: 322bec40e0b8fbe85951a2eda760726ab4af49249e4fe595860b5c60be46c52b7e1efbe972aee34367c8fcf195fc2b5e074561c76ba1e67ef083a7c6140876f0
7
- data.tar.gz: 981195d2134e1fccfc06986cdec88019e7c0d47273e857b838810d6643484374d4cf1e69b91ca64af21f62dd5703148641f1965481b331d7feed008cbfb52868
6
+ metadata.gz: f60e3a127aba57bd69a3d9ce5f899a9bb7915ca4aee4b4114f03d559ce9555f21ef9d4bc4470b1a0abdb058c77b1f92d742c145c880a0a2729ac53dee975b51d
7
+ data.tar.gz: ca0fa723aaf930665aa8851831702b3b0fd13b27193f69374966181200159f640e3d61b31f6feb39a33a616ab7a2851c5c605a1331093431d3611290ac74fe1f
@@ -1,3 +1,4 @@
1
1
  require 'mkmf'
2
+
2
3
  create_makefile('slow_blink/ext_schema_parser')
3
4
 
@@ -3479,21 +3479,19 @@ YY_RULE_SETUP
3479
3479
  #line 80 "etc/slow_blink/ext_schema_parser/parser.l"
3480
3480
  { *yylval = rb_str_new(&yytext[1], yyleng-1); return TOK_ESCAPED_NC_NAME; }
3481
3481
  YY_BREAK
3482
- case YY_STATE_EOF(INITIAL):
3483
- #line 82 "etc/slow_blink/ext_schema_parser/parser.l"
3484
- { return TOK_EOF; }
3485
- YY_BREAK
3486
3482
  case 50:
3487
3483
  YY_RULE_SETUP
3488
- #line 84 "etc/slow_blink/ext_schema_parser/parser.l"
3484
+ #line 82 "etc/slow_blink/ext_schema_parser/parser.l"
3489
3485
  { return TOK_UNKNOWN; }
3490
3486
  YY_BREAK
3491
3487
  case 51:
3492
3488
  YY_RULE_SETUP
3493
- #line 86 "etc/slow_blink/ext_schema_parser/parser.l"
3489
+ #line 84 "etc/slow_blink/ext_schema_parser/parser.l"
3494
3490
  ECHO;
3495
3491
  YY_BREAK
3496
- #line 3497 "ext/slow_blink/ext_schema_parser/lexer.c"
3492
+ #line 3493 "ext/slow_blink/ext_schema_parser/lexer.c"
3493
+ case YY_STATE_EOF(INITIAL):
3494
+ yyterminate();
3497
3495
 
3498
3496
  case YY_END_OF_BUFFER:
3499
3497
  {
@@ -4640,7 +4638,7 @@ void yyfree (void * ptr , yyscan_t yyscanner)
4640
4638
 
4641
4639
  #define YYTABLES_NAME "yytables"
4642
4640
 
4643
- #line 86 "etc/slow_blink/ext_schema_parser/parser.l"
4641
+ #line 84 "etc/slow_blink/ext_schema_parser/parser.l"
4644
4642
 
4645
4643
 
4646
4644
 
@@ -355,7 +355,7 @@ extern int yylex \
355
355
  #undef YY_DECL
356
356
  #endif
357
357
 
358
- #line 86 "etc/slow_blink/ext_schema_parser/parser.l"
358
+ #line 84 "etc/slow_blink/ext_schema_parser/parser.l"
359
359
 
360
360
 
361
361
  #line 362 "ext/slow_blink/ext_schema_parser/lexer.h"
@@ -1275,7 +1275,7 @@ yyuserAction (yyRuleNum yyn, size_t yyrhslen, yyGLRStackItem* yyvsp,
1275
1275
  #line 251 "etc/slow_blink/ext_schema_parser/parser.y" /* glr.c:816 */
1276
1276
  {
1277
1277
  ((*yyvalp)) = rb_hash_new();
1278
- rb_hash_aset(((*yyvalp)), ID2SYM(rb_intern("class")), ID2SYM(rb_intern("BOOL")));
1278
+ rb_hash_aset(((*yyvalp)), ID2SYM(rb_intern("class")), ID2SYM(rb_intern("BOOLEAN")));
1279
1279
  rb_hash_aset(((*yyvalp)), ID2SYM(rb_intern("loc")), newLocation(filename, &(*yylocp)));
1280
1280
  }
1281
1281
  #line 1282 "ext/slow_blink/ext_schema_parser/parser.c" /* glr.c:816 */
@@ -3756,6 +3756,8 @@ static VALUE parseFileBuffer(int argc, VALUE* argv, VALUE self)
3756
3756
 
3757
3757
  filename = rb_hash_aref(opts, ID2SYM(rb_intern("filename")));
3758
3758
 
3759
+ rb_gc_mark(filename);
3760
+
3759
3761
  if(yylex_init(&scanner) == 0){
3760
3762
 
3761
3763
  if(yy_scan_bytes((const char *)RSTRING_PTR(buffer), RSTRING_LEN(buffer), scanner)){
@@ -82,9 +82,14 @@ static VALUE cWeakError4;
82
82
  static VALUE cWeakError9;
83
83
  static VALUE cWeakError11;
84
84
 
85
- static struct blink_stream_user cUserStream = {
85
+ static const struct blink_stream_user cUserStream = {
86
86
  .read = myRead,
87
- .write = myWrite
87
+ .write = myWrite,
88
+ .tell = NULL,
89
+ .peek = NULL,
90
+ .seekCur = NULL,
91
+ .seekSet = NULL,
92
+ .eof = NULL
88
93
  };
89
94
 
90
95
  /* functions **********************************************************/
@@ -147,13 +152,15 @@ void Init_ext_compact_encoder(void)
147
152
 
148
153
  /* static functions ***************************************************/
149
154
 
155
+ #include <assert.h>
156
+
150
157
  static bool myRead(void *state, void *buf, size_t nbyte)
151
158
  {
152
159
  bool retval = false;
153
- VALUE stringIO = *(VALUE *)state;
154
160
 
161
+ VALUE stringIO = *(VALUE *)state;
155
162
  VALUE out = rb_funcall(stringIO, rb_intern("read"), 1, SIZET2NUM(nbyte));
156
-
163
+
157
164
  if((size_t)RSTRING_LEN(out) == nbyte){
158
165
 
159
166
  (void)memcpy(buf, RSTRING_PTR(out), (size_t)RSTRING_LEN(out));
@@ -182,6 +189,7 @@ static VALUE putU8(VALUE self, VALUE val)
182
189
  if(NUM2ULL(val) <= UINT8_MAX){
183
190
 
184
191
  struct blink_stream stream;
192
+
185
193
  (void)BLINK_Stream_initUser(&stream, &self, cUserStream);
186
194
  (void)BLINK_Compact_encodeU8((uint8_t)NUM2ULL(val), &stream);
187
195
  }
@@ -203,6 +211,7 @@ static VALUE putU16(VALUE self, VALUE val)
203
211
  if(NUM2ULL(val) <= UINT16_MAX){
204
212
 
205
213
  struct blink_stream stream;
214
+
206
215
  (void)BLINK_Stream_initUser(&stream, &self, cUserStream);
207
216
  (void)BLINK_Compact_encodeU16((uint16_t)NUM2ULL(val), &stream);
208
217
  }
@@ -224,6 +233,7 @@ static VALUE putU32(VALUE self, VALUE val)
224
233
  if(NUM2ULL(val) <= UINT32_MAX){
225
234
 
226
235
  struct blink_stream stream;
236
+
227
237
  (void)BLINK_Stream_initUser(&stream, &self, cUserStream);
228
238
  (void)BLINK_Compact_encodeU32((uint32_t)NUM2ULL(val), &stream);
229
239
  }
@@ -242,16 +252,11 @@ static VALUE putU64(VALUE self, VALUE val)
242
252
  (void)putNull(self);
243
253
  }
244
254
  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
255
 
253
- rb_raise(rb_eRangeError, "Input exceeds allowable range of type");
254
- }
256
+ struct blink_stream stream;
257
+
258
+ (void)BLINK_Stream_initUser(&stream, &self, cUserStream);
259
+ (void)BLINK_Compact_encodeU64(NUM2ULL(val), &stream);
255
260
  }
256
261
 
257
262
  return self;
@@ -266,6 +271,7 @@ static VALUE putI8(VALUE self, VALUE val)
266
271
  if((NUM2LL(val) >= INT8_MIN) && (NUM2LL(val) <= INT8_MAX)){
267
272
 
268
273
  struct blink_stream stream;
274
+
269
275
  (void)BLINK_Stream_initUser(&stream, &self, cUserStream);
270
276
  (void)BLINK_Compact_encodeI8((int8_t)NUM2LL(val), &stream);
271
277
  }
@@ -287,6 +293,7 @@ static VALUE putI16(VALUE self, VALUE val)
287
293
  if((NUM2LL(val) >= INT16_MIN) && (NUM2LL(val) <= INT16_MAX)){
288
294
 
289
295
  struct blink_stream stream;
296
+
290
297
  (void)BLINK_Stream_initUser(&stream, &self, cUserStream);
291
298
  (void)BLINK_Compact_encodeI16((int16_t)NUM2LL(val), &stream);
292
299
  }
@@ -308,6 +315,7 @@ static VALUE putI32(VALUE self, VALUE val)
308
315
  if((NUM2LL(val) >= INT32_MIN) && (NUM2LL(val) <= INT32_MAX)){
309
316
 
310
317
  struct blink_stream stream;
318
+
311
319
  (void)BLINK_Stream_initUser(&stream, &self, cUserStream);
312
320
  (void)BLINK_Compact_encodeI32((int32_t)NUM2LL(val), &stream);
313
321
  }
@@ -326,16 +334,10 @@ static VALUE putI64(VALUE self, VALUE val)
326
334
  }
327
335
  else{
328
336
 
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
- }
337
+ struct blink_stream stream;
338
+
339
+ (void)BLINK_Stream_initUser(&stream, &self, cUserStream);
340
+ (void)BLINK_Compact_encodeI64(NUM2LL(val), &stream);
339
341
  }
340
342
  return self;
341
343
  }
@@ -348,6 +350,7 @@ static VALUE putF64(VALUE self, VALUE val)
348
350
  else{
349
351
 
350
352
  struct blink_stream stream;
353
+
351
354
  (void)BLINK_Stream_initUser(&stream, &self, cUserStream);
352
355
  (void)BLINK_Compact_encodeF64(NUM2DBL(val), &stream);
353
356
  }
@@ -363,8 +366,9 @@ static VALUE putBool(VALUE self, VALUE val)
363
366
  else{
364
367
 
365
368
  struct blink_stream stream;
369
+
366
370
  (void)BLINK_Stream_initUser(&stream, &self, cUserStream);
367
- (void)BLINK_Compact_encodeBool((val == Qfalse) ? false : true, &stream);
371
+ (void)BLINK_Compact_encodeBool(((val == Qfalse) ? false : true), &stream);
368
372
  }
369
373
  return self;
370
374
  }
@@ -372,6 +376,7 @@ static VALUE putBool(VALUE self, VALUE val)
372
376
  static VALUE putNull(VALUE self)
373
377
  {
374
378
  struct blink_stream stream;
379
+
375
380
  (void)BLINK_Stream_initUser(&stream, &self, cUserStream);
376
381
  (void)BLINK_Compact_encodeNull(&stream);
377
382
  return self;
@@ -380,6 +385,7 @@ static VALUE putNull(VALUE self)
380
385
  static VALUE putPresent(VALUE self)
381
386
  {
382
387
  struct blink_stream stream;
388
+
383
389
  (void)BLINK_Stream_initUser(&stream, &self, cUserStream);
384
390
  (void)BLINK_Compact_encodePresent(&stream);
385
391
  return self;
@@ -389,6 +395,7 @@ static VALUE putBinary(VALUE self, VALUE val)
389
395
  {
390
396
  VALUE retval = Qnil;
391
397
  struct blink_stream stream;
398
+
392
399
  (void)BLINK_Stream_initUser(&stream, &self, cUserStream);
393
400
 
394
401
  if(val == Qnil){
@@ -428,6 +435,7 @@ static VALUE getU8(VALUE self)
428
435
  uint8_t val;
429
436
  bool isNull;
430
437
  struct blink_stream stream;
438
+
431
439
  (void)BLINK_Stream_initUser(&stream, &self, cUserStream);
432
440
  if(BLINK_Compact_decodeU8(&stream, &val, &isNull)){
433
441
 
@@ -447,6 +455,7 @@ static VALUE getU16(VALUE self)
447
455
  uint16_t val;
448
456
  bool isNull;
449
457
  struct blink_stream stream;
458
+
450
459
  (void)BLINK_Stream_initUser(&stream, &self, cUserStream);
451
460
  if(BLINK_Compact_decodeU16(&stream, &val, &isNull)){
452
461
 
@@ -465,6 +474,7 @@ static VALUE getU32(VALUE self)
465
474
  VALUE retval = Qnil;
466
475
  uint32_t val;
467
476
  bool isNull;
477
+ rb_gc_mark(self);
468
478
  struct blink_stream stream;
469
479
  (void)BLINK_Stream_initUser(&stream, &self, cUserStream);
470
480
  if(BLINK_Compact_decodeU32(&stream, &val, &isNull)){
@@ -485,6 +495,7 @@ static VALUE getU64(VALUE self)
485
495
  uint64_t val;
486
496
  bool isNull;
487
497
  struct blink_stream stream;
498
+
488
499
  (void)BLINK_Stream_initUser(&stream, &self, cUserStream);
489
500
  if(BLINK_Compact_decodeU64(&stream, &val, &isNull)){
490
501
 
@@ -504,6 +515,7 @@ static VALUE getI8(VALUE self)
504
515
  int8_t val;
505
516
  bool isNull;
506
517
  struct blink_stream stream;
518
+
507
519
  (void)BLINK_Stream_initUser(&stream, &self, cUserStream);
508
520
  if(BLINK_Compact_decodeI8(&stream, &val, &isNull)){
509
521
 
@@ -523,6 +535,7 @@ static VALUE getI16(VALUE self)
523
535
  int16_t val;
524
536
  bool isNull;
525
537
  struct blink_stream stream;
538
+
526
539
  (void)BLINK_Stream_initUser(&stream, &self, cUserStream);
527
540
  if(BLINK_Compact_decodeI16(&stream, &val, &isNull)){
528
541
 
@@ -542,6 +555,7 @@ static VALUE getI32(VALUE self)
542
555
  int32_t val;
543
556
  bool isNull;
544
557
  struct blink_stream stream;
558
+
545
559
  (void)BLINK_Stream_initUser(&stream, &self, cUserStream);
546
560
  if(BLINK_Compact_decodeI32(&stream, &val, &isNull)){
547
561
 
@@ -561,6 +575,7 @@ static VALUE getI64(VALUE self)
561
575
  int64_t val;
562
576
  bool isNull;
563
577
  struct blink_stream stream;
578
+
564
579
  (void)BLINK_Stream_initUser(&stream, &self, cUserStream);
565
580
  if(BLINK_Compact_decodeI64(&stream, &val, &isNull)){
566
581
 
@@ -580,6 +595,7 @@ static VALUE getF64(VALUE self)
580
595
  double val;
581
596
  bool isNull;
582
597
  struct blink_stream stream;
598
+
583
599
  (void)BLINK_Stream_initUser(&stream, &self, cUserStream);
584
600
  if(BLINK_Compact_decodeF64(&stream, &val, &isNull)){
585
601
 
@@ -598,6 +614,7 @@ static VALUE getPresent(VALUE self)
598
614
  VALUE retval = Qnil;
599
615
  bool val;
600
616
  struct blink_stream stream;
617
+
601
618
  (void)BLINK_Stream_initUser(&stream, &self, cUserStream);
602
619
  if(BLINK_Compact_decodePresent(&stream, &val)){
603
620
 
@@ -617,6 +634,8 @@ static VALUE getBool(VALUE self)
617
634
  bool val;
618
635
  bool isNull;
619
636
  struct blink_stream stream;
637
+ rb_gc_mark(self);
638
+
620
639
  (void)BLINK_Stream_initUser(&stream, &self, cUserStream);
621
640
  if(BLINK_Compact_decodeBool(&stream, &val, &isNull)){
622
641
 
@@ -636,6 +655,8 @@ static VALUE getBinary(VALUE self)
636
655
  uint32_t size;
637
656
  bool isNull;
638
657
  struct blink_stream stream;
658
+ rb_gc_mark(self);
659
+
639
660
  (void)BLINK_Stream_initUser(&stream, &self, cUserStream);
640
661
 
641
662
  if(BLINK_Compact_decodeU32(&stream, &size, &isNull)){
@@ -643,6 +664,7 @@ static VALUE getBinary(VALUE self)
643
664
  if(!isNull){
644
665
 
645
666
  retval = rb_funcall(self, rb_intern("read"), 1, UINT2NUM(size));
667
+ rb_gc_mark(retval);
646
668
 
647
669
  if((retval == Qnil) || ((uint32_t)NUM2UINT(rb_funcall(retval, rb_intern("size"), 0)) != size)){
648
670
 
@@ -1,4 +1,11 @@
1
1
  require 'mkmf'
2
- $CFLAGS += " -std=c99"
3
- create_makefile('slow_blink/message/ext_compact_encoder')
2
+
3
+ $srcs = ['ext_compact_encoder.c', 'blink_stream.c', 'blink_compact.c']
4
+ $VPATH << "../../../../ext/slow_blink/message/ext_compact_encoder"
5
+ $INCFLAGS << " -I$(srcdir)/../include"
6
+ $defs << " -DBLINK_DEBUG_INCLUDE=#include <ruby.h>"
7
+ $defs << " -D'BLINK_ERROR(...)=rb_funcall(rb_stderr, rb_intern(\\\"puts\\\"), 1, rb_str_new2(__VA_ARGS__));'"
8
+ $defs << " -D'BLINK_DEBUG(...)=rb_funcall(rb_stderr, rb_intern(\\\"puts\\\"), 1, rb_str_new2(__VA_ARGS__));'"
9
+
10
+ create_makefile('slow_blink/message/ext_compact_encoder', "../../../../assets/ublink/src")
4
11
 
@@ -38,7 +38,8 @@ module SlowBlink
38
38
  # @private
39
39
  def initialize(attr)
40
40
 
41
- @location = attr[:loc]
41
+ super(attr)
42
+
42
43
  @symbols = {}
43
44
  @name = attr[:name].dup.freeze
44
45
 
@@ -90,10 +91,12 @@ module SlowBlink
90
91
  if (result = @symbols[nameOrVal]).nil?
91
92
  raise RangeError
92
93
  end
94
+ result
93
95
  else
94
96
  if (result = @symbols.values.detect{|s|s.value == nameOrVal.to_i}).nil?
95
97
  raise RangeError
96
98
  end
99
+ result
97
100
  end
98
101
  end
99
102
 
@@ -93,7 +93,7 @@ module SlowBlink
93
93
  def initialize(attr)
94
94
  @name = attr[:name][:name].freeze
95
95
  @id = attr[:name][:id]
96
- @optional = attr[:opt]
96
+ @optional = (attr[:optional] ? true : false)
97
97
  @location = attr[:location].freeze
98
98
  @type = SlowBlink.const_get(attr[:type][:class]).new(attr[:type].merge({:table => attr[:table], :ns => attr[:ns]}))
99
99
  @table = attr[:table]
@@ -14,17 +14,57 @@ module SlowBlink
14
14
  @options = {}
15
15
  end
16
16
 
17
- def render
18
- header = put("groups.h.erb")
19
- source = put("groups.c.erb")
17
+ def generate(prefix)
20
18
 
21
- File.write("groups.h", header)
22
- File.write("groups.c", source)
23
- end
19
+ `mkdir -p #{prefix}`
20
+ `rm -fr #{File.join(prefix, "*")}`
21
+
22
+ header = run_erb("include/groups.h.erb")
23
+ source = run_erb("src/groups.c.erb")
24
+
25
+ tc_new = run_erb("test/tc_new.c.erb")
26
+ tc_decodecompact = run_erb("test/tc_decodecompact.c.erb")
27
+
28
+ testMake = run_erb("test/makefile.erb")
29
+
30
+ `mkdir #{File.join(prefix, "src")}`
31
+ `mkdir #{File.join(prefix, "include")}`
32
+ `mkdir #{File.join(prefix, "test")}`
33
+ `mkdir #{File.join(prefix, "test", "build")}`
34
+ `mkdir #{File.join(prefix, "test", "bin")}`
35
+ `mkdir #{File.join(prefix, "vendor")}`
36
+ `mkdir #{File.join(prefix, "vendor", "cmocka")}`
37
+
38
+ assetsDir = File.expand_path(File.join(File.dirname(__FILE__), "../../../assets"))
39
+
40
+ `cp #{assetsDir}/ublink/src/blink_stream.c #{prefix}/src`
41
+ `cp #{assetsDir}/ublink/src/blink_compact.c #{prefix}/src`
42
+
43
+ `cp #{assetsDir}/ublink/include/blink_stream.h #{prefix}/include`
44
+ `cp #{assetsDir}/ublink/include/blink_compact.h #{prefix}/include`
45
+
46
+ `cp #{assetsDir}/ublink/include/blink_debug.h #{prefix}/include`
47
+
48
+ `cp -r #{assetsDir}/cmocka/src #{prefix}/vendor/cmocka/`
49
+ `cp -r #{assetsDir}/cmocka/include #{prefix}/vendor/cmocka/`
50
+ `cp #{assetsDir}/cmocka/COPYING #{prefix}/vendor/cmocka/`
51
+
52
+
53
+ File.open("#{prefix}/include/groups.h", "w"){|f|f.write(header)}
54
+ File.open("#{prefix}/src/groups.c", "w"){|f|f.write(source)}
55
+
56
+ File.open("#{prefix}/test/tc_new.c", "w"){|f|f.write(tc_new)}
57
+ File.open("#{prefix}/test/tc_decodecompact.c", "w"){|f|f.write(tc_decodecompact)}
58
+
59
+ File.open("#{prefix}/test/makefile", "w"){|f|f.write(testMake)}
60
+
61
+ puts `cd #{prefix}/test && make`
62
+
63
+ end
24
64
 
25
65
  private
26
66
 
27
- def put(filename)
67
+ def run_erb(filename)
28
68
  f = File.read(File.expand_path(File.join(File.dirname(__FILE__), filename)))
29
69
  erb = ERB.new(f, nil, "<>-")
30
70
  erb.filename = filename
@@ -39,13 +79,82 @@ module SlowBlink
39
79
  "_#{f.name}"
40
80
  end
41
81
 
82
+ def fvalue(f)
83
+ if f.type.sequence?
84
+ "#{fname(f)}.tail->value"
85
+ else
86
+ "#{fname(f)}.value"
87
+ end
88
+ end
89
+
90
+ def testSignature(g, f)
91
+ "bool #{gname(g)}_test_#{f.name}(group_t group)"
92
+ end
93
+
94
+ def clearSignature(g, f)
95
+ "void #{gname(g)}_clear_#{f.name}(group_t group)"
96
+ end
97
+
98
+ def setSignature(g, f)
99
+ out = "bool #{}_#{gname(g)}_set_#{f.name}(group_t group, "
100
+ case f.type.class
101
+ when STRING
102
+ out << "const char *data, uint32_t len"
103
+ when BINARY, FIXED
104
+ out << "const uint8_t *data, uint32_t len"
105
+ when DECIMAL
106
+ out << "int64_t mantissa, int8_t exponent"
107
+ when ENUM
108
+ out << "const char *value"
109
+ else
110
+ out << "#{value_type(f.type)} value"
111
+ end
112
+ out << ")"
113
+ end
114
+
115
+ def getSignature(g, f)
116
+ out = ""
117
+ case f.type.class
118
+ when STRING, BINARY, FIXED, DECIMAL
119
+ out << "void"
120
+ when ENUM
121
+ out << "const char *"
122
+ else
123
+ out << value_type(f.type)
124
+ end
125
+ out << " #{gname(g)}_get_#{f.name}(group_t group"
126
+ case f.type.class
127
+ when STRING
128
+ out << ", const char **data, uint32_t *len"
129
+ when BINARY, FIXED
130
+ out << ", const uint8_t **data, uint32_t *len"
131
+ when DECIMAL
132
+ out << ", int64_t *mantissa, int8_t *exponent"
133
+ end
134
+ out << ")"
135
+ end
136
+
137
+ def appendSignature(g,f)
138
+ setSignature(g,f).sub("_get_","_append_")
139
+ end
140
+
141
+ def getResult(f)
142
+ out = ""
143
+ case f.type.class
144
+ when STRING, BINARY, FIXED, DECIMAL
145
+ out << "void"
146
+ else
147
+ out << value_type(f.type)
148
+ end
149
+ end
150
+
42
151
  def value_type(type)
43
152
 
44
153
  out = ""
45
154
 
46
155
  case type.class
47
156
  when BINARY, STRING, FIXED
48
- out << "struct blink_string"
157
+ out << "struct string"
49
158
  when U8
50
159
  out << "uint8_t"
51
160
  when U16
@@ -58,16 +167,14 @@ module SlowBlink
58
167
  out << "int8_t"
59
168
  when I16
60
169
  out << "int16_t"
61
- when I32
170
+ when I32, ENUM
62
171
  out << "int32_t"
63
172
  when I64
64
173
  out << "int64_t"
65
- when ENUM
66
- out << "const char *"
67
174
  when FLOATING_POINT
68
175
  out << "double"
69
176
  when DECIMAL
70
- out << "struct blink_decimal"
177
+ out << "struct decimal"
71
178
  when BOOLEAN
72
179
  out << "bool"
73
180
  when StaticGroup
@@ -24,8 +24,12 @@ module SlowBlink::Message
24
24
  # @abstract
25
25
  class BINARY
26
26
 
27
+ def self.type
28
+ @type
29
+ end
30
+
27
31
  # @private
28
- def self.from_compact(input, stack)
32
+ def self.from_compact(input, depth)
29
33
  if value = input.getBinary
30
34
  if !@size or value.size <= @size
31
35
  self.new(value)
@@ -73,6 +77,10 @@ module SlowBlink::Message
73
77
  out.putBinary(@value)
74
78
  end
75
79
 
80
+ def to_tag
81
+ @value.bytes.map{ |c| sprintf("\\x%02X",c) }.join
82
+ end
83
+
76
84
  end
77
85
 
78
86
  end
@@ -24,9 +24,14 @@ module SlowBlink::Message
24
24
  # @abstract
25
25
  class BOOLEAN
26
26
 
27
+ def self.type
28
+ @type
29
+ end
30
+
27
31
  # @private
28
- def self.from_compact(input, stack)
29
- if value = input.getBool
32
+ def self.from_compact(input, depth)
33
+ value = input.getBool
34
+ if !value.nil?
30
35
  self.new(value)
31
36
  else
32
37
  nil
@@ -51,13 +56,17 @@ module SlowBlink::Message
51
56
 
52
57
  # @note calls {#set}(value)
53
58
  def initialize(value)
54
- set(value)
59
+ set(value)
55
60
  end
56
61
 
57
62
  # @private
58
63
  def to_compact(out)
59
64
  out.putBool(@value)
60
65
  end
66
+
67
+ def to_tag
68
+ ( @value ? "Y" : "N" )
69
+ end
61
70
 
62
71
  end
63
72
 
@@ -24,8 +24,12 @@ module SlowBlink::Message
24
24
  # @abstract
25
25
  class DATE
26
26
 
27
+ def self.type
28
+ @type
29
+ end
30
+
27
31
  # @private
28
- def self.from_compact(input, stack)
32
+ def self.from_compact(input, depth)
29
33
  if value = input.getI32
30
34
  self.new(value)
31
35
  else
@@ -49,6 +53,10 @@ module SlowBlink::Message
49
53
  def to_compact(out)
50
54
  out.putI32(@value.strftime('%Q'))
51
55
  end
56
+
57
+ def to_tag
58
+ @value.to_s
59
+ end
52
60
 
53
61
  end
54
62
 
@@ -26,8 +26,12 @@ module SlowBlink::Message
26
26
  # @abstract
27
27
  class DECIMAL
28
28
 
29
+ def self.type
30
+ @type
31
+ end
32
+
29
33
  # @private
30
- def self.from_compact(input, stack)
34
+ def self.from_compact(input, depth)
31
35
  if e = input.getI8
32
36
  if m = input.getI64
33
37
  self.new("#{m}E#{e}")
@@ -68,6 +72,10 @@ module SlowBlink::Message
68
72
  out.putI64(mantissa)
69
73
 
70
74
  end
75
+
76
+ def to_tag
77
+ @value.to_s
78
+ end
71
79
 
72
80
  end
73
81