erlang-etf 1.0.0 → 1.0.1

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.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +3 -0
  3. data/Gemfile +10 -0
  4. data/README.md +3 -3
  5. data/Rakefile +3 -0
  6. data/erlang-etf.gemspec +0 -3
  7. data/lib/erlang/etf/atom.rb +28 -3
  8. data/lib/erlang/etf/atom_utf8.rb +27 -2
  9. data/lib/erlang/etf/binary.rb +10 -3
  10. data/lib/erlang/etf/bit_binary.rb +9 -5
  11. data/lib/erlang/etf/export.rb +12 -4
  12. data/lib/erlang/etf/extensions.rb +0 -19
  13. data/lib/erlang/etf/extensions/array.rb +0 -2
  14. data/lib/erlang/etf/extensions/big_decimal.rb +0 -2
  15. data/lib/erlang/etf/extensions/erlang-export.rb +0 -2
  16. data/lib/erlang/etf/extensions/erlang-list.rb +0 -2
  17. data/lib/erlang/etf/extensions/erlang-nil.rb +0 -2
  18. data/lib/erlang/etf/extensions/erlang-pid.rb +0 -2
  19. data/lib/erlang/etf/extensions/erlang-string.rb +13 -4
  20. data/lib/erlang/etf/extensions/erlang-tuple.rb +0 -2
  21. data/lib/erlang/etf/extensions/false_class.rb +0 -2
  22. data/lib/erlang/etf/extensions/float.rb +0 -2
  23. data/lib/erlang/etf/extensions/hash.rb +0 -2
  24. data/lib/erlang/etf/extensions/integer.rb +0 -2
  25. data/lib/erlang/etf/extensions/nil_class.rb +0 -2
  26. data/lib/erlang/etf/extensions/object.rb +0 -2
  27. data/lib/erlang/etf/extensions/regexp.rb +0 -2
  28. data/lib/erlang/etf/extensions/string.rb +0 -2
  29. data/lib/erlang/etf/extensions/symbol.rb +0 -2
  30. data/lib/erlang/etf/extensions/time.rb +0 -2
  31. data/lib/erlang/etf/extensions/true_class.rb +0 -2
  32. data/lib/erlang/etf/float.rb +9 -4
  33. data/lib/erlang/etf/fun.rb +26 -12
  34. data/lib/erlang/etf/integer.rb +7 -3
  35. data/lib/erlang/etf/large_big.rb +10 -5
  36. data/lib/erlang/etf/large_tuple.rb +6 -1
  37. data/lib/erlang/etf/list.rb +10 -5
  38. data/lib/erlang/etf/new_float.rb +7 -3
  39. data/lib/erlang/etf/new_fun.rb +47 -25
  40. data/lib/erlang/etf/new_reference.rb +14 -9
  41. data/lib/erlang/etf/nil.rb +8 -4
  42. data/lib/erlang/etf/pid.rb +13 -7
  43. data/lib/erlang/etf/port.rb +12 -6
  44. data/lib/erlang/etf/reference.rb +19 -10
  45. data/lib/erlang/etf/small_atom.rb +13 -6
  46. data/lib/erlang/etf/small_atom_utf8.rb +8 -3
  47. data/lib/erlang/etf/small_big.rb +14 -6
  48. data/lib/erlang/etf/small_integer.rb +7 -3
  49. data/lib/erlang/etf/small_tuple.rb +6 -2
  50. data/lib/erlang/etf/string.rb +6 -1
  51. data/lib/erlang/etf/version.rb +1 -1
  52. data/spec/erlang/etf/extensions/erlang-string_spec.rb +19 -4
  53. data/spec/erlang/etf/extensions/erlang-tuple_spec.rb +2 -1
  54. data/spec/erlang/etf/extensions/hash_spec.rb +3 -3
  55. data/spec/erlang/etf/large_tuple_spec.rb +1 -1
  56. data/spec/erlang_spec.rb +2 -1
  57. metadata +3 -44
@@ -6,16 +6,25 @@ module Erlang
6
6
 
7
7
  module ErlangString
8
8
 
9
+ STRING_MAX = (+1 << 16) - 1
10
+
9
11
  def __erlang_type__
10
- :string
12
+ if bytesize > STRING_MAX
13
+ :list
14
+ else
15
+ :string
16
+ end
11
17
  end
