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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5c84395a38c6a6a4525f31778825efbeaa06382991d523dfb0f495c4199eb871
4
- data.tar.gz: 9c8570517d4e856dca7edaa7575a4e13d78fd81c9fce3735e5f1ed7952aca036
3
+ metadata.gz: cb447b6bd939e85f7064d8f8bb2dc8c9c9760dd85176aa03faa2f71b80d399af
4
+ data.tar.gz: 7e44a500d2f09968376420c89a3009299000751c7944e8c34dab65bab65dc364
5
5
  SHA512:
6
- metadata.gz: ef57856031cb10f729737aaff10f662aefea4550490b7dee5fce2214d923512d5ef4b3d6188cee779b292198e1a9b3914b3ba21ec078cc7119244471b334b7a2
7
- data.tar.gz: 7b7a31b7ac2c5c326b29cca226120e5b95368f4fd7737ec0329f5546c44889abb3ed2d625666770f46cd9dac0ca63cffa4e74ad7c8b405f5c28d06db909532da
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 Binary Term Format for Ruby
2
- ==================================
1
+ Erlang External Term Format for Ruby
2
+ ====================================
3
3
 
4
- [![Build Status](https://secure.travis-ci.org/okeuday/erlang_rb.png?branch=master)](http://travis-ci.org/okeuday/erlang_rb)
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 Binary Term Format
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-2019 Michael Truog <mjtruog at protonmail dot com>
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
- creation_size = @creation.bytesize
231
- if creation_size == 1
232
- return "#{TAG_PORT_EXT.chr}" \
213
+ id_size = @id.bytesize
214
+ if id_size == 8
215
+ return "#{TAG_V4_PORT_EXT.chr}" \
233
216
  "#{@node.binary}#{@id}#{@creation}"
234
- elsif creation_size == 4
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 tag == TAG_ATOM_EXT
374
- j = data[i,2].unpack('n')[0]
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
- id = data[i,4]
387
- i += 4
388
- if tag == TAG_NEW_PORT_EXT
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 == TAG_NEW_PORT_EXT or tag == TAG_PORT_EXT
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 tag == TAG_NEW_PID_EXT or tag == TAG_PID_EXT
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 tag == TAG_SMALL_TUPLE_EXT or tag == TAG_LARGE_TUPLE_EXT
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 tag == TAG_SMALL_BIG_EXT or tag == TAG_LARGE_BIG_EXT
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 tag == TAG_NEWER_REFERENCE_EXT or tag == TAG_NEW_REFERENCE_EXT
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 == TAG_ATOM_UTF8_EXT
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].force_encoding('UTF-8')
546
- if atom_name.valid_encoding?
547
- return [i + j, OtpErlangAtom.new(atom_name)]
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
- raise ParseException, 'invalid atom_name unicode', caller
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 == TAG_SMALL_ATOM_UTF8_EXT
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].force_encoding('UTF-8')
555
- if atom_name.valid_encoding?
556
- return [i + j, OtpErlangAtom.new(atom_name)]
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
- raise ParseException, 'invalid atom_name unicode', caller
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('ISO-8859-1')
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('ISO-8859-1')
732
+ 'false'.force_encoding('UTF-8')
697
733
  ).binary
698
734
  elsif term.nil?
699
735
  return OtpErlangAtom.new(
700
- 'undefined'.force_encoding('ISO-8859-1')
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
 
@@ -4,7 +4,7 @@
4
4
  #
5
5
  # MIT License
6
6
  #
7
- # Copyright (c) 2014-2019 Michael Truog <mjtruog at protonmail dot com>
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("\x83d\0\0"))
123
- assert_equal(:'', Erlang::binary_to_term("\x83s\0"))
124
- assert_equal(:test, Erlang::binary_to_term("\x83d\0\4test"))
125
- assert_equal(:test, Erlang::binary_to_term("\x83s\4test"))
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(:undefined,
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\1jd\0\4tail")
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("\x83s\4true", Erlang::term_to_binary(true))
590
- assert_equal("\x83s\5false", Erlang::term_to_binary(false))
591
- assert_equal("\x83s\x09undefined", Erlang::term_to_binary(nil))
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
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
- dW9nL0RDPXByb3Rvbm1haWwvREM9Y29tMB4XDTIxMDUyNzIwNTIwMFoXDTIyMDUy
15
- NzIwNTIwMFowJzElMCMGA1UEAwwcbWp0cnVvZy9EQz1wcm90b25tYWlsL0RDPWNv
16
- bTCCAaIwDQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBAMd6XAi81JZcv5AzNqvx
17
- 7rPXgBArpQVU0zoUCcJ8ZkszXLnaDkyLXZZDWi4tNIZGzkFGzJv2YxQg/ocUzZXF
18
- ixcKuCiUF8nvV58DrFxd8ZYvYMk9GDoU95zIu/brrn6KeFP/nd10vtx46hSlGgeE
19
- 2vzk2pxw8Umml6xwTuximLjVcetas0tIm3kcUAhdWnI7hTgQbPmsGMEtpebpx4Ff
20
- RluZWlBVLt0i1mFpG2BxtGXLFxgxzK/syD8ZHBwaraW5k2ENY163TaJUo2NjDpNF
21
- 0GpcyslZLz0JKKS1RHyuj6fI5cB+7pP/ewbU7ksoMa8zN067gG6Ry75RnKu/Tfzv
22
- Ebh3eBwapuvHnPsW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rjTqmnXnJSQcOJTJaTZkXuY/vXI/AcN7aGbDi8gifgvvS6Umju+z
32
+ VFSVwtQuPhU4ruToRGUseXOsPwwWnJPleiEX5RQOIJ4mGmHzx5FnoDYNlHkS8DTT
33
+ K+77PgOz8oMDmzrQlCx1FDWhgNqsImrLYcca7kcoINTasLWmvfz1xaBeP4MdCk0R
34
+ CUaImqpeG21iNKLYHcNZkGfepUpp4FHudbeQeaJj8R5ug+f402l7T4s3JCAOcVIY
35
+ MqZAStuHt2H1iR+JVSpFx1kkRJncIjtSnxUFd4MsBT083aOme9H/J+tb/YA=
36
36
  -----END CERTIFICATE-----
37
- date: 2021-12-04 00:00:00.000000000 Z
37
+ date: 2023-06-21 00:00:00.000000000 Z
38
38
  dependencies: []
39
- description: Erlang Binary Term Format for Ruby
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