erlang-etf 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +3 -0
- data/Gemfile +10 -0
- data/README.md +3 -3
- data/Rakefile +3 -0
- data/erlang-etf.gemspec +0 -3
- data/lib/erlang/etf/atom.rb +28 -3
- data/lib/erlang/etf/atom_utf8.rb +27 -2
- data/lib/erlang/etf/binary.rb +10 -3
- data/lib/erlang/etf/bit_binary.rb +9 -5
- data/lib/erlang/etf/export.rb +12 -4
- data/lib/erlang/etf/extensions.rb +0 -19
- data/lib/erlang/etf/extensions/array.rb +0 -2
- data/lib/erlang/etf/extensions/big_decimal.rb +0 -2
- data/lib/erlang/etf/extensions/erlang-export.rb +0 -2
- data/lib/erlang/etf/extensions/erlang-list.rb +0 -2
- data/lib/erlang/etf/extensions/erlang-nil.rb +0 -2
- data/lib/erlang/etf/extensions/erlang-pid.rb +0 -2
- data/lib/erlang/etf/extensions/erlang-string.rb +13 -4
- data/lib/erlang/etf/extensions/erlang-tuple.rb +0 -2
- data/lib/erlang/etf/extensions/false_class.rb +0 -2
- data/lib/erlang/etf/extensions/float.rb +0 -2
- data/lib/erlang/etf/extensions/hash.rb +0 -2
- data/lib/erlang/etf/extensions/integer.rb +0 -2
- data/lib/erlang/etf/extensions/nil_class.rb +0 -2
- data/lib/erlang/etf/extensions/object.rb +0 -2
- data/lib/erlang/etf/extensions/regexp.rb +0 -2
- data/lib/erlang/etf/extensions/string.rb +0 -2
- data/lib/erlang/etf/extensions/symbol.rb +0 -2
- data/lib/erlang/etf/extensions/time.rb +0 -2
- data/lib/erlang/etf/extensions/true_class.rb +0 -2
- data/lib/erlang/etf/float.rb +9 -4
- data/lib/erlang/etf/fun.rb +26 -12
- data/lib/erlang/etf/integer.rb +7 -3
- data/lib/erlang/etf/large_big.rb +10 -5
- data/lib/erlang/etf/large_tuple.rb +6 -1
- data/lib/erlang/etf/list.rb +10 -5
- data/lib/erlang/etf/new_float.rb +7 -3
- data/lib/erlang/etf/new_fun.rb +47 -25
- data/lib/erlang/etf/new_reference.rb +14 -9
- data/lib/erlang/etf/nil.rb +8 -4
- data/lib/erlang/etf/pid.rb +13 -7
- data/lib/erlang/etf/port.rb +12 -6
- data/lib/erlang/etf/reference.rb +19 -10
- data/lib/erlang/etf/small_atom.rb +13 -6
- data/lib/erlang/etf/small_atom_utf8.rb +8 -3
- data/lib/erlang/etf/small_big.rb +14 -6
- data/lib/erlang/etf/small_integer.rb +7 -3
- data/lib/erlang/etf/small_tuple.rb +6 -2
- data/lib/erlang/etf/string.rb +6 -1
- data/lib/erlang/etf/version.rb +1 -1
- data/spec/erlang/etf/extensions/erlang-string_spec.rb +19 -4
- data/spec/erlang/etf/extensions/erlang-tuple_spec.rb +2 -1
- data/spec/erlang/etf/extensions/hash_spec.rb +3 -3
- data/spec/erlang/etf/large_tuple_spec.rb +1 -1
- data/spec/erlang_spec.rb +2 -1
- metadata +3 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0df02c49c6d963c92a155665d854c29c64d4d506
|
4
|
+
data.tar.gz: 1f4365a62a0b2ee16b87fa688cba57ee0b4a89f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40c84fcbf9312de7a5d9e0e057651743764fe6172e72c8c7e66a80fd4fd693b826235b83f010410f0ff086295f81186f3f4b9630b23276a432b6ad0a26af018b
|
7
|
+
data.tar.gz: f167a812a0f03ab72ea546cf3cf47947a9192e921de500439130932c11a33283fdad27f3a3d3b9e195c5b4b560d9a3b4f773d4b523598e421259d9ffdfba1b0a
|
data/.yardopts
ADDED
data/Gemfile
CHANGED
@@ -1,4 +1,14 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
+
platforms :ruby do
|
4
|
+
group :development do
|
5
|
+
gem "pry"
|
6
|
+
gem "pry-doc"
|
7
|
+
gem "redcarpet"
|
8
|
+
gem "simplecov", require: false
|
9
|
+
gem "yard"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
3
13
|
# Specify your gem's dependencies in erlang-etf.gemspec
|
4
14
|
gemspec
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Erlang::
|
1
|
+
# Erlang::ETF
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/potatosalad/erlang-etf.png)](https://travis-ci.org/potatosalad/erlang-etf)
|
4
4
|
|
@@ -26,14 +26,14 @@ $ gem install erlang-etf
|
|
26
26
|
|
27
27
|
## Usage
|
28
28
|
|
29
|
-
### Erlang.term_to_binary(term)
|
29
|
+
### `Erlang.term_to_binary(term)`
|
30
30
|
|
31
31
|
```ruby
|
32
32
|
Erlang.term_to_binary(:atom)
|
33
33
|
# => "\x83s\x04atom"
|
34
34
|
```
|
35
35
|
|
36
|
-
### Erlang.binary_to_term(binary)
|
36
|
+
### `Erlang.binary_to_term(binary)`
|
37
37
|
|
38
38
|
```ruby
|
39
39
|
Erlang.binary_to_term("\x83s\x04atom")
|
data/Rakefile
CHANGED
data/erlang-etf.gemspec
CHANGED
@@ -22,9 +22,6 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_dependency "erlang-terms"
|
23
23
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
-
spec.add_development_dependency "pry"
|
26
|
-
spec.add_development_dependency "pry-doc"
|
27
25
|
spec.add_development_dependency "rake"
|
28
26
|
spec.add_development_dependency "rspec"
|
29
|
-
spec.add_development_dependency "simplecov"
|
30
27
|
end
|
data/lib/erlang/etf/atom.rb
CHANGED
@@ -7,10 +7,14 @@ module Erlang
|
|
7
7
|
# 100 | Len | AtomName
|
8
8
|
#
|
9
9
|
# An atom is stored with a 2 byte unsigned length in big-endian
|
10
|
-
# order, followed by Len numbers of 8 bit Latin1 characters that
|
11
|
-
# forms the AtomName
|
10
|
+
# order, followed by `Len` numbers of 8 bit Latin1 characters that
|
11
|
+
# forms the `AtomName`.
|
12
12
|
#
|
13
|
-
# Note
|
13
|
+
# **Note:** The maximum allowed value for `Len` is 255.
|
14
|
+
#
|
15
|
+
# (see [`ATOM_EXT`])
|
16
|
+
#
|
17
|
+
# [`ATOM_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#ATOM_EXT
|
14
18
|
#
|
15
19
|
class Atom
|
16
20
|
include Term
|
@@ -22,22 +26,43 @@ module Erlang
|
|
22
26
|
end
|
23
27
|
|
24
28
|
undef deserialize_atom_name
|
29
|
+
# @private
|
25
30
|
def deserialize_atom_name(buffer)
|
26
31
|
self.atom_name = buffer.read(len).from_utf8_binary
|
27
32
|
end
|
28
33
|
|
29
34
|
undef serialize_atom_name
|
35
|
+
# @private
|
30
36
|
def serialize_atom_name(buffer)
|
31
37
|
buffer << atom_name.to_utf8_binary
|
32
38
|
end
|
33
39
|
|
34
40
|
finalize
|
35
41
|
|
42
|
+
# Instantiate the new atom.
|
43
|
+
#
|
44
|
+
# @example Instantiate the atom.
|
45
|
+
# Erlang::ETF::Atom.new("test")
|
46
|
+
# # => #<Erlang::ETF::Atom @tag=100 @len=4 @atom_name="test">
|
47
|
+
#
|
48
|
+
# @param [ ::String ] atom_name The `AtomName` as a string.
|
49
|
+
#
|
50
|
+
# @since 1.0.0
|
36
51
|
def initialize(atom_name)
|
37
52
|
@atom_name = atom_name
|
38
53
|
@len = atom_name.to_s.bytesize
|
39
54
|
end
|
40
55
|
|
56
|
+
# Evolve to native ruby.
|
57
|
+
#
|
58
|
+
# @example Evolve to native ruby.
|
59
|
+
# atom = Erlang::ETF::Atom.new("test")
|
60
|
+
# atom.__ruby_evolve__
|
61
|
+
# # => :test
|
62
|
+
#
|
63
|
+
# @return [ ::Symbol ] The `AtomName` as a symbol.
|
64
|
+
#
|
65
|
+
# @since 1.0.0
|
41
66
|
def __ruby_evolve__
|
42
67
|
atom_name.intern
|
43
68
|
end
|
data/lib/erlang/etf/atom_utf8.rb
CHANGED
@@ -7,8 +7,12 @@ module Erlang
|
|
7
7
|
# 118 | Len | AtomName
|
8
8
|
#
|
9
9
|
# An atom is stored with a 2 byte unsigned length in big-endian
|
10
|
-
# order, followed by Len bytes containing the AtomName encoded
|
11
|
-
# UTF-8.
|
10
|
+
# order, followed by `Len` bytes containing the `AtomName` encoded
|
11
|
+
# in UTF-8.
|
12
|
+
#
|
13
|
+
# (see [`ATOM_UTF8_EXT`])
|
14
|
+
#
|
15
|
+
# [`ATOM_UTF8_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#ATOM_UTF8_EXT
|
12
16
|
#
|
13
17
|
class AtomUTF8
|
14
18
|
include Term
|
@@ -20,22 +24,43 @@ module Erlang
|
|
20
24
|
end
|
21
25
|
|
22
26
|
undef deserialize_atom_name
|
27
|
+
# @private
|
23
28
|
def deserialize_atom_name(buffer)
|
24
29
|
self.atom_name = buffer.read(len).from_utf8_binary
|
25
30
|
end
|
26
31
|
|
27
32
|
undef serialize_atom_name
|
33
|
+
# @private
|
28
34
|
def serialize_atom_name(buffer)
|
29
35
|
buffer << atom_name.to_utf8_binary
|
30
36
|
end
|
31
37
|
|
32
38
|
finalize
|
33
39
|
|
40
|
+
# Instantiate the new UTF-8 atom.
|
41
|
+
#
|
42
|
+
# @example Instantiate the UTF-8 atom.
|
43
|
+
# Erlang::ETF::AtomUTF8.new("Ωmega")
|
44
|
+
# # => #<Erlang::ETF::AtomUTF8 @tag=118 @len=5 @atom_name="Ωmega">
|
45
|
+
#
|
46
|
+
# @param [ ::String ] atom_name The `AtomName` as a string.
|
47
|
+
#
|
48
|
+
# @since 1.0.0
|
34
49
|
def initialize(atom_name)
|
35
50
|
@atom_name = atom_name
|
36
51
|
@len = atom_name.to_s.bytesize
|
37
52
|
end
|
38
53
|
|
54
|
+
# Evolve to native ruby.
|
55
|
+
#
|
56
|
+
# @example Evolve to native ruby.
|
57
|
+
# atom_utf8 = Erlang::ETF::AtomUTF8.new("Ωmega")
|
58
|
+
# atom_utf8.__ruby_evolve__
|
59
|
+
# # => :'Ωmega'
|
60
|
+
#
|
61
|
+
# @return [ ::Symbol ] The `AtomName` as a symbol.
|
62
|
+
#
|
63
|
+
# @since 1.0.0
|
39
64
|
def __ruby_evolve__
|
40
65
|
atom_name.intern
|
41
66
|
end
|
data/lib/erlang/etf/binary.rb
CHANGED
@@ -7,9 +7,16 @@ module Erlang
|
|
7
7
|
# 109 | Len | Data
|
8
8
|
#
|
9
9
|
# Binaries are generated with bit syntax expression or with
|
10
|
-
# list_to_binary/1, term_to_binary/1, or as input from
|
11
|
-
# ports.
|
12
|
-
#
|
10
|
+
# [`list_to_binary/1`], [`term_to_binary/1`], or as input from
|
11
|
+
# binary ports.
|
12
|
+
#
|
13
|
+
# The `Len` length field is an unsigned 4 byte integer (big endian).
|
14
|
+
#
|
15
|
+
# (see [`BINARY_EXT`])
|
16
|
+
#
|
17
|
+
# [`list_to_binary/1`]: http://erlang.org/doc/man/erlang.html#list_to_binary-1
|
18
|
+
# [`term_to_binary/1`]: http://erlang.org/doc/man/erlang.html#term_to_binary-1
|
19
|
+
# [`BINARY_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#BINARY_EXT
|
13
20
|
#
|
14
21
|
class Binary
|
15
22
|
include Term
|
@@ -2,17 +2,21 @@ module Erlang
|
|
2
2
|
module ETF
|
3
3
|
|
4
4
|
#
|
5
|
-
# 1
|
6
|
-
#
|
7
|
-
# 77
|
5
|
+
# 1 | 4 | 1 | Len
|
6
|
+
# --- | --- | ---- | ----
|
7
|
+
# 77 | Len | Bits | Data
|
8
8
|
#
|
9
9
|
# This term represents a bitstring whose length in bits is not a
|
10
10
|
# multiple of 8 (created using the bit syntax in R12B and later).
|
11
|
-
# The Len field is an unsigned 4 byte integer (big endian).
|
12
|
-
# The Bits field is the number of bits that are used in the last
|
11
|
+
# The `Len` field is an unsigned 4 byte integer (big endian).
|
12
|
+
# The `Bits` field is the number of bits that are used in the last
|
13
13
|
# byte in the data field, counting from the most significant bit
|
14
14
|
# towards the least significant.
|
15
15
|
#
|
16
|
+
# (see [`BIT_BINARY_EXT`])
|
17
|
+
#
|
18
|
+
# [`BIT_BINARY_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#BIT_BINARY_EXT
|
19
|
+
#
|
16
20
|
class BitBinary
|
17
21
|
include Term
|
18
22
|
|
data/lib/erlang/etf/export.rb
CHANGED
@@ -6,12 +6,20 @@ module Erlang
|
|
6
6
|
# --- | ------ | -------- | -----
|
7
7
|
# 113 | Module | Function | Arity
|
8
8
|
#
|
9
|
-
# This term is the encoding for external funs: fun M:F/A
|
9
|
+
# This term is the encoding for external funs: `fun M:F/A`.
|
10
10
|
#
|
11
|
-
# Module and Function are atoms (encoded using ATOM_EXT,
|
12
|
-
# SMALL_ATOM_EXT or ATOM_CACHE_REF).
|
11
|
+
# `Module` and `Function` are atoms (encoded using [`ATOM_EXT`],
|
12
|
+
# [`SMALL_ATOM_EXT`] or [`ATOM_CACHE_REF`]).
|
13
13
|
#
|
14
|
-
# Arity is an integer encoded using SMALL_INTEGER_EXT.
|
14
|
+
# `Arity` is an integer encoded using [`SMALL_INTEGER_EXT`].
|
15
|
+
#
|
16
|
+
# (see [`EXPORT_EXT`])
|
17
|
+
#
|
18
|
+
# [`ATOM_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#ATOM_EXT
|
19
|
+
# [`SMALL_ATOM_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#SMALL_ATOM_EXT
|
20
|
+
# [`ATOM_CACHE_REF`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#ATOM_CACHE_REF
|
21
|
+
# [`SMALL_INTEGER_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#SMALL_INTEGER_EXT
|
22
|
+
# [`EXPORT_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#EXPORT_EXT
|
15
23
|
#
|
16
24
|
class Export
|
17
25
|
include Term
|
@@ -6,7 +6,6 @@ module Erlang
|
|
6
6
|
|
7
7
|
# @private
|
8
8
|
class ::Object
|
9
|
-
extend Erlang::ETF::Extensions::Object::ClassMethods
|
10
9
|
include Erlang::ETF::Extensions::Object
|
11
10
|
end
|
12
11
|
end
|
@@ -26,37 +25,31 @@ module Erlang
|
|
26
25
|
|
27
26
|
# @private
|
28
27
|
class ::Erlang::Export
|
29
|
-
extend Erlang::ETF::Extensions::ErlangExport::ClassMethods
|
30
28
|
include Erlang::ETF::Extensions::ErlangExport
|
31
29
|
end
|
32
30
|
|
33
31
|
# @private
|
34
32
|
class ::Erlang::List
|
35
|
-
extend Erlang::ETF::Extensions::ErlangList::ClassMethods
|
36
33
|
include Erlang::ETF::Extensions::ErlangList
|
37
34
|
end
|
38
35
|
|
39
36
|
# @private
|
40
37
|
class ::Erlang::Nil
|
41
|
-
extend Erlang::ETF::Extensions::ErlangNil::ClassMethods
|
42
38
|
include Erlang::ETF::Extensions::ErlangNil
|
43
39
|
end
|
44
40
|
|
45
41
|
# @private
|
46
42
|
class ::Erlang::Pid
|
47
|
-
extend Erlang::ETF::Extensions::ErlangPid::ClassMethods
|
48
43
|
include Erlang::ETF::Extensions::ErlangPid
|
49
44
|
end
|
50
45
|
|
51
46
|
# @private
|
52
47
|
class ::Erlang::String
|
53
|
-
extend Erlang::ETF::Extensions::ErlangString::ClassMethods
|
54
48
|
include Erlang::ETF::Extensions::ErlangString
|
55
49
|
end
|
56
50
|
|
57
51
|
# @private
|
58
52
|
class ::Erlang::Tuple
|
59
|
-
extend Erlang::ETF::Extensions::ErlangTuple::ClassMethods
|
60
53
|
include Erlang::ETF::Extensions::ErlangTuple
|
61
54
|
end
|
62
55
|
end
|
@@ -82,73 +75,61 @@ module Erlang
|
|
82
75
|
|
83
76
|
# @private
|
84
77
|
class ::Array
|
85
|
-
extend Erlang::ETF::Extensions::Array::ClassMethods
|
86
78
|
include Erlang::ETF::Extensions::Array
|
87
79
|
end
|
88
80
|
|
89
81
|
# @private
|
90
82
|
class ::BigDecimal
|
91
|
-
extend Erlang::ETF::Extensions::BigDecimal::ClassMethods
|
92
83
|
include Erlang::ETF::Extensions::BigDecimal
|
93
84
|
end
|
94
85
|
|
95
86
|
# @private
|
96
87
|
class ::FalseClass
|
97
|
-
extend Erlang::ETF::Extensions::FalseClass::ClassMethods
|
98
88
|
include Erlang::ETF::Extensions::FalseClass
|
99
89
|
end
|
100
90
|
|
101
91
|
# @private
|
102
92
|
class ::Float
|
103
|
-
extend Erlang::ETF::Extensions::Float::ClassMethods
|
104
93
|
include Erlang::ETF::Extensions::Float
|
105
94
|
end
|
106
95
|
|
107
96
|
# @private
|
108
97
|
class ::Hash
|
109
|
-
extend Erlang::ETF::Extensions::Hash::ClassMethods
|
110
98
|
include Erlang::ETF::Extensions::Hash
|
111
99
|
end
|
112
100
|
|
113
101
|
# @private
|
114
102
|
class ::Integer
|
115
|
-
extend Erlang::ETF::Extensions::Integer::ClassMethods
|
116
103
|
include Erlang::ETF::Extensions::Integer
|
117
104
|
end
|
118
105
|
|
119
106
|
# @private
|
120
107
|
class ::NilClass
|
121
|
-
extend Erlang::ETF::Extensions::NilClass::ClassMethods
|
122
108
|
include Erlang::ETF::Extensions::NilClass
|
123
109
|
end
|
124
110
|
|
125
111
|
# @private
|
126
112
|
class ::Regexp
|
127
|
-
extend Erlang::ETF::Extensions::Regexp::ClassMethods
|
128
113
|
include Erlang::ETF::Extensions::Regexp
|
129
114
|
end
|
130
115
|
|
131
116
|
# @private
|
132
117
|
class ::String
|
133
|
-
extend Erlang::ETF::Extensions::String::ClassMethods
|
134
118
|
include Erlang::ETF::Extensions::String
|
135
119
|
end
|
136
120
|
|
137
121
|
# @private
|
138
122
|
class ::Symbol
|
139
|
-
extend Erlang::ETF::Extensions::Symbol::ClassMethods
|
140
123
|
include Erlang::ETF::Extensions::Symbol
|
141
124
|
end
|
142
125
|
|
143
126
|
# @private
|
144
127
|
class ::Time
|
145
|
-
extend Erlang::ETF::Extensions::Time::ClassMethods
|
146
128
|
include Erlang::ETF::Extensions::Time
|
147
129
|
end
|
148
130
|
|
149
131
|
# @private
|
150
132
|
class ::TrueClass
|
151
|
-
extend Erlang::ETF::Extensions::TrueClass::ClassMethods
|
152
133
|
include Erlang::ETF::Extensions::TrueClass
|
153
134
|
end
|
154
135
|
|