12
18
 
13
19
  def __erlang_evolve__
14
- ETF::String.new(self)
20
+ case __erlang_type__
21
+ when :list
22
+ ETF::List.new(unpack('C*'))
23
+ when :string
24
+ ETF::String.new(self)
25
+ end
15
26
  end
16
27
 
17
- module ClassMethods
18
- end
19
28
  end
20
29
  end
21
30
  end
@@ -23,8 +23,6 @@ module Erlang
23
23
  end
24
24
  end
25
25
 
26
- module ClassMethods
27
- end
28
26
  end
29
27
  end
30
28
  end
@@ -20,8 +20,6 @@ module Erlang
20
20
  ::Erlang::Tuple[:bert, :false].__erlang_evolve__
21
21
  end
22
22
 
23
- module ClassMethods
24
- end
25
23
  end
26
24
  end
27
25
  end
@@ -12,8 +12,6 @@ module Erlang
12
12
  ETF::NewFloat.new(self)
13
13
  end
14
14
 
15
- module ClassMethods
16
- end
17
15
  end
18
16
  end
19
17
  end
@@ -24,8 +24,6 @@ module Erlang
24
24
  end].__erlang_evolve__
25
25
  end
26
26
 
27
- module ClassMethods
28
- end
29
27
  end
30
28
  end
31
29
  end
@@ -40,8 +40,6 @@ module Erlang
40
40
  end
41
41
  end
42
42
 
43
- module ClassMethods
44
- end
45
43
  end
46
44
  end
47
45
  end
@@ -21,8 +21,6 @@ module Erlang
21
21
  ::Erlang::Tuple[:bert, :nil].__erlang_evolve__
22
22
  end
23
23
 
24
- module ClassMethods
25
- end
26
24
  end
27
25
  end
28
26
  end
@@ -16,8 +16,6 @@ module Erlang
16
16
  __erlang_evolve__.serialize(buffer)
17
17
  end
18
18
 
19
- module ClassMethods
20
- end
21
19
  end
22
20
  end
23
21
  end
@@ -26,8 +26,6 @@ module Erlang
26
26
  ::Erlang::Tuple[:bert, :regex, source, opts].__erlang_evolve__
27
27
  end
28
28
 
29
- module ClassMethods
30
- end
31
29
  end
32
30
  end
33
31
  end
@@ -27,8 +27,6 @@ module Erlang
27
27
  force_encoding(UTF8_ENCODING).encode!
28
28
  end
29
29
 
30
- module ClassMethods
31
- end
32
30
  end
33
31
  end
34
32
  end
@@ -37,8 +37,6 @@ module Erlang
37
37
  to_s.to_utf8_binary
38
38
  end
39
39
 
40
- module ClassMethods
41
- end
42
40
  end
43
41
  end
44
42
  end
@@ -21,8 +21,6 @@ module Erlang
21
21
  ::Erlang::Tuple[:bert, :time, to_i / 1_000_000, to_i % 1_000_000, usec].__erlang_evolve__
22
22
  end
23
23
 
24
- module ClassMethods
25
- end
26
24
  end
27
25
  end
28
26
  end
@@ -20,8 +20,6 @@ module Erlang
20
20
  ::Erlang::Tuple[:bert, :true].__erlang_evolve__
21
21
  end
22
22
 
23
- module ClassMethods
24
- end
25
23
  end
26
24
  end
27
25
  end
@@ -4,9 +4,9 @@ module Erlang
4
4
  module ETF
5
5
 
6
6
  #
7
- # 1 | 31
8
- # -- | ------------
9
- # 99 | Float String
7
+ # 1 | 31
8
+ # --- | ------------
9
+ # 99 | Float String
10
10
  #
11
11
  # A float is stored in string format. the format used in sprintf
12
12
  # to format the float is "%.20e" (there are more bytes allocated
@@ -14,7 +14,12 @@ module Erlang
14
14
  # "%lf".
15
15
  #
16
16
  # This term is used in minor version 0 of the external format; it
17
- # has been superseded by NEW_FLOAT_EXT .
17
+ # has been superseded by [`NEW_FLOAT_EXT`].
18
+ #
19
+ # (see [`FLOAT_EXT`])
20
+ #
21
+ # [`NEW_FLOAT_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#NEW_FLOAT_EXT
22
+ # [`FLOAT_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#FLOAT_EXT
18
23
  #
