erlang_rb 2.0.5 → 2.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 82fd795948db72df73625ab7cef0f407018800b88d25e99a9a9a7a09d7ffbe8b
4
- data.tar.gz: 1a049d6f1d488f86ef89450c5d258d389d25de4c7bdfb8bf7eb66802e36728fd
3
+ metadata.gz: cb447b6bd939e85f7064d8f8bb2dc8c9c9760dd85176aa03faa2f71b80d399af
4
+ data.tar.gz: 7e44a500d2f09968376420c89a3009299000751c7944e8c34dab65bab65dc364
5
5
  SHA512:
6
- metadata.gz: c843ced9e5875d4439495a8fb9b193f2ea4672cfc86a682c4da2b23c6079d72920c607da8cc8c2afcc0b935da683f2ec2dc5fcfc5c2d30d03744c742dd084de5
7
- data.tar.gz: 3497c55537d5a02e8aca60c3d54e733721370e011775f3425240aed59739b112a31551cf54a23cb31cd2a541b53ea505e15cd839c82fba7da6bbdf5f0229ad06
6
+ metadata.gz: 64da30400b66241b3742fe4e05f37c10c8fcf17b01380989d268e11640c5d91a069a37fe965d6b51dcd5ed820cc21cf94ffdd152dcc77d5003c866c7d446bcec
7
+ data.tar.gz: 934690e36553ff1c20eb4de1f1d5d0cc7893d4181e46738792b59238d731bc047e3a72827db6fec30047dbc372ea94878e62edecd3e87d934312a709138d0d6d
checksums.yaml.gz.sig CHANGED
Binary file
data/README.markdown CHANGED
@@ -1,7 +1,7 @@
1
1
  Erlang External Term Format for Ruby
2
2
  ====================================
3
3
 
4
-
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
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))
data/lib/erlang.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # MIT License
5
5
  #
6
- # Copyright (c) 2011-2022 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"),
@@ -118,28 +118,6 @@ module Erlang
118
118
  alias eql? ==
119
119
  end
120
120
 
121
- class OtpErlangFunction
122
- def initialize(tag, value)
123
- @tag = tag
124
- @value = value
125
- end
126
- attr_reader :tag
127
- attr_reader :value
128
- def binary
129
- return "#{@tag.chr}#{@value}"
130
- end
131
- def to_s
132
- return "#{self.class.name}('#{@tag.to_s}','#{@value.to_s}')"
133
- end
134
- def hash
135
- return binary.hash
136
- end
137
- def ==(other)
138
- return binary == other.binary
139
- end
140
- alias eql? ==
141
- end
142
-
143
121
  class OtpErlangList
144
122
  def initialize(value, improper = false)
145
123
  @value = value
@@ -232,13 +210,18 @@ module Erlang
232
210
  attr_reader :id
233
211
  attr_reader :creation
234
212
  def binary
235
- creation_size = @creation.bytesize
236
- if creation_size == 1
237
- return "#{TAG_PORT_EXT.chr}" \
213
+ id_size = @id.bytesize
214
+ if id_size == 8
215
+ return "#{TAG_V4_PORT_EXT.chr}" \
238
216
  "#{@node.binary}#{@id}#{@creation}"
239
- elsif creation_size == 4
217
+ end
218
+ creation_size = @creation.bytesize
219
+ if creation_size == 4
240
220
  return "#{TAG_NEW_PORT_EXT.chr}" \
241
221
  "#{@node.binary}#{@id}#{@creation}"
222
+ elsif creation_size == 1
223
+ return "#{TAG_PORT_EXT.chr}" \
224
+ "#{@node.binary}#{@id}#{@creation}"
242
225
  else
243
226
  raise OutputException, 'unknown port type', caller
244
227
  end
@@ -299,6 +282,28 @@ module Erlang
299
282
  alias eql? ==
300
283
  end
301
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
+
302
307
  # core functionality
303
308
 
304
309
  def self.binary_to_term(data)
@@ -380,12 +385,18 @@ module Erlang
380
385
  elsif tag == TAG_FLOAT_EXT
381
386
  value = data[i,31].partition(0.chr)[0].to_f
382
387
  return [i + 31, value]
383
- elsif Set[TAG_NEW_PORT_EXT,TAG_REFERENCE_EXT,TAG_PORT_EXT].include?(tag)
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,7 +406,8 @@ 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
412
  elsif Set[TAG_NEW_PID_EXT, TAG_PID_EXT].include?(tag)
401
413
  result = binary_to_atom(i, data)
@@ -597,6 +609,8 @@ module Erlang
597
609
  raise ParseException, 'unparsed data', caller
598
610
  end
599
611
  return [i + j, term]
612
+ elsif tag == TAG_LOCAL_EXT
613
+ raise ParseException, 'LOCAL_EXT is opaque', caller
600
614
  else
601
615
  raise ParseException, 'invalid tag', caller
602
616
  end
@@ -875,6 +889,8 @@ module Erlang
875
889
  TAG_FUN_EXT = 117
876
890
  TAG_ATOM_UTF8_EXT = 118
877
891
  TAG_SMALL_ATOM_UTF8_EXT = 119
892
+ TAG_V4_PORT_EXT = 120
893
+ TAG_LOCAL_EXT = 121
878
894
 
879
895
  end
880
896
 
@@ -4,7 +4,7 @@
4
4
  #
5
5
  # MIT License
6
6
  #
7
- # Copyright (c) 2014-2022 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
@@ -339,6 +339,41 @@ class DecodeTestCase < Test::Unit::TestCase
339
339
  assert_equal(-6618611909121,
340
340
  Erlang::binary_to_term("\x83o\0\0\0\6\1\1\2\3\4\5\6"))
341
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
342
377
  def test_binary_to_term_pid
343
378
  pid_old_binary = (
344
379
  "\x83\x67\x64\x00\x0D\x6E\x6F\x6E\x6F\x64\x65\x40\x6E\x6F" \
@@ -377,6 +412,13 @@ class DecodeTestCase < Test::Unit::TestCase
377
412
  assert_equal(Erlang::term_to_binary(port_new),
378
413
  "\x83Ys\rnonode@nohost\x00\x00\x00\x06" \
379
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)
380
422
  end
381
423
  def test_binary_to_term_ref
382
424
  ref_new_binary = (
@@ -633,6 +675,27 @@ class EncodeTestCase < Test::Unit::TestCase
633
675
  assert_equal("\x83F\xc0\t!\xfbM\x12\xd8J",
634
676
  Erlang::term_to_binary(-3.1415926))
635
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
636
699
  def test_term_to_binary_compressed_term
637
700
  assert_equal(
638
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.5
4
+ version: 2.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Truog
@@ -34,7 +34,7 @@ cert_chain:
34
34
  CUaImqpeG21iNKLYHcNZkGfepUpp4FHudbeQeaJj8R5ug+f402l7T4s3JCAOcVIY
35
35
  MqZAStuHt2H1iR+JVSpFx1kkRJncIjtSnxUFd4MsBT083aOme9H/J+tb/YA=
36
36
  -----END CERTIFICATE-----
37
- date: 2022-10-12 00:00:00.000000000 Z
37
+ date: 2023-06-21 00:00:00.000000000 Z
38
38
  dependencies: []
39
39
  description: Erlang External Term Format for Ruby
40
40
  email: mjtruog@protonmail.com
metadata.gz.sig CHANGED
Binary file