divine 0.0.4 → 0.0.5
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.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/README.md +285 -2
- data/divine.gemspec +2 -2
- data/lib/divine.rb +0 -0
- data/lib/divine/code_generators/code_generator.rb +0 -0
- data/lib/divine/code_generators/csharp.rb +24 -50
- data/lib/divine/code_generators/java.rb +22 -28
- data/lib/divine/code_generators/javascript.rb +19 -33
- data/lib/divine/code_generators/ruby.rb +17 -34
- data/lib/divine/dsl.rb +47 -8
- data/lib/divine/graph_generator/graph_generator.rb +0 -0
- data/lib/divine/version.rb +1 -1
- data/test/basic_complex_test/basic_complex_test.rb +0 -0
- data/test/basic_complex_test/java_test/JavaTest.java +0 -0
- data/test/basic_complex_test/js_test/js_testBasic.js +1 -5
- data/test/basic_complex_test/js_test/js_testComplex.js +1 -5
- data/test/basic_complex_test/ruby_test/ruby_test.rb +0 -0
- data/test/binaryTree_test/binaryTree_test.rb +1 -0
- data/test/binaryTree_test/csharp_test/csharp_test.cs +8 -0
- data/test/binaryTree_test/graph.png +0 -0
- data/test/binaryTree_test/java_test/JavaTest.java +9 -0
- data/test/binaryTree_test/js_test/js_test.js +9 -5
- data/test/binaryTree_test/ruby_test/ruby_test.rb +10 -2
- data/test/complex_test/complex_test.rb +0 -0
- data/test/complex_test/csharp_test/csharp_test.cs +0 -0
- data/test/complex_test/graph.png +0 -0
- data/test/complex_test/java_test/JavaTest.java +0 -0
- data/test/complex_test/js_test/js_test.js +1 -5
- data/test/complex_test/ruby_test/ruby_test.rb +0 -0
- data/test/dynamic_int_test/csharp_test/csharp_test.cs +0 -0
- data/test/dynamic_int_test/dynamic_int_test.rb +0 -0
- data/test/dynamic_int_test/java_test/JavaTest.java +0 -0
- data/test/dynamic_int_test/js_test/js_test.js +1 -5
- data/test/dynamic_int_test/ruby_test/ruby_test.rb +0 -0
- data/test/ipv6_test/csharp_test/csharp_test.cs +0 -0
- data/test/ipv6_test/ipv6_test.rb +0 -0
- data/test/ipv6_test/java_test/JavaTest.java +0 -0
- data/test/ipv6_test/js_test/js_test.js +1 -5
- data/test/ipv6_test/ruby_test/ruby_test.rb +0 -0
- data/test/lib/csharp/nunit.framework.dll +0 -0
- data/test/lib/java/junit.jar +0 -0
- data/test/signed_int_test/csharp_test/csharp_test.cs +0 -0
- data/test/signed_int_test/java_test/JavaTest.java +0 -0
- data/test/signed_int_test/js_test/js_test.js +1 -5
- data/test/signed_int_test/ruby_test/ruby_test.rb +0 -0
- data/test/signed_int_test/signed_int_test.rb +0 -0
- data/test/unify_test/unify_test.rb +0 -0
- metadata +18 -34
- data/test/basic_complex_test/graph.jpg +0 -0
- data/test/dynamic_int_test/graph.jpg +0 -0
- data/test/ipv6_test/graph.jpg +0 -0
- data/test/signed_int_test/graph.jpg +0 -0
@@ -81,7 +81,7 @@ abstract class Divine <%= toplevel_class %> {
|
|
81
81
|
|
82
82
|
protected String readString(ByteArrayInputStream data) throws IOException {
|
83
83
|
// Force utf8
|
84
|
-
return new String(readBytes(
|
84
|
+
return new String(readBytes((int)readDint63(data), data), UTF8);
|
85
85
|
}
|
86
86
|
|
87
87
|
private byte[] readBytes(int size, ByteArrayInputStream data) throws IOException {
|
@@ -91,19 +91,15 @@ abstract class Divine <%= toplevel_class %> {
|
|
91
91
|
}
|
92
92
|
|
93
93
|
protected byte[] readBinary(ByteArrayInputStream data) throws IOException {
|
94
|
-
long c =
|
94
|
+
long c = readDint63(data);
|
95
95
|
if (c > Integer.MAX_VALUE) {
|
96
96
|
throw new IndexOutOfBoundsException("Binary data to big for java");
|
97
97
|
}
|
98
98
|
return readBytes((int) c, data);
|
99
99
|
}
|
100
100
|
|
101
|
-
protected byte[] readShortBinary(ByteArrayInputStream data) throws IOException {
|
102
|
-
return readBytes(readInt8(data), data);
|
103
|
-
}
|
104
|
-
|
105
101
|
protected String readIpNumber(ByteArrayInputStream data) throws IOException {
|
106
|
-
byte[] ips =
|
102
|
+
byte[] ips = readBytes(readInt8(data), data);
|
107
103
|
if(ips.length == 4){
|
108
104
|
return readIpv4Number(ips);
|
109
105
|
} else{
|
@@ -207,8 +203,10 @@ abstract class Divine <%= toplevel_class %> {
|
|
207
203
|
|
208
204
|
for (int i = bytes.length - 1; i >= 0; i--){
|
209
205
|
String s = bytes[i];
|
210
|
-
|
211
|
-
|
206
|
+
char[] zeros = new char[ 7 - s.length()];
|
207
|
+
Arrays.fill(zeros, '0');
|
208
|
+
s += new String(zeros) + Math.min(i, 1);
|
209
|
+
int t = Integer.parseInt(new StringBuffer(s).reverse().toString(), 2);
|
212
210
|
this.writeInt8(t, out);
|
213
211
|
}
|
214
212
|
}
|
@@ -222,7 +220,7 @@ abstract class Divine <%= toplevel_class %> {
|
|
222
220
|
if (bs.length > 0xFFFF) {
|
223
221
|
raiseError("Too large string: " + bs.length + " bytes");
|
224
222
|
}
|
225
|
-
|
223
|
+
writeDint63(bs.length, out);
|
226
224
|
out.write(bs);
|
227
225
|
}
|
228
226
|
|
@@ -230,7 +228,7 @@ abstract class Divine <%= toplevel_class %> {
|
|
230
228
|
if (v.length > 0xFFFFFFFFL) {
|
231
229
|
raiseError("Too large binary: " + v.length + " bytes");
|
232
230
|
}
|
233
|
-
|
231
|
+
writeDint63(v.length, out);
|
234
232
|
out.write(v);
|
235
233
|
}
|
236
234
|
|
@@ -245,14 +243,6 @@ abstract class Divine <%= toplevel_class %> {
|
|
245
243
|
}
|
246
244
|
}
|
247
245
|
|
248
|
-
protected void writeShortBinary(byte[] v, ByteArrayOutputStream out) throws IOException {
|
249
|
-
if (v.length > 0xFF) {
|
250
|
-
raiseError("Too large short_binary: " + v.length + " bytes");
|
251
|
-
}
|
252
|
-
writeInt8(v.length, out);
|
253
|
-
out.write(v);
|
254
|
-
}
|
255
|
-
|
256
246
|
protected void writeIpNumber(String v, ByteArrayOutputStream out) throws IOException {
|
257
247
|
if(v.contains(":")){
|
258
248
|
writeIpv6Number( v, out);
|
@@ -271,7 +261,8 @@ abstract class Divine <%= toplevel_class %> {
|
|
271
261
|
}
|
272
262
|
}
|
273
263
|
if (ss.length == 0 || ss.length == 4) {
|
274
|
-
|
264
|
+
writeInt8(ss.length, out);
|
265
|
+
out.write(ss);
|
275
266
|
} else {
|
276
267
|
raiseError("Unknown IP v4 number " + v); // Only IPv4 for now
|
277
268
|
}
|
@@ -423,7 +414,6 @@ EOS
|
|
423
414
|
# * string --> ""
|
424
415
|
# * ip_number--> ""
|
425
416
|
# * binary --> new Byte[0]
|
426
|
-
# * short_binary --> new Byte[0]
|
427
417
|
# * list --> new ArrayList<type>()
|
428
418
|
# * map --> new HashMap<keyType, valueType>()
|
429
419
|
|
@@ -446,7 +436,7 @@ EOS
|
|
446
436
|
|
447
437
|
else
|
448
438
|
case types
|
449
|
-
when :binary
|
439
|
+
when :binary
|
450
440
|
is_reference_type ? "new Byte[0]" : "new byte[0]"
|
451
441
|
when :int8, :int16, :sint32
|
452
442
|
"0"
|
@@ -454,6 +444,8 @@ EOS
|
|
454
444
|
"0L"
|
455
445
|
when :string, :ip_number
|
456
446
|
"\"\""
|
447
|
+
when :bool
|
448
|
+
false
|
457
449
|
else
|
458
450
|
if $all_structs[types]
|
459
451
|
types
|
@@ -476,7 +468,6 @@ EOS
|
|
476
468
|
# * string --> String
|
477
469
|
# * ip_number--> String
|
478
470
|
# * binary --> Byte[]
|
479
|
-
# * short_binary --> Byte[]
|
480
471
|
# * list --> ArrayList<type>
|
481
472
|
# * map --> HashMap<keyType, valueType>
|
482
473
|
|
@@ -502,7 +493,7 @@ EOS
|
|
502
493
|
|
503
494
|
else
|
504
495
|
case types
|
505
|
-
when :binary
|
496
|
+
when :binary
|
506
497
|
is_reference_type ? "Byte[]" : "byte[]"
|
507
498
|
when :int8, :int16, :sint32
|
508
499
|
is_reference_type ? "Integer" : "int"
|
@@ -510,6 +501,8 @@ EOS
|
|
510
501
|
is_reference_type ? "Long" : "long"
|
511
502
|
when :string, :ip_number
|
512
503
|
"String"
|
504
|
+
when :bool
|
505
|
+
"boolean"
|
513
506
|
else
|
514
507
|
if $all_structs[types]
|
515
508
|
types
|
@@ -532,7 +525,7 @@ EOS
|
|
532
525
|
nv = get_fresh_variable_name
|
533
526
|
idx = get_fresh_variable_name
|
534
527
|
return [
|
535
|
-
"
|
528
|
+
"writeDint63(#{var}.size(), baos);",
|
536
529
|
"for(int #{idx}=0; #{idx}<#{var}.size(); #{idx}++) {",
|
537
530
|
:indent,
|
538
531
|
"#{java_get_type_declaration types[1]} #{nv} = #{var}.get(#{idx});",
|
@@ -544,7 +537,7 @@ EOS
|
|
544
537
|
nv1 = get_fresh_variable_name
|
545
538
|
nv2 = get_fresh_variable_name
|
546
539
|
return [
|
547
|
-
"
|
540
|
+
"writeDint63(#{var}.size(), baos);",
|
548
541
|
"for(#{java_get_type_declaration types[1]} #{nv1} : #{var}.keySet()) {",
|
549
542
|
:indent,
|
550
543
|
"#{java_get_type_declaration types[2]} #{nv2} = #{var}.get(#{nv1});",
|
@@ -583,7 +576,7 @@ EOS
|
|
583
576
|
iter = get_fresh_variable_name
|
584
577
|
return [
|
585
578
|
"#{"#{java_get_type_declaration(types)} " unless var.include? "this."}#{var} = #{java_get_empty_declaration(types)};",
|
586
|
-
"int #{count} = (int)this.
|
579
|
+
"int #{count} = (int)this.readDint63(bais);",
|
587
580
|
"for(int #{iter}=0; #{iter}<#{count}; #{iter}++) {",
|
588
581
|
:indent,
|
589
582
|
java_deserialize_internal(nv, types[1]),
|
@@ -597,7 +590,7 @@ EOS
|
|
597
590
|
nv2 = get_fresh_variable_name
|
598
591
|
iter = get_fresh_variable_name
|
599
592
|
return ["#{"#{java_get_type_declaration(types)} " unless var.include? "this."}#{var} = #{java_get_empty_declaration(types)};",
|
600
|
-
"int #{count} = (int)
|
593
|
+
"int #{count} = (int)readDint63(bais);",
|
601
594
|
"for(int #{iter}=0; #{iter}<#{count}; #{iter}++) {",
|
602
595
|
:indent,
|
603
596
|
java_deserialize_internal(nv1, types[1]),
|
@@ -684,6 +677,7 @@ EOS
|
|
684
677
|
"java.io.ByteArrayOutputStream",
|
685
678
|
"java.io.IOException",
|
686
679
|
"java.util.ArrayList",
|
680
|
+
"java.util.Arrays",
|
687
681
|
"java.util.HashMap",
|
688
682
|
"java.util.regex.Pattern",
|
689
683
|
"java.nio.charset.Charset"
|
@@ -150,16 +150,16 @@ DivineHelper.prototype.read_dint63 = function (data) {
|
|
150
150
|
return val;
|
151
151
|
}
|
152
152
|
|
153
|
-
DivineHelper.prototype.
|
154
|
-
return
|
155
|
-
}
|
153
|
+
DivineHelper.prototype.read_bool = function (data) {
|
154
|
+
return this.read_int8(data) == 1;
|
155
|
+
}
|
156
156
|
|
157
|
-
DivineHelper.prototype.
|
158
|
-
return data.read(this.
|
157
|
+
DivineHelper.prototype.read_binary = function (data) {
|
158
|
+
return data.read(this.read_dint63(data));
|
159
159
|
};
|
160
160
|
|
161
161
|
DivineHelper.prototype.read_ip_number = function (data) {
|
162
|
-
var ip_array = this.
|
162
|
+
var ip_array = data.read(this.read_int8(data));
|
163
163
|
if(ip_array.length == 4){
|
164
164
|
return this.read_ipv4_number(ip_array);
|
165
165
|
}else{
|
@@ -194,7 +194,7 @@ DivineHelper.prototype.read_ipv6_number = function (ip_array) {
|
|
194
194
|
};
|
195
195
|
|
196
196
|
DivineHelper.prototype.read_string = function (data) {
|
197
|
-
return this.decode_utf8(data.read(this.
|
197
|
+
return this.decode_utf8(data.read(this.read_dint63(data)))
|
198
198
|
};
|
199
199
|
|
200
200
|
DivineHelper.prototype.write_int8 = function (v, out) {
|
@@ -290,18 +290,18 @@ DivineHelper.prototype.write_bool = function (v, out) {
|
|
290
290
|
DivineHelper.prototype.write_string = function (v, out) {
|
291
291
|
var s = this.encode_utf8(v);
|
292
292
|
if (s.length > 0xFFFF) this.raise_error("Too large string: " + s.length + " bytes");
|
293
|
-
this.
|
293
|
+
this.write_dint63(s.length, out);
|
294
294
|
out.write(s);
|
295
295
|
}
|
296
296
|
|
297
297
|
DivineHelper.prototype.write_binary = function (v, out) {
|
298
298
|
if ((v instanceof Array) || (v instanceof Uint8Array)) {
|
299
299
|
if (v.length > 0xFFFFFFFF) this.raise_error("Too large binary: " + v.length + " (" + v.constructor.name + ")");
|
300
|
-
this.
|
300
|
+
this.write_dint63(v.length, out)
|
301
301
|
out.write(v);
|
302
302
|
} else if (v.constructor == String) {
|
303
303
|
if (v.length > 0xFFFFFFFF) this.raise_error("Too large binary: " + v.length + " (" + v.constructor.name + ")");
|
304
|
-
this.
|
304
|
+
this.write_dint63(v.length, out)
|
305
305
|
out.write(v);
|
306
306
|
} else if (v == null) {
|
307
307
|
this.raise_error("Unsupported binary 'null'");
|
@@ -325,22 +325,6 @@ DivineHelper.prototype.write_16_binary = function (v, out) {
|
|
325
325
|
}
|
326
326
|
}
|
327
327
|
|
328
|
-
DivineHelper.prototype.write_short_binary = function (v, out) {
|
329
|
-
if ((v instanceof Array) || (v instanceof Uint8Array)) {
|
330
|
-
if (v.length > 0xFF) this.raise_error("Too large binary: " + v.length + " (" + v.constructor.name + ")");
|
331
|
-
this.write_int8(v.length, out)
|
332
|
-
out.write(v);
|
333
|
-
} else if (v.constructor == String) {
|
334
|
-
if (v.length > 0xFF) this.raise_error("Too large binary: " + v.length + " (" + v.constructor.name + ")");
|
335
|
-
this.write_int8(v.length, out)
|
336
|
-
out.write(v);
|
337
|
-
} else if (v == null) {
|
338
|
-
this.raise_error("Unsupported binary 'null'");
|
339
|
-
} else {
|
340
|
-
this.raise_error("Unsupported binary of type '" + v.constructor.name + "'");
|
341
|
-
}
|
342
|
-
}
|
343
|
-
|
344
328
|
DivineHelper.prototype.write_ip_number = function (v, out) {
|
345
329
|
if ((v instanceof Array) || (v instanceof Uint8Array)){
|
346
330
|
if(v.length == 4){
|
@@ -362,7 +346,8 @@ DivineHelper.prototype.write_ip_number = function (v, out) {
|
|
362
346
|
DivineHelper.prototype.write_ipv4_number = function (v, out) {
|
363
347
|
if ((v instanceof Array) || (v instanceof Uint8Array)) {
|
364
348
|
if (v.length != 4 && v.length != 0) this.raise_error("Unknown IP v4 number " + v);
|
365
|
-
this.
|
349
|
+
this.write_int8(v.length, out)
|
350
|
+
out.write(v);
|
366
351
|
} else if (v.constructor == String) {
|
367
352
|
var ss = [];
|
368
353
|
if (v.length > 0) {
|
@@ -615,13 +600,12 @@ EOS
|
|
615
600
|
# * string --> ""
|
616
601
|
# * ip_number--> ""
|
617
602
|
# * binary --> []
|
618
|
-
# * short_binary --> []
|
619
603
|
# * list --> []
|
620
604
|
# * map --> {}
|
621
605
|
|
622
606
|
def javascript_get_empty_declaration(field)
|
623
607
|
case field.type
|
624
|
-
when :list, :binary
|
608
|
+
when :list, :binary
|
625
609
|
"[]"
|
626
610
|
when :map
|
627
611
|
"{}"
|
@@ -629,6 +613,8 @@ EOS
|
|
629
613
|
"0"
|
630
614
|
when :string, :ip_number
|
631
615
|
"\"\""
|
616
|
+
when :bool
|
617
|
+
false
|
632
618
|
else
|
633
619
|
raise "Unkown field type #{field.type}"
|
634
620
|
end
|
@@ -647,7 +633,7 @@ EOS
|
|
647
633
|
nv = get_fresh_variable_name
|
648
634
|
idx = get_fresh_variable_name
|
649
635
|
return [
|
650
|
-
"this.
|
636
|
+
"this.write_dint63(#{var}.length, out);",
|
651
637
|
"for(var #{idx}=0; #{idx}<#{var}.length; #{idx}++) {",
|
652
638
|
:indent,
|
653
639
|
"var #{nv} = #{var}[#{idx}];",
|
@@ -662,7 +648,7 @@ EOS
|
|
662
648
|
key = get_fresh_variable_name
|
663
649
|
return [
|
664
650
|
"var #{len} = Object.keys(#{var}).length;",
|
665
|
-
"this.
|
651
|
+
"this.write_dint63(#{len}, out);",
|
666
652
|
"for(var #{nv1} in #{var}) {",
|
667
653
|
:indent,
|
668
654
|
"var #{nv2} = #{var}[#{nv1}];",
|
@@ -702,7 +688,7 @@ EOS
|
|
702
688
|
iter = get_fresh_variable_name
|
703
689
|
return [
|
704
690
|
"#{"var " unless var.include? "this."}#{var} = [];",
|
705
|
-
"var #{count} = this.
|
691
|
+
"var #{count} = this.read_dint63(data);",
|
706
692
|
"for(var #{iter}=0; #{iter}<#{count}; #{iter}++) {",
|
707
693
|
:indent,
|
708
694
|
javascript_deserialize_internal(nv, types[1]),
|
@@ -716,7 +702,7 @@ EOS
|
|
716
702
|
nv2 = get_fresh_variable_name
|
717
703
|
iter = get_fresh_variable_name
|
718
704
|
return ["#{"var " unless var.include? "this."}#{var} = {};",
|
719
|
-
"var #{count} = this.
|
705
|
+
"var #{count} = this.read_dint63(data);",
|
720
706
|
"for(var #{iter}=0; #{iter}<#{count}; #{iter}++) {",
|
721
707
|
:indent,
|
722
708
|
javascript_deserialize_internal(nv1, types[1]),
|
@@ -86,19 +86,15 @@ module Divine
|
|
86
86
|
end
|
87
87
|
|
88
88
|
def read_string(data)
|
89
|
-
data.read(
|
89
|
+
data.read(read_dint63(data)).force_encoding('UTF-8')
|
90
90
|
end
|
91
91
|
|
92
92
|
def read_binary(data)
|
93
|
-
data.read(
|
94
|
-
end
|
95
|
-
|
96
|
-
def read_short_binary(data)
|
97
|
-
data.read(read_int8(data))
|
93
|
+
data.read(read_dint63(data))
|
98
94
|
end
|
99
95
|
|
100
96
|
def read_ip_number(data)
|
101
|
-
ips =
|
97
|
+
ips = data.read(read_int8(data))
|
102
98
|
if ips.size == 4
|
103
99
|
read_ipv4_number(ips)
|
104
100
|
else
|
@@ -200,20 +196,20 @@ module Divine
|
|
200
196
|
def write_string(v, out)
|
201
197
|
s = force_to_utf8_string(v)
|
202
198
|
raise_error "Too large string: #{s.bytesize} bytes" if s.bytesize > 0xFFFF
|
203
|
-
|
199
|
+
write_dint63(s.bytesize, out)
|
204
200
|
out << s.bytes.to_a
|
205
201
|
end
|
206
202
|
|
207
203
|
def write_binary(v, out)
|
208
204
|
if v.is_a?(Array)
|
209
205
|
raise_error "Too large binary: #{v.size} (#{v.class.name})" unless v.size < 0xFFFFFFFF
|
210
|
-
|
206
|
+
write_dint63(v.size, out)
|
211
207
|
v.each do |x|
|
212
208
|
write_int8(x, out)
|
213
209
|
end
|
214
210
|
elsif v.is_a?(String)
|
215
211
|
raise_error "Too large binary: #{v.size} (#{v.class.name})" unless v.size < 0xFFFFFFFF
|
216
|
-
|
212
|
+
write_dint63(v.size, out)
|
217
213
|
out << v.bytes.to_a
|
218
214
|
else
|
219
215
|
raise_error "Unsupported binary 'nil'" if v == nil
|
@@ -234,23 +230,6 @@ module Divine
|
|
234
230
|
end
|
235
231
|
end
|
236
232
|
|
237
|
-
def write_short_binary(v, out)
|
238
|
-
if v.is_a?(Array)
|
239
|
-
raise_error "Too large short_binary: #{v.size} (#{v.class.name})" unless v.size < 0xFF
|
240
|
-
write_int8(v.size, out)
|
241
|
-
v.each do |x|
|
242
|
-
write_int8(x, out)
|
243
|
-
end
|
244
|
-
elsif v.is_a?(String)
|
245
|
-
raise_error "To large short_binary: #{v.size} (#{v.class.name})" unless v.size < 0xFF
|
246
|
-
write_int8(v.size, out)
|
247
|
-
out << v.bytes.to_a
|
248
|
-
else
|
249
|
-
raise_error "Unsupported binary 'nil'" if v == nil
|
250
|
-
raise_error "Unsupported binary of type '#{v.class.name}'"
|
251
|
-
end
|
252
|
-
end
|
253
|
-
|
254
233
|
def write_ip_number(v, out)
|
255
234
|
if v.is_a?(Array)
|
256
235
|
if v.size == 4
|
@@ -272,7 +251,10 @@ module Divine
|
|
272
251
|
def write_ipv4_number(v,out)
|
273
252
|
if v.is_a?(Array)
|
274
253
|
raise_error "Unknown IP v4 number #{v}" unless v.size == 0 || v.size == 4 # Only IPv4 for now
|
275
|
-
|
254
|
+
write_int8(v.size, out)
|
255
|
+
v.each do |x|
|
256
|
+
write_int8(x, out)
|
257
|
+
end
|
276
258
|
elsif v.is_a?(String)
|
277
259
|
ss = v.split(/\./).map do |s|
|
278
260
|
s.to_i
|
@@ -431,13 +413,12 @@ module Divine
|
|
431
413
|
# * string --> ""
|
432
414
|
# * ip_number--> ""
|
433
415
|
# * binary --> []
|
434
|
-
# * short_binary --> []
|
435
416
|
# * list --> []
|
436
417
|
# * map --> {}
|
437
418
|
|
438
419
|
def ruby_get_empty_declaration(field)
|
439
420
|
case field.type
|
440
|
-
when :list, :binary
|
421
|
+
when :list, :binary
|
441
422
|
"[]"
|
442
423
|
when :map
|
443
424
|
"{}"
|
@@ -445,6 +426,8 @@ module Divine
|
|
445
426
|
"0"
|
446
427
|
when :string, :ip_number
|
447
428
|
"\"\""
|
429
|
+
when :bool
|
430
|
+
false
|
448
431
|
else
|
449
432
|
raise "Unkown field type #{field.type}"
|
450
433
|
end
|
@@ -462,7 +445,7 @@ module Divine
|
|
462
445
|
when :list
|
463
446
|
nv = get_fresh_variable_name
|
464
447
|
return [
|
465
|
-
"
|
448
|
+
"write_dint63(#{var}.size, out)",
|
466
449
|
"#{var}.each do |#{nv}|",
|
467
450
|
:indent,
|
468
451
|
ruby_serialize_internal(nv, types[1]),
|
@@ -473,7 +456,7 @@ module Divine
|
|
473
456
|
nv1 = get_fresh_variable_name
|
474
457
|
nv2 = get_fresh_variable_name
|
475
458
|
return [
|
476
|
-
"
|
459
|
+
"write_dint63(#{var}.size, out)",
|
477
460
|
"#{var}.each_pair do |#{nv1}, #{nv2}|",
|
478
461
|
:indent,
|
479
462
|
ruby_serialize_internal(nv1, types[1]),
|
@@ -511,7 +494,7 @@ module Divine
|
|
511
494
|
nv = get_fresh_variable_name
|
512
495
|
return [
|
513
496
|
"#{var} = []",
|
514
|
-
"#{count} =
|
497
|
+
"#{count} = read_dint63(data)",
|
515
498
|
"(1..#{count}).each do",
|
516
499
|
:indent,
|
517
500
|
ruby_deserialize_internal(nv, types[1]),
|
@@ -524,7 +507,7 @@ module Divine
|
|
524
507
|
nv1 = get_fresh_variable_name
|
525
508
|
nv2 = get_fresh_variable_name
|
526
509
|
return ["#{var} = {}",
|
527
|
-
"#{count} =
|
510
|
+
"#{count} = read_dint63(data)",
|
528
511
|
"(1..#{count}).each do",
|
529
512
|
:indent,
|
530
513
|
ruby_deserialize_internal(nv1, types[1]),
|