19
24
  class Float
20
25
  include Term
@@ -6,23 +6,37 @@ module Erlang
6
6
  # --- | ------- | --- | ------ | ----- | ---- | -------------
7
7
  # 117 | NumFree | Pid | Module | Index | Uniq | Free vars ...
8
8
  #
9
- # Pid
10
- # is a process identifier as in PID_EXT. It represents the
9
+ # `Pid`
10
+ # > is a process identifier as in [`PID_EXT`]. It represents the
11
11
  # process in which the fun was created.
12
- # Module
13
- # is an encoded as an atom, using ATOM_EXT, SMALL_ATOM_EXT or
14
- # ATOM_CACHE_REF. This is the module that the fun is
12
+ #
13
+ # `Module`
14
+ # > is an encoded as an atom, using [`ATOM_EXT`], [`SMALL_ATOM_EXT`] or
15
+ # [`ATOM_CACHE_REF`]. This is the module that the fun is
15
16
  # implemented in.
16
- # Index
17
- # is an integer encoded using SMALL_INTEGER_EXT or INTEGER_EXT.
17
+ #
18
+ # `Index`
19
+ # > is an integer encoded using [`SMALL_INTEGER_EXT`] or [`INTEGER_EXT`].
18
20
  # It is typically a small index into the module's fun table.
19
- # Uniq
20
- # is an integer encoded using SMALL_INTEGER_EXT or INTEGER_EXT.
21
- # Uniq is the hash value of the parse for the fun.
22
- # Free vars
23
- # is NumFree number of terms, each one encoded according to its
21
+ #
22
+ # `Uniq`
23
+ # > is an integer encoded using [`SMALL_INTEGER_EXT`] or [`INTEGER_EXT`].
24
+ # `Uniq` is the hash value of the parse for the fun.
25
+ #
26
+ # `Free vars`
27
+ # > is `NumFree` number of terms, each one encoded according to its
24
28
  # type.
25
29
  #
30
+ # (see [`FUN_EXT`])
31
+ #
32
+ # [`PID_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#PID_EXT
33
+ # [`ATOM_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#ATOM_EXT
34
+ # [`SMALL_ATOM_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#SMALL_ATOM_EXT
35
+ # [`ATOM_CACHE_REF`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#ATOM_CACHE_REF
36
+ # [`SMALL_INTEGER_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#SMALL_INTEGER_EXT
37
+ # [`INTEGER_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#INTEGER_EXT
38
+ # [`FUN_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#FUN_EXT
39
+ #
26
40
  class Fun
27
41
  include Term
28
42
 
@@ -2,12 +2,16 @@ module Erlang
2
2
  module ETF
3
3
 
4
4
  #
5
- # 1 | 4
6
- # -- | ---
7
- # 98 | Int
5
+ # 1 | 4
6
+ # --- | ---
7
+ # 98 | Int
8
8
  #
9
9
  # Signed 32 bit integer in big-endian format (i.e. MSB first)
10
10
  #
11
+ # (see [`INTEGER_EXT`])
12
+ #
13
+ # [`INTEGER_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#INTEGER_EXT
14
+ #
11
15
  class Integer
12
16
  include Term
13
17
 
@@ -2,12 +2,17 @@ module Erlang
2
2
  module ETF
3
3
 
4
4
  #
5
- # 1 | 4 | 1 | n
6
- # --- | - | ---- | ---------------
7
- # 111 | n | Sign | d(0) ... d(n-1)
5
+ # 1 | 4 | 1 | n
6
+ # --- | --- | ---- | ---------------
7
+ # 111 | n | Sign | d(0) ... d(n-1)
8
8
  #
9
- # Same as SMALL_BIG_EXT with the difference that the length field
10
- # is an unsigned 4 byte integer.
9
+ # Same as [`SMALL_BIG_EXT`] with the difference that the length
10
+ # field is an unsigned 4 byte integer.
11
+ #
12
+ # (see [`LARGE_BIG_EXT`])
13
+ #
14
+ # [`SMALL_BIG_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#SMALL_BIG_EXT
15
+ # [`LARGE_BIG_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#LARGE_BIG_EXT
11
16
  #
