erlang_rb 2.0.4 → 2.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.markdown +4 -4
- data/lib/erlang.rb +134 -96
- data/tests/erlang_tests.rb +81 -10
- data.tar.gz.sig +0 -0
- metadata +25 -25
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb447b6bd939e85f7064d8f8bb2dc8c9c9760dd85176aa03faa2f71b80d399af
|
4
|
+
data.tar.gz: 7e44a500d2f09968376420c89a3009299000751c7944e8c34dab65bab65dc364
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64da30400b66241b3742fe4e05f37c10c8fcf17b01380989d268e11640c5d91a069a37fe965d6b51dcd5ed820cc21cf94ffdd152dcc77d5003c866c7d446bcec
|
7
|
+
data.tar.gz: 934690e36553ff1c20eb4de1f1d5d0cc7893d4181e46738792b59238d731bc047e3a72827db6fec30047dbc372ea94878e62edecd3e87d934312a709138d0d6d
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.markdown
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
Erlang
|
2
|
-
|
1
|
+
Erlang External Term Format for Ruby
|
2
|
+
====================================
|
3
3
|
|
4
|
-
[![Build Status](https://
|
4
|
+
[![Build Status](https://app.travis-ci.com/okeuday/erlang_rb.svg?branch=master)](https://app.travis-ci.com/okeuday/erlang_rb)
|
5
5
|
|
6
|
-
Provides all encoding and decoding for the Erlang
|
6
|
+
Provides all encoding and decoding for the Erlang External Term Format
|
7
7
|
(as defined at [http://erlang.org/doc/apps/erts/erl_ext_dist.html](http://erlang.org/doc/apps/erts/erl_ext_dist.html))
|
8
8
|
in a single Ruby module.
|
9
9
|
|
data/lib/erlang.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# MIT License
|
5
5
|
#
|
6
|
-
# Copyright (c) 2011-
|
6
|
+
# Copyright (c) 2011-2023 Michael Truog <mjtruog at protonmail dot com>
|
7
7
|
#
|
8
8
|
# Permission is hereby granted, free of charge, to any person obtaining a
|
9
9
|
# copy of this software and associated documentation files (the "Software"),
|
@@ -25,11 +25,14 @@
|
|
25
25
|
#
|
26
26
|
|
27
27
|
require 'zlib'
|
28
|
+
require 'set'
|
28
29
|
|
29
30
|
# Erlang term classes listed alphabetically
|
30
31
|
|
31
32
|
module Erlang
|
32
33
|
|
34
|
+
@@UNDEFINED = 'undefined' # Change with set_undefined
|
35
|
+
|
33
36
|
class OtpErlangAtom
|
34
37
|
def initialize(value)
|
35
38
|
@value = value
|
@@ -52,6 +55,8 @@ module Erlang
|
|
52
55
|
raise OutputException, 'uint16 overflow', caller
|
53
56
|
end
|
54
57
|
else
|
58
|
+
# deprecated
|
59
|
+
# (not used in Erlang/OTP 26, i.e., minor_version 2)
|
55
60
|
if length <= 255
|
56
61
|
return "#{TAG_SMALL_ATOM_EXT.chr}#{length.chr}#{@value}"
|
57
62
|
elsif length <= 65535
|
@@ -76,7 +81,7 @@ module Erlang
|
|
76
81
|
end
|
77
82
|
alias eql? ==
|
78
83
|
end
|
79
|
-
|
84
|
+
|
80
85
|
class OtpErlangBinary
|
81
86
|
def initialize(value, bits = 8)
|
82
87
|
@value = value
|
@@ -112,29 +117,7 @@ module Erlang
|
|
112
117
|
end
|
113
118
|
alias eql? ==
|
114
119
|
end
|
115
|
-
|
116
|
-
class OtpErlangFunction
|
117
|
-
def initialize(tag, value)
|
118
|
-
@tag = tag
|
119
|
-
@value = value
|
120
|
-
end
|
121
|
-
attr_reader :tag
|
122
|
-
attr_reader :value
|
123
|
-
def binary
|
124
|
-
return "#{@tag.chr}#{@value}"
|
125
|
-
end
|
126
|
-
def to_s
|
127
|
-
return "#{self.class.name}('#{@tag.to_s}','#{@value.to_s}')"
|
128
|
-
end
|
129
|
-
def hash
|
130
|
-
return binary.hash
|
131
|
-
end
|
132
|
-
def ==(other)
|
133
|
-
return binary == other.binary
|
134
|
-
end
|
135
|
-
alias eql? ==
|
136
|
-
end
|
137
|
-
|
120
|
+
|
138
121
|
class OtpErlangList
|
139
122
|
def initialize(value, improper = false)
|
140
123
|
@value = value
|
@@ -216,7 +199,7 @@ module Erlang
|
|
216
199
|
end
|
217
200
|
alias eql? ==
|
218
201
|
end
|
219
|
-
|
202
|
+
|
220
203
|
class OtpErlangPort
|
221
204
|
def initialize(node, id, creation)
|
222
205
|
@node = node
|
@@ -227,13 +210,18 @@ module Erlang
|
|
227
210
|
attr_reader :id
|
228
211
|
attr_reader :creation
|
229
212
|
def binary
|
230
|
-
|
231
|
-
if
|
232
|
-
return "#{
|
213
|
+
id_size = @id.bytesize
|
214
|
+
if id_size == 8
|
215
|
+
return "#{TAG_V4_PORT_EXT.chr}" \
|
233
216
|
"#{@node.binary}#{@id}#{@creation}"
|
234
|
-
|
217
|
+
end
|
218
|
+
creation_size = @creation.bytesize
|
219
|
+
if creation_size == 4
|
235
220
|
return "#{TAG_NEW_PORT_EXT.chr}" \
|
236
221
|
"#{@node.binary}#{@id}#{@creation}"
|
222
|
+
elsif creation_size == 1
|
223
|
+
return "#{TAG_PORT_EXT.chr}" \
|
224
|
+
"#{@node.binary}#{@id}#{@creation}"
|
237
225
|
else
|
238
226
|
raise OutputException, 'unknown port type', caller
|
239
227
|
end
|
@@ -250,7 +238,7 @@ module Erlang
|
|
250
238
|
end
|
251
239
|
alias eql? ==
|
252
240
|
end
|
253
|
-
|
241
|
+
|
254
242
|
class OtpErlangReference
|
255
243
|
def initialize(node, id, creation)
|
256
244
|
@node = node
|
@@ -294,8 +282,30 @@ module Erlang
|
|
294
282
|
alias eql? ==
|
295
283
|
end
|
296
284
|
|
285
|
+
class OtpErlangFunction
|
286
|
+
def initialize(tag, value)
|
287
|
+
@tag = tag
|
288
|
+
@value = value
|
289
|
+
end
|
290
|
+
attr_reader :tag
|
291
|
+
attr_reader :value
|
292
|
+
def binary
|
293
|
+
return "#{@tag.chr}#{@value}"
|
294
|
+
end
|
295
|
+
def to_s
|
296
|
+
return "#{self.class.name}('#{@tag.to_s}','#{@value.to_s}')"
|
297
|
+
end
|
298
|
+
def hash
|
299
|
+
return binary.hash
|
300
|
+
end
|
301
|
+
def ==(other)
|
302
|
+
return binary == other.binary
|
303
|
+
end
|
304
|
+
alias eql? ==
|
305
|
+
end
|
306
|
+
|
297
307
|
# core functionality
|
298
|
-
|
308
|
+
|
299
309
|
def self.binary_to_term(data)
|
300
310
|
size = data.bytesize
|
301
311
|
if size <= 1
|
@@ -318,7 +328,7 @@ module Erlang
|
|
318
328
|
raise ParseException, 'missing data', e.backtrace
|
319
329
|
end
|
320
330
|
end
|
321
|
-
|
331
|
+
|
322
332
|
def self.term_to_binary(term, compressed = false)
|
323
333
|
data_uncompressed = term_to_binary_(term)
|
324
334
|
if compressed == false
|
@@ -341,11 +351,16 @@ module Erlang
|
|
341
351
|
"#{size_uncompressed_packed}#{data_compressed}"
|
342
352
|
end
|
343
353
|
end
|
344
|
-
|
354
|
+
|
355
|
+
# Elixir use can set to 'nil'
|
356
|
+
def self.set_undefined(value)
|
357
|
+
@@UNDEFINED = value
|
358
|
+
end
|
359
|
+
|
345
360
|
private
|
346
|
-
|
361
|
+
|
347
362
|
# binary_to_term implementation functions
|
348
|
-
|
363
|
+
|
349
364
|
def self.binary_to_term_(i, data)
|
350
365
|
tag = data[i].ord
|
351
366
|
i += 1
|
@@ -370,22 +385,18 @@ module Erlang
|
|
370
385
|
elsif tag == TAG_FLOAT_EXT
|
371
386
|
value = data[i,31].partition(0.chr)[0].to_f
|
372
387
|
return [i + 31, value]
|
373
|
-
elsif
|
374
|
-
|
375
|
-
i += 2
|
376
|
-
atom_name = data[i,j].force_encoding('ISO-8859-1')
|
377
|
-
if atom_name.valid_encoding?
|
378
|
-
return [i + j, atom_name.to_sym]
|
379
|
-
else
|
380
|
-
raise ParseException, 'invalid atom_name latin1', caller
|
381
|
-
end
|
382
|
-
elsif tag == TAG_NEW_PORT_EXT or \
|
383
|
-
tag == TAG_REFERENCE_EXT or tag == TAG_PORT_EXT
|
388
|
+
elsif Set[TAG_V4_PORT_EXT,TAG_NEW_PORT_EXT,
|
389
|
+
TAG_REFERENCE_EXT,TAG_PORT_EXT].include?(tag)
|
384
390
|
result = binary_to_atom(i, data)
|
385
391
|
i = result[0]; node = result[1]
|
386
|
-
|
387
|
-
|
388
|
-
|
392
|
+
if tag == TAG_V4_PORT_EXT
|
393
|
+
id = data[i,8]
|
394
|
+
i += 8
|
395
|
+
else
|
396
|
+
id = data[i,4]
|
397
|
+
i += 4
|
398
|
+
end
|
399
|
+
if Set[TAG_V4_PORT_EXT,TAG_NEW_PORT_EXT].include?(tag)
|
389
400
|
creation = data[i,4]
|
390
401
|
i += 4
|
391
402
|
else
|
@@ -395,9 +406,10 @@ module Erlang
|
|
395
406
|
return [i, OtpErlangReference.new(node, id, creation)]
|
396
407
|
end
|
397
408
|
end
|
398
|
-
# tag ==
|
409
|
+
# tag == TAG_V4_PORT_EXT or tag == TAG_NEW_PORT_EXT or
|
410
|
+
# tag == TAG_PORT_EXT
|
399
411
|
return [i, OtpErlangPort.new(node, id, creation)]
|
400
|
-
elsif
|
412
|
+
elsif Set[TAG_NEW_PID_EXT, TAG_PID_EXT].include?(tag)
|
401
413
|
result = binary_to_atom(i, data)
|
402
414
|
i = result[0]; node = result[1]
|
403
415
|
id = data[i,4]
|
@@ -412,7 +424,7 @@ module Erlang
|
|
412
424
|
i += 1
|
413
425
|
end
|
414
426
|
return [i, OtpErlangPid.new(node, id, serial, creation)]
|
415
|
-
elsif
|
427
|
+
elsif Set[TAG_SMALL_TUPLE_EXT, TAG_LARGE_TUPLE_EXT].include?(tag)
|
416
428
|
if tag == TAG_SMALL_TUPLE_EXT
|
417
429
|
length = data[i].ord
|
418
430
|
i += 1
|
@@ -447,7 +459,7 @@ module Erlang
|
|
447
459
|
j = data[i,4].unpack('N')[0]
|
448
460
|
i += 4
|
449
461
|
return [i + j, OtpErlangBinary.new(data[i,j], 8)]
|
450
|
-
elsif
|
462
|
+
elsif Set[TAG_SMALL_BIG_EXT, TAG_LARGE_BIG_EXT].include?(tag)
|
451
463
|
if tag == TAG_SMALL_BIG_EXT
|
452
464
|
j = data[i].ord
|
453
465
|
i += 1
|
@@ -482,7 +494,7 @@ module Erlang
|
|
482
494
|
#arity = data[i].ord
|
483
495
|
i += 1
|
484
496
|
return [i, OtpErlangFunction.new(tag, data[old_i,i - old_i])]
|
485
|
-
elsif
|
497
|
+
elsif Set[TAG_NEWER_REFERENCE_EXT, TAG_NEW_REFERENCE_EXT].include?(tag)
|
486
498
|
j = data[i,2].unpack('n')[0] * 4
|
487
499
|
i += 2
|
488
500
|
result = binary_to_atom(i, data)
|
@@ -496,22 +508,6 @@ module Erlang
|
|
496
508
|
end
|
497
509
|
id = data[i,j]
|
498
510
|
return [i + j, OtpErlangReference.new(node, id, creation)]
|
499
|
-
elsif tag == TAG_SMALL_ATOM_EXT
|
500
|
-
j = data[i,1].ord
|
501
|
-
i += 1
|
502
|
-
atom_name = data[i,j].force_encoding('ISO-8859-1')
|
503
|
-
if atom_name.valid_encoding?
|
504
|
-
if atom_name == 'true'
|
505
|
-
tmp = true
|
506
|
-
elsif atom_name == 'false'
|
507
|
-
tmp = false
|
508
|
-
else
|
509
|
-
tmp = atom_name.to_sym
|
510
|
-
end
|
511
|
-
return [i + j, tmp]
|
512
|
-
else
|
513
|
-
raise ParseException, 'invalid atom_name latin1', caller
|
514
|
-
end
|
515
511
|
elsif tag == TAG_MAP_EXT
|
516
512
|
length = data[i,4].unpack('N')[0]
|
517
513
|
i += 4
|
@@ -539,23 +535,61 @@ module Erlang
|
|
539
535
|
result = binary_to_term_sequence(i, numfree, data)
|
540
536
|
i = result[0]#; free = result[1]
|
541
537
|
return [i, OtpErlangFunction.new(tag, data[old_i,i - old_i])]
|
542
|
-
elsif tag
|
538
|
+
elsif Set[TAG_ATOM_UTF8_EXT, TAG_ATOM_EXT].include?(tag)
|
543
539
|
j = data[i,2].unpack('n')[0]
|
544
540
|
i += 2
|
545
|
-
atom_name = data[i,j]
|
546
|
-
|
547
|
-
|
541
|
+
atom_name = data[i,j]
|
542
|
+
i = i + j
|
543
|
+
if atom_name == 'true'
|
544
|
+
return [i, true]
|
545
|
+
elsif atom_name == 'false'
|
546
|
+
return [i, false]
|
547
|
+
elsif atom_name == @@UNDEFINED
|
548
|
+
return [i, nil]
|
548
549
|
else
|
549
|
-
|
550
|
+
if tag == TAG_ATOM_UTF8_EXT
|
551
|
+
atom_name = atom_name.force_encoding('UTF-8')
|
552
|
+
if atom_name.valid_encoding?
|
553
|
+
return [i, atom_name.to_sym]
|
554
|
+
else
|
555
|
+
raise ParseException, 'invalid atom_name unicode', caller
|
556
|
+
end
|
557
|
+
else
|
558
|
+
atom_name = atom_name.force_encoding('ISO-8859-1')
|
559
|
+
if atom_name.valid_encoding?
|
560
|
+
return [i, OtpErlangAtom.new(atom_name)]
|
561
|
+
else
|
562
|
+
raise ParseException, 'invalid atom_name latin1', caller
|
563
|
+
end
|
564
|
+
end
|
550
565
|
end
|
551
|
-
elsif tag
|
566
|
+
elsif Set[TAG_SMALL_ATOM_UTF8_EXT, TAG_SMALL_ATOM_EXT].include?(tag)
|
552
567
|
j = data[i,1].ord
|
553
568
|
i += 1
|
554
|
-
atom_name = data[i,j]
|
555
|
-
|
556
|
-
|
569
|
+
atom_name = data[i,j]
|
570
|
+
i = i + j
|
571
|
+
if atom_name == 'true'
|
572
|
+
return [i, true]
|
573
|
+
elsif atom_name == 'false'
|
574
|
+
return [i, false]
|
575
|
+
elsif atom_name == @@UNDEFINED
|
576
|
+
return [i, nil]
|
557
577
|
else
|
558
|
-
|
578
|
+
if tag == TAG_SMALL_ATOM_UTF8_EXT
|
579
|
+
atom_name = atom_name.force_encoding('UTF-8')
|
580
|
+
if atom_name.valid_encoding?
|
581
|
+
return [i, atom_name.to_sym]
|
582
|
+
else
|
583
|
+
raise ParseException, 'invalid atom_name unicode', caller
|
584
|
+
end
|
585
|
+
else
|
586
|
+
atom_name = atom_name.force_encoding('ISO-8859-1')
|
587
|
+
if atom_name.valid_encoding?
|
588
|
+
return [i, OtpErlangAtom.new(atom_name)]
|
589
|
+
else
|
590
|
+
raise ParseException, 'invalid atom_name latin1', caller
|
591
|
+
end
|
592
|
+
end
|
559
593
|
end
|
560
594
|
elsif tag == TAG_COMPRESSED_ZLIB
|
561
595
|
size_uncompressed = data[i,4].unpack('N')[0]
|
@@ -575,11 +609,13 @@ module Erlang
|
|
575
609
|
raise ParseException, 'unparsed data', caller
|
576
610
|
end
|
577
611
|
return [i + j, term]
|
612
|
+
elsif tag == TAG_LOCAL_EXT
|
613
|
+
raise ParseException, 'LOCAL_EXT is opaque', caller
|
578
614
|
else
|
579
615
|
raise ParseException, 'invalid tag', caller
|
580
616
|
end
|
581
617
|
end
|
582
|
-
|
618
|
+
|
583
619
|
def self.binary_to_term_sequence(i, length, data)
|
584
620
|
sequence = []
|
585
621
|
(0...length).each do |length_index|
|
@@ -591,7 +627,7 @@ module Erlang
|
|
591
627
|
end
|
592
628
|
|
593
629
|
# (binary_to_term Erlang term primitive type functions)
|
594
|
-
|
630
|
+
|
595
631
|
def self.binary_to_integer(i, data)
|
596
632
|
tag = data[i].ord
|
597
633
|
i += 1
|
@@ -607,7 +643,7 @@ module Erlang
|
|
607
643
|
raise ParseException, 'invalid integer tag', caller
|
608
644
|
end
|
609
645
|
end
|
610
|
-
|
646
|
+
|
611
647
|
def self.binary_to_pid(i, data)
|
612
648
|
tag = data[i].ord
|
613
649
|
i += 1
|
@@ -635,7 +671,7 @@ module Erlang
|
|
635
671
|
raise ParseException, 'invalid pid tag', caller
|
636
672
|
end
|
637
673
|
end
|
638
|
-
|
674
|
+
|
639
675
|
def self.binary_to_atom(i, data)
|
640
676
|
tag = data[i].ord
|
641
677
|
i += 1
|
@@ -671,9 +707,9 @@ module Erlang
|
|
671
707
|
raise ParseException, 'invalid atom tag', caller
|
672
708
|
end
|
673
709
|
end
|
674
|
-
|
710
|
+
|
675
711
|
# term_to_binary implementation functions
|
676
|
-
|
712
|
+
|
677
713
|
def self.term_to_binary_(term)
|
678
714
|
if term.kind_of?(String)
|
679
715
|
return string_to_binary(term)
|
@@ -689,15 +725,15 @@ module Erlang
|
|
689
725
|
return OtpErlangAtom.new(term.to_s).binary
|
690
726
|
elsif term.kind_of?(TrueClass)
|
691
727
|
return OtpErlangAtom.new(
|
692
|
-
'true'.force_encoding('
|
728
|
+
'true'.force_encoding('UTF-8')
|
693
729
|
).binary
|
694
730
|
elsif term.kind_of?(FalseClass)
|
695
731
|
return OtpErlangAtom.new(
|
696
|
-
'false'.force_encoding('
|
732
|
+
'false'.force_encoding('UTF-8')
|
697
733
|
).binary
|
698
734
|
elsif term.nil?
|
699
735
|
return OtpErlangAtom.new(
|
700
|
-
|
736
|
+
@@UNDEFINED.force_encoding('UTF-8')
|
701
737
|
).binary
|
702
738
|
elsif term.kind_of?(OtpErlangAtom)
|
703
739
|
return term.binary
|
@@ -719,7 +755,7 @@ module Erlang
|
|
719
755
|
end
|
720
756
|
|
721
757
|
# (term_to_binary Erlang term composite type functions)
|
722
|
-
|
758
|
+
|
723
759
|
def self.string_to_binary(term)
|
724
760
|
length = term.bytesize
|
725
761
|
if length == 0
|
@@ -738,7 +774,7 @@ module Erlang
|
|
738
774
|
raise OutputException, 'uint32 overflow', caller
|
739
775
|
end
|
740
776
|
end
|
741
|
-
|
777
|
+
|
742
778
|
def self.tuple_to_binary(term)
|
743
779
|
length = term.length
|
744
780
|
term_packed = term.map{ |element|
|
@@ -753,7 +789,7 @@ module Erlang
|
|
753
789
|
raise OutputException, 'uint32 overflow', caller
|
754
790
|
end
|
755
791
|
end
|
756
|
-
|
792
|
+
|
757
793
|
def self.hash_to_binary(term)
|
758
794
|
length = term.length
|
759
795
|
if length <= 4294967295
|
@@ -781,7 +817,7 @@ module Erlang
|
|
781
817
|
return bignum_to_binary(term)
|
782
818
|
end
|
783
819
|
end
|
784
|
-
|
820
|
+
|
785
821
|
def self.bignum_to_binary(term)
|
786
822
|
bignum = term.abs
|
787
823
|
if term < 0
|
@@ -811,7 +847,7 @@ module Erlang
|
|
811
847
|
end
|
812
848
|
|
813
849
|
# Exception classes listed alphabetically
|
814
|
-
|
850
|
+
|
815
851
|
class InputException < ArgumentError
|
816
852
|
end
|
817
853
|
|
@@ -820,7 +856,7 @@ module Erlang
|
|
820
856
|
|
821
857
|
class ParseException < SyntaxError
|
822
858
|
end
|
823
|
-
|
859
|
+
|
824
860
|
# tag values here http://www.erlang.org/doc/apps/erts/erl_ext_dist.html
|
825
861
|
TAG_VERSION = 131
|
826
862
|
TAG_COMPRESSED_ZLIB = 80
|
@@ -853,6 +889,8 @@ module Erlang
|
|
853
889
|
TAG_FUN_EXT = 117
|
854
890
|
TAG_ATOM_UTF8_EXT = 118
|
855
891
|
TAG_SMALL_ATOM_UTF8_EXT = 119
|
892
|
+
TAG_V4_PORT_EXT = 120
|
893
|
+
TAG_LOCAL_EXT = 121
|
856
894
|
|
857
895
|
end
|
858
896
|
|
data/tests/erlang_tests.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
#
|
5
5
|
# MIT License
|
6
6
|
#
|
7
|
-
# Copyright (c) 2014-
|
7
|
+
# Copyright (c) 2014-2023 Michael Truog <mjtruog at protonmail dot com>
|
8
8
|
# Copyright (c) 2009-2013 Dmitry Vasiliev <dima@hlabs.org>
|
9
9
|
#
|
10
10
|
# Permission is hereby granted, free of charge, to any person obtaining a
|
@@ -119,18 +119,26 @@ class DecodeTestCase < Test::Unit::TestCase
|
|
119
119
|
assert_raise(Erlang::ParseException){
|
120
120
|
Erlang::binary_to_term("\x83d\0\1")
|
121
121
|
}
|
122
|
-
assert_equal(:'', Erlang::binary_to_term("\
|
123
|
-
assert_equal(:'', Erlang::binary_to_term("\
|
124
|
-
assert_equal(:test, Erlang::binary_to_term("\
|
125
|
-
assert_equal(:test, Erlang::binary_to_term("\
|
122
|
+
assert_equal(:'', Erlang::binary_to_term("\x83v\0\0"))
|
123
|
+
assert_equal(:'', Erlang::binary_to_term("\x83w\0"))
|
124
|
+
assert_equal(:test, Erlang::binary_to_term("\x83v\0\4test"))
|
125
|
+
assert_equal(:test, Erlang::binary_to_term("\x83w\4test"))
|
126
126
|
end
|
127
127
|
def test_binary_to_term_predefined_atoms
|
128
128
|
assert_equal(true,
|
129
129
|
Erlang::binary_to_term("\x83s\4true"))
|
130
130
|
assert_equal(false,
|
131
131
|
Erlang::binary_to_term("\x83s\5false"))
|
132
|
-
assert_equal(
|
132
|
+
assert_equal(false,
|
133
|
+
Erlang::binary_to_term("\x83w\5false"))
|
134
|
+
assert_equal(nil,
|
135
|
+
Erlang::binary_to_term("\x83s\11undefined"))
|
136
|
+
assert_equal(nil,
|
137
|
+
Erlang::binary_to_term("\x83w\11undefined"))
|
138
|
+
assert_equal(nil,
|
133
139
|
Erlang::binary_to_term("\x83d\0\11undefined"))
|
140
|
+
assert_equal(nil,
|
141
|
+
Erlang::binary_to_term("\x83v\0\11undefined"))
|
134
142
|
end
|
135
143
|
def test_binary_to_term_empty_list
|
136
144
|
assert_equal(Erlang::OtpErlangList.new([]),
|
@@ -175,7 +183,7 @@ class DecodeTestCase < Test::Unit::TestCase
|
|
175
183
|
assert_raise(Erlang::ParseException){
|
176
184
|
Erlang::binary_to_term("\x83l\0\0\0\0k")
|
177
185
|
}
|
178
|
-
lst = Erlang::binary_to_term("\x83l\0\0\0\
|
186
|
+
lst = Erlang::binary_to_term("\x83l\0\0\0\1jv\0\4tail")
|
179
187
|
assert(lst.kind_of?(Erlang::OtpErlangList))
|
180
188
|
assert_equal([Erlang::OtpErlangList.new([]), :tail], lst.value)
|
181
189
|
assert_equal(true, lst.improper)
|
@@ -331,6 +339,41 @@ class DecodeTestCase < Test::Unit::TestCase
|
|
331
339
|
assert_equal(-6618611909121,
|
332
340
|
Erlang::binary_to_term("\x83o\0\0\0\6\1\1\2\3\4\5\6"))
|
333
341
|
end
|
342
|
+
def test_binary_to_term_map
|
343
|
+
assert_raise(Erlang::ParseException){
|
344
|
+
Erlang::binary_to_term("\x83t")
|
345
|
+
}
|
346
|
+
assert_raise(Erlang::ParseException){
|
347
|
+
Erlang::binary_to_term("\x83t\x00")
|
348
|
+
}
|
349
|
+
assert_raise(Erlang::ParseException){
|
350
|
+
Erlang::binary_to_term("\x83t\x00\x00")
|
351
|
+
}
|
352
|
+
assert_raise(Erlang::ParseException){
|
353
|
+
Erlang::binary_to_term("\x83t\x00\x00\x00")
|
354
|
+
}
|
355
|
+
assert_raise(Erlang::ParseException){
|
356
|
+
Erlang::binary_to_term("\x83t\x00\x00\x00\x01")
|
357
|
+
}
|
358
|
+
assert_equal({}, Erlang::binary_to_term("\x83t\x00\x00\x00\x00"))
|
359
|
+
map1 = {
|
360
|
+
Erlang::OtpErlangAtom.new("a".encode(Encoding::ISO_8859_1)) => 1
|
361
|
+
}
|
362
|
+
map1_binary = "\x83t\x00\x00\x00\x01s\x01aa\x01"
|
363
|
+
assert_equal(map1, Erlang::binary_to_term(map1_binary))
|
364
|
+
map2 = {
|
365
|
+
Erlang::OtpErlangBinary.new("\xA8", 6) =>
|
366
|
+
Erlang::OtpErlangBinary.new("everything"),
|
367
|
+
nil => Erlang::OtpErlangBinary.new("nothing")
|
368
|
+
}
|
369
|
+
map2_binary = (
|
370
|
+
"\x83\x74\x00\x00\x00\x02\x77\x09\x75\x6E\x64\x65\x66\x69" \
|
371
|
+
"\x6E\x65\x64\x6D\x00\x00\x00\x07\x6E\x6F\x74\x68\x69\x6E" \
|
372
|
+
"\x67\x4D\x00\x00\x00\x01\x06\xA8\x6D\x00\x00\x00\x0A\x65" \
|
373
|
+
"\x76\x65\x72\x79\x74\x68\x69\x6E\x67"
|
374
|
+
)
|
375
|
+
assert_equal(map2, Erlang::binary_to_term(map2_binary))
|
376
|
+
end
|
334
377
|
def test_binary_to_term_pid
|
335
378
|
pid_old_binary = (
|
336
379
|
"\x83\x67\x64\x00\x0D\x6E\x6F\x6E\x6F\x64\x65\x40\x6E\x6F" \
|
@@ -369,6 +412,13 @@ class DecodeTestCase < Test::Unit::TestCase
|
|
369
412
|
assert_equal(Erlang::term_to_binary(port_new),
|
370
413
|
"\x83Ys\rnonode@nohost\x00\x00\x00\x06" \
|
371
414
|
"\x00\x00\x00\x00")
|
415
|
+
port_v4_binary = (
|
416
|
+
"\x83\x78\x77\x0D\x6E\x6F\x6E\x6F\x64\x65\x40\x6E\x6F\x68\x6F" \
|
417
|
+
"\x73\x74\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00"
|
418
|
+
)
|
419
|
+
port_v4 = Erlang::binary_to_term(port_v4_binary)
|
420
|
+
assert(port_v4.kind_of?(Erlang::OtpErlangPort))
|
421
|
+
assert_equal(Erlang::term_to_binary(port_v4), port_v4_binary)
|
372
422
|
end
|
373
423
|
def test_binary_to_term_ref
|
374
424
|
ref_new_binary = (
|
@@ -586,9 +636,9 @@ class EncodeTestCase < Test::Unit::TestCase
|
|
586
636
|
Erlang::term_to_binary('test'))
|
587
637
|
end
|
588
638
|
def test_term_to_binary_predefined_atom
|
589
|
-
assert_equal("\
|
590
|
-
assert_equal("\
|
591
|
-
assert_equal("\
|
639
|
+
assert_equal("\x83w\4true", Erlang::term_to_binary(true))
|
640
|
+
assert_equal("\x83w\5false", Erlang::term_to_binary(false))
|
641
|
+
assert_equal("\x83w\x09undefined", Erlang::term_to_binary(nil))
|
592
642
|
end
|
593
643
|
def test_term_to_binary_short_integer
|
594
644
|
assert_equal("\x83a\0", Erlang::term_to_binary(0))
|
@@ -625,6 +675,27 @@ class EncodeTestCase < Test::Unit::TestCase
|
|
625
675
|
assert_equal("\x83F\xc0\t!\xfbM\x12\xd8J",
|
626
676
|
Erlang::term_to_binary(-3.1415926))
|
627
677
|
end
|
678
|
+
def test_term_to_binary_map
|
679
|
+
assert_equal("\x83t\x00\x00\x00\x00", Erlang::term_to_binary({}))
|
680
|
+
map1 = {
|
681
|
+
Erlang::OtpErlangAtom.new("a".encode(Encoding::ISO_8859_1)) => 1
|
682
|
+
}
|
683
|
+
map1_binary = "\x83t\x00\x00\x00\x01s\x01aa\x01"
|
684
|
+
assert_equal(map1_binary, Erlang::term_to_binary(map1))
|
685
|
+
map2 = {
|
686
|
+
Erlang::OtpErlangAtom.new("undefined".encode(Encoding::UTF_8)) =>
|
687
|
+
Erlang::OtpErlangBinary.new("nothing"),
|
688
|
+
Erlang::OtpErlangBinary.new("\xA8", 6) =>
|
689
|
+
Erlang::OtpErlangBinary.new("everything")
|
690
|
+
}
|
691
|
+
map2_binary = (
|
692
|
+
"\x83\x74\x00\x00\x00\x02\x77\x09\x75\x6E\x64\x65\x66\x69" \
|
693
|
+
"\x6E\x65\x64\x6D\x00\x00\x00\x07\x6E\x6F\x74\x68\x69\x6E" \
|
694
|
+
"\x67\x4D\x00\x00\x00\x01\x06\xA8\x6D\x00\x00\x00\x0A\x65" \
|
695
|
+
"\x76\x65\x72\x79\x74\x68\x69\x6E\x67"
|
696
|
+
)
|
697
|
+
assert_equal(map2_binary, Erlang::term_to_binary(map2))
|
698
|
+
end
|
628
699
|
def test_term_to_binary_compressed_term
|
629
700
|
assert_equal(
|
630
701
|
"\x83P\x00\x00\x00\x15x\x9c\xcba``\xe0\xcfB\x03\x00B@\x07\x1c",
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: erlang_rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Truog
|
@@ -11,32 +11,32 @@ cert_chain:
|
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
13
|
MIIESDCCArCgAwIBAgIBATANBgkqhkiG9w0BAQsFADAnMSUwIwYDVQQDDBxtanRy
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
14
|
+
dW9nL0RDPXByb3Rvbm1haWwvREM9Y29tMB4XDTIyMTAxMjIwMDU0MloXDTIzMTAx
|
15
|
+
MjIwMDU0MlowJzElMCMGA1UEAwwcbWp0cnVvZy9EQz1wcm90b25tYWlsL0RDPWNv
|
16
|
+
bTCCAaIwDQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBAL9nIaNAY7hDthCtaBzd
|
17
|
+
KhqiT5DXoVMqM/ya+Y676+M6WnUcqvsCJ3XvE0axG/0u0jAbu0XejTZ2/9NcETHf
|
18
|
+
N4T2bw7jA6Vnn+rN2gKk62KlEzQVxZN+zbNme6fsxQ6j+nc4kqB6s6pd8VdTElJz
|
19
|
+
goBHUm/wmFRIpcbd+MZRQz+OJASi7Swjx+r65cFG7Ik7BriTnJLoAnrso1dfAYCV
|
20
|
+
ptrn+OMq33MFKkxneu7FrZsaD7Qo0taKl7nenZmG+qCzvJfiprzMyE1JDGPJptmf
|
21
|
+
VpjCct+Zolwa1MS+W07VS09iSllQ2xQPjSeMkrjKmjss3+kig4oKYTRP6gpdbWd7
|
22
|
+
hWIn/h2mQ3OmGeAlq6rcN0p9PVTYTByRT773g21fJHPa3GpHGfXfz6fV2D3aG1/F
|
23
|
+
dUgJMiWjhuHQQSbLEHZpxyaN0siAzbmwpzOXs2slBX+v3VMiNPT2fvLYWIfg7sVn
|
24
|
+
oCmqqb7Y+1qqCh68O+0A6+AGQQm2j8BUwRxyMFft6jeCPwIDAQABo38wfTAJBgNV
|
25
|
+
HRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUip5VZOKxMDY7Gw5PV5KjDOUB
|
26
|
+
aPAwIQYDVR0RBBowGIEWbWp0cnVvZ0Bwcm90b25tYWlsLmNvbTAhBgNVHRIEGjAY
|
27
|
+
gRZtanRydW9nQHByb3Rvbm1haWwuY29tMA0GCSqGSIb3DQEBCwUAA4IBgQC8NHmm
|
28
|
+
ytJq5FerCrZhwcyUN+OkBP5xDO3N5Vv7v5AcJ8R4+XpEE0J+Xi5ZPNRwDcVVA1f3
|
29
|
+
QPYrzFhgAFh9Fj7vzeYJIe3gGEgLvJZe5t5sTQCg1O4hg97qUrXz894KUMYzxFxv
|
30
|
+
r5Ujpaa5jIeCRLLEoMRCj2LM7aTD0BJ4D9rjUpOguALeMDjXuRFpPG0V2bRBR5yX
|
31
|
+
FgoLpkThWNwOrjTqmnXnJSQcOJTJaTZkXuY/vXI/AcN7aGbDi8gifgvvS6Umju+z
|
32
|
+
VFSVwtQuPhU4ruToRGUseXOsPwwWnJPleiEX5RQOIJ4mGmHzx5FnoDYNlHkS8DTT
|
33
|
+
K+77PgOz8oMDmzrQlCx1FDWhgNqsImrLYcca7kcoINTasLWmvfz1xaBeP4MdCk0R
|
34
|
+
CUaImqpeG21iNKLYHcNZkGfepUpp4FHudbeQeaJj8R5ug+f402l7T4s3JCAOcVIY
|
35
|
+
MqZAStuHt2H1iR+JVSpFx1kkRJncIjtSnxUFd4MsBT083aOme9H/J+tb/YA=
|
36
36
|
-----END CERTIFICATE-----
|
37
|
-
date:
|
37
|
+
date: 2023-06-21 00:00:00.000000000 Z
|
38
38
|
dependencies: []
|
39
|
-
description: Erlang
|
39
|
+
description: Erlang External Term Format for Ruby
|
40
40
|
email: mjtruog@protonmail.com
|
41
41
|
executables: []
|
42
42
|
extensions: []
|
metadata.gz.sig
CHANGED
Binary file
|