erlang_rb 2.0.5 → 2.0.7

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: 8e39b414a34c0b86599a78e666258fa65e2b9d5057de57c36139bf97e4959757
4
+ data.tar.gz: ab6a198acac3dee117e653d405098c2942989289dfd8ec66b387510d6193c0d5
5
5
  SHA512:
6
- metadata.gz: c843ced9e5875d4439495a8fb9b193f2ea4672cfc86a682c4da2b23c6079d72920c607da8cc8c2afcc0b935da683f2ec2dc5fcfc5c2d30d03744c742dd084de5
7
- data.tar.gz: 3497c55537d5a02e8aca60c3d54e733721370e011775f3425240aed59739b112a31551cf54a23cb31cd2a541b53ea505e15cd839c82fba7da6bbdf5f0229ad06
6
+ metadata.gz: c103d383da43f5756219a63893ff00c6dbccc60ac0044b499d35d0bcba74ee9ad91eb0430c0170bbbc1dc7febb87da55f797e5cb7f9ced5728761c9372755bce
7
+ data.tar.gz: 6aa1cb7ceea594bdd95a2a2c5e941b2e9293f9bc2de9aa9ad9bb848b09bff0ca4c9c5189d8c9490f7d8e058333b4a11673c351267cf5864030849dc3e3992475
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.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Truog
@@ -11,30 +11,30 @@ cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
13
  MIIESDCCArCgAwIBAgIBATANBgkqhkiG9w0BAQsFADAnMSUwIwYDVQQDDBxtanRy
14
- dW9nL0RDPXByb3Rvbm1haWwvREM9Y29tMB4XDTIyMTAxMjIwMDU0MloXDTIzMTAx
15
- MjIwMDU0MlowJzElMCMGA1UEAwwcbWp0cnVvZy9EQz1wcm90b25tYWlsL0RDPWNv
16
- bTCCAaIwDQYJKoZIhvc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6fbnIpADqTDFl8QmE6mJT9vV
26
+ 1hEwIQYDVR0RBBowGIEWbWp0cnVvZ0Bwcm90b25tYWlsLmNvbTAhBgNVHRIEGjAY
27
+ gRZtanRydW9nQHByb3Rvbm1haWwuY29tMA0GCSqGSIb3DQEBCwUAA4IBgQBA8ugi
28
+ Wy2K1d4DZ+qyQwGCrVjkPBhFg0orXCaahFbSRRrNa/xRnHLSEwkFbxxLV8k2xzpa
29
+ HvHty0jdBpQraGclgGjm76hUSzm1X3xIlEIdpYAs7UF4NVjXDfU5OMMBtRl/nSN2
30
+ KZD7Wf/7wDAPZMxBo4lP1JLilkzznL8W3KnYERY/+q3iWqVlJWuVaM3V+7odgVD6
31
+ bt2XZoRA9gGCEN6Nx2sLyKu+3JG4NDaKP1I1NMkGvhVstmQR3ZkEfOLaDYqu4bZB
32
+ a89mkwELvrETEHSQ7VJjWjhXmpn1AYbj8OVpRcJtLsDx7n5wtUTh3yraCPLHpw9q
33
+ fEzFk+odm98DueIpYM8kcKvljGCZw5gD+LwqB37jeMDo6kW48ohjHw9bvbH2kEak
34
+ 5GS+S6xXCWXQrHEaX5ikTEuneT9Leg0sPCnORwWvWcxNYjZyQJ9EZtdyI703E0ck
35
+ iwD6tabrOe6QilJg+2O5Wx73t3W6cV820ZgXfXO1LvM37FFCC5QgjKRYaTY=
36
36
  -----END CERTIFICATE-----
37
- date: 2022-10-12 00:00:00.000000000 Z
37
+ date: 2023-10-26 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