12
17
  class LargeBig
13
18
  include Term
@@ -6,9 +6,14 @@ module Erlang
6
6
  # --- | ----- | --------
7
7
  # 105 | Arity | Elements
8
8
  #
9
- # Same as SMALL_TUPLE_EXT with the exception that Arity is an
9
+ # Same as [`SMALL_TUPLE_EXT`] with the exception that `Arity` is an
10
10
  # unsigned 4 byte integer in big endian format.
11
11
  #
12
+ # (see [`LARGE_TUPLE_EXT`])
13
+ #
14
+ # [`SMALL_TUPLE_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#SMALL_TUPLE_EXT
15
+ # [`LARGE_TUPLE_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#LARGE_TUPLE_EXT
16
+ #
12
17
  class LargeTuple
13
18
  include Term
14
19
 
@@ -2,14 +2,19 @@ module Erlang
2
2
  module ETF
3
3
 
4
4
  #
5
- # 1 | 4 | Len |
5
+ # 1 | 4 | Len | N1
6
6
  # --- | --- | -------- | ----
7
7
  # 108 | Len | Elements | Tail
8
8
  #
9
- # Length is the number of elements that follows in the Elements
10
- # section. Tail is the final tail of the list; it is NIL_EXT for a
9
+ # `Length` is the number of elements that follows in the `Elements`
10
+ # section. `Tail` is the final tail of the list; it is [`NIL_EXT`] for a
11
11
  # proper list, but may be anything type if the list is improper
12
- # (for instance [a|b]).
12
+ # (for instance `[a|b]`).
13
+ #
14
+ # (see [`LIST_EXT`])
15
+ #
16
+ # [`NIL_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#NIL_EXT
17
+ # [`LIST_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#LIST_EXT
13
18
  #
14
19
  class List
15
20
  include Term
@@ -18,7 +23,7 @@ module Erlang
18
23
 
19
24
  uint32be :len, always: -> { elements.size }
20
25
 
21
- term :elements, type: :array
26
+ term :elements, type: :array, allow_char: true
22
27
  term :tail
23
28
 
24
29
  deserialize do |buffer|
@@ -4,14 +4,18 @@ module Erlang
4
4
  module ETF
5
5
 
6
6
  #
7
- # 1 | 8
8
- # -- | ----------
9
- # 70 | IEEE Float
7
+ # 1 | 8
8
+ # --- | ----------
9
+ # 70 | IEEE Float
10
10
  #
11
11
  # A float is stored as 8 bytes in big-endian IEEE format.
12
12
  #
13
13
  # This term is used in minor version 1 of the external format.
14
14
  #
15
+ # (see [`NEW_FLOAT_EXT`])
16
+ #
17
+ # [`NEW_FLOAT_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#NEW_FLOAT_EXT
18
+ #
15
19
  class NewFloat
16
20
  include Term
17
21
 
@@ -7,36 +7,58 @@ module Erlang
7
7
  # 112 | Size | Arity | Uniq | Index | NumFree | Module | Oldindex | OldUniq | Pid | Free Vars
8
8
  #
9
9
  # This is the new encoding of internal funs:
10
- # fun F/A and fun(Arg1,..) -> ... end.
11
- #
12
- # Size
13
- # is the total number of bytes, including the Size field.
14
- # Arity
15
- # is the arity of the function implementing the fun.
16
- # Uniq
17
- # is the 16 bytes MD5 of the significant parts of the Beam file.
18
- # Index
19
- # is an index number. Each fun within a module has an unique
20
- # index. Index is stored in big-endian byte order.
21
- # NumFree
22
- # is the number of free variables.
23
- # Module
24
- # is an encoded as an atom, using ATOM_EXT, SMALL_ATOM_EXT or
25
- # ATOM_CACHE_REF. This is the module that the fun is implemented
10
+ #
11
+ # ```erlang
12
+ # fun F/A and fun(Arg1,..) -> ... end.
13
+ # ```
14
+ #
15
+ # `Size`
16
+ # > is the total number of bytes, including the `Size` field.
17
+ #
18
+ # `Arity`
19
+ # > is the arity of the function implementing the fun.
20
+ #
21
+ # `Uniq`
22
+ # > is the 16 bytes MD5 of the significant parts of the Beam file.
23
+ #
24
+ # `Index`
25
+ # > is an index number. Each fun within a module has an unique
26
+ # index. `Index` is stored in big-endian byte order.
27
+ #
28
+ # `NumFree`
29
+ # > is the number of free variables.
30
+ #
31
+ # `Module`
32
+ # > is an encoded as an atom, using [`ATOM_EXT`], [`SMALL_ATOM_EXT`] or
33
+ # [`ATOM_CACHE_REF`]. This is the module that the fun is implemented
26
34
  # in.
27
- # OldIndex
28
- # is an integer encoded using SMALL_INTEGER_EXT or INTEGER_EXT.
35
+ #
36
+ # `OldIndex`
37
+ # > is an integer encoded using [`SMALL_INTEGER_EXT`] or [`INTEGER_EXT`].
29
38
  # It is typically a small index into the module's fun table.
30
- # OldUniq
31
- # is an integer encoded using SMALL_INTEGER_EXT or INTEGER_EXT.
32
- # Uniq is the hash value of the parse tree for the fun.
33
- # Pid
34
- # is a process identifier as in PID_EXT. It represents the
39
+ #
40
+ # `OldUniq`
41
+ # > is an integer encoded using [`SMALL_INTEGER_EXT`] or [`INTEGER_EXT`].
42
+ # `Uniq` is the hash value of the parse tree for the fun.
43
+ #
44
+ # `Pid`
45
+ # > is a process identifier as in [`PID_EXT`]. It represents the
35
46
  # process in which the fun was created.
36
- # Free vars
37
- # is NumFree number of terms, each one encoded according to its
47
+ #
48
+ # `Free vars`
49
+ # > is `NumFree` number of terms, each one encoded according to its
38
50
  # type.
39
51
  #
52
+ # (see [`NEW_FUN_EXT`])
53
+ #
54
+ # [`ATOM_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#ATOM_EXT
55
+ # [`SMALL_ATOM_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#SMALL_ATOM_EXT
56
+ # [`ATOM_CACHE_REF`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#ATOM_CACHE_REF
57
+ # [`SMALL_INTEGER_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#SMALL_INTEGER_EXT
58
+ # [`INTEGER_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#INTEGER_EXT
59
+ # [`PID_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#PID_EXT
60
+ # [`NEW_FUN_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#NEW_FUN_EXT
61
+ #
40
62
  class NewFun
41
63
  include Term
42
64
 
@@ -6,22 +6,27 @@ module Erlang
6
6
  # --- | --- | ---- | -------- | ------
7
7
  # 114 | Len | Node | Creation | ID ...
8
8
  #
9
- # Node and Creation are as in REFERENCE_EXT.
9
+ # `Node` and `Creation` are as in [`REFERENCE_EXT`].
10
10
  #
11
- # ID contains a sequence of big-endian unsigned integers (4 bytes
12
- # each, so N' is a multiple of 4), but should be regarded as
11
+ # `ID` contains a sequence of big-endian unsigned integers (4 bytes
12
+ # each, so `N'` is a multiple of 4), but should be regarded as
13
13
  # uninterpreted data.
14
14
  #
15
- # N' = 4 * Len.
15
+ # `N' = 4 * Len.`
16
16
  #
17
- # In the first word (four bytes) of ID, only 18 bits are
18
- # significant, the rest should be 0. In Creation, only 2 bits are
17
+ # In the first word (four bytes) of `ID`, only 18 bits are
18
+ # significant, the rest should be 0. In `Creation`, only 2 bits are
19
19
  # significant, the rest should be 0.
20
20
  #
21
- # NEW_REFERENCE_EXT was introduced with distribution version 4. In
22
- # version 4, N' should be at most 12.
21
+ # [`NEW_REFERENCE_EXT`] was introduced with distribution version 4. In
22
+ # version 4, `N'` should be at most 12.
23
23
  #
24
- # See REFERENCE_EXT).
24
+ # See [`REFERENCE_EXT`]).
25
+ #
26
+ # (see [`NEW_REFERENCE_EXT`])
27
+ #
28
+ # [`REFERENCE_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#REFERENCE_EXT
29
+ # [`NEW_REFERENCE_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#NEW_REFERENCE_EXT
25
30
  #
26
31
  class NewReference
27
32
  include Term