erlang-etf 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +49 -0
- data/Rakefile +6 -0
- data/erlang-etf.gemspec +30 -0
- data/lib/erlang/etf.rb +40 -0
- data/lib/erlang/etf/atom.rb +46 -0
- data/lib/erlang/etf/atom_utf8.rb +44 -0
- data/lib/erlang/etf/bert.rb +74 -0
- data/lib/erlang/etf/binary.rb +44 -0
- data/lib/erlang/etf/bit_binary.rb +47 -0
- data/lib/erlang/etf/export.rb +44 -0
- data/lib/erlang/etf/extensions.rb +157 -0
- data/lib/erlang/etf/extensions/array.rb +29 -0
- data/lib/erlang/etf/extensions/big_decimal.rb +22 -0
- data/lib/erlang/etf/extensions/erlang-export.rb +26 -0
- data/lib/erlang/etf/extensions/erlang-list.rb +31 -0
- data/lib/erlang/etf/extensions/erlang-nil.rb +22 -0
- data/lib/erlang/etf/extensions/erlang-pid.rb +22 -0
- data/lib/erlang/etf/extensions/erlang-string.rb +22 -0
- data/lib/erlang/etf/extensions/erlang-tuple.rb +31 -0
- data/lib/erlang/etf/extensions/false_class.rb +28 -0
- data/lib/erlang/etf/extensions/float.rb +20 -0
- data/lib/erlang/etf/extensions/hash.rb +32 -0
- data/lib/erlang/etf/extensions/integer.rb +48 -0
- data/lib/erlang/etf/extensions/nil_class.rb +29 -0
- data/lib/erlang/etf/extensions/object.rb +24 -0
- data/lib/erlang/etf/extensions/regexp.rb +34 -0
- data/lib/erlang/etf/extensions/string.rb +35 -0
- data/lib/erlang/etf/extensions/symbol.rb +45 -0
- data/lib/erlang/etf/extensions/time.rb +29 -0
- data/lib/erlang/etf/extensions/true_class.rb +28 -0
- data/lib/erlang/etf/float.rb +57 -0
- data/lib/erlang/etf/fun.rb +67 -0
- data/lib/erlang/etf/integer.rb +29 -0
- data/lib/erlang/etf/large_big.rb +53 -0
- data/lib/erlang/etf/large_tuple.rb +55 -0
- data/lib/erlang/etf/list.rb +50 -0
- data/lib/erlang/etf/new_float.rb +33 -0
- data/lib/erlang/etf/new_fun.rb +98 -0
- data/lib/erlang/etf/new_reference.rb +59 -0
- data/lib/erlang/etf/nil.rb +23 -0
- data/lib/erlang/etf/pid.rb +45 -0
- data/lib/erlang/etf/port.rb +34 -0
- data/lib/erlang/etf/reference.rb +41 -0
- data/lib/erlang/etf/small_atom.rb +48 -0
- data/lib/erlang/etf/small_atom_utf8.rb +44 -0
- data/lib/erlang/etf/small_big.rb +59 -0
- data/lib/erlang/etf/small_integer.rb +29 -0
- data/lib/erlang/etf/small_tuple.rb +56 -0
- data/lib/erlang/etf/string.rb +46 -0
- data/lib/erlang/etf/term.rb +101 -0
- data/lib/erlang/etf/terms.rb +105 -0
- data/lib/erlang/etf/version.rb +5 -0
- data/spec/erlang/etf/atom_spec.rb +90 -0
- data/spec/erlang/etf/atom_utf8_spec.rb +90 -0
- data/spec/erlang/etf/binary_spec.rb +90 -0
- data/spec/erlang/etf/bit_binary_spec.rb +99 -0
- data/spec/erlang/etf/export_spec.rb +58 -0
- data/spec/erlang/etf/extensions/array_spec.rb +40 -0
- data/spec/erlang/etf/extensions/big_decimal_spec.rb +26 -0
- data/spec/erlang/etf/extensions/erlang-export_spec.rb +32 -0
- data/spec/erlang/etf/extensions/erlang-list_spec.rb +76 -0
- data/spec/erlang/etf/extensions/erlang-nil_spec.rb +24 -0
- data/spec/erlang/etf/extensions/erlang-pid_spec.rb +33 -0
- data/spec/erlang/etf/extensions/erlang-string_spec.rb +26 -0
- data/spec/erlang/etf/extensions/erlang-tuple_spec.rb +56 -0
- data/spec/erlang/etf/extensions/false_class_spec.rb +29 -0
- data/spec/erlang/etf/extensions/float_spec.rb +24 -0
- data/spec/erlang/etf/extensions/hash_spec.rb +90 -0
- data/spec/erlang/etf/extensions/integer_spec.rb +259 -0
- data/spec/erlang/etf/extensions/nil_class_spec.rb +29 -0
- data/spec/erlang/etf/extensions/object_spec.rb +30 -0
- data/spec/erlang/etf/extensions/regexp_spec.rb +35 -0
- data/spec/erlang/etf/extensions/string_spec.rb +43 -0
- data/spec/erlang/etf/extensions/symbol_spec.rb +64 -0
- data/spec/erlang/etf/extensions/time_spec.rb +32 -0
- data/spec/erlang/etf/extensions/true_class_spec.rb +29 -0
- data/spec/erlang/etf/float_spec.rb +92 -0
- data/spec/erlang/etf/fun_spec.rb +132 -0
- data/spec/erlang/etf/integer_spec.rb +57 -0
- data/spec/erlang/etf/large_big_spec.rb +67 -0
- data/spec/erlang/etf/large_tuple_spec.rb +119 -0
- data/spec/erlang/etf/list_spec.rb +159 -0
- data/spec/erlang/etf/new_float_spec.rb +92 -0
- data/spec/erlang/etf/new_fun_spec.rb +146 -0
- data/spec/erlang/etf/new_reference_spec.rb +60 -0
- data/spec/erlang/etf/nil_spec.rb +50 -0
- data/spec/erlang/etf/pid_spec.rb +61 -0
- data/spec/erlang/etf/port_spec.rb +58 -0
- data/spec/erlang/etf/reference_spec.rb +58 -0
- data/spec/erlang/etf/small_atom_spec.rb +90 -0
- data/spec/erlang/etf/small_atom_utf8_spec.rb +90 -0
- data/spec/erlang/etf/small_big_spec.rb +67 -0
- data/spec/erlang/etf/small_integer_spec.rb +57 -0
- data/spec/erlang/etf/small_tuple_spec.rb +112 -0
- data/spec/erlang/etf/string_spec.rb +92 -0
- data/spec/erlang/etf/term_spec.rb +27 -0
- data/spec/erlang/etf/terms_spec.rb +23 -0
- data/spec/erlang/etf_spec.rb +23 -0
- data/spec/erlang_spec.rb +77 -0
- data/spec/spec_helper.rb +7 -0
- metadata +310 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 195a05d3181de002ad6dff10e6994d94f722e8b2
|
4
|
+
data.tar.gz: 18a71520747f118760e31724f9dc135ebdc38dde
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c97cd0e64ceaf45946b042117c7cab7cb4654dcb325df611e4f35fdc323970b13b42317901d074ae1daaafff8901959332446e4737e53d37cdd5d874fafe0c5f
|
7
|
+
data.tar.gz: 2723c6b9376a9e1b235a5e195f30329f777f53b0c841f19bd4ebb44d975d2190d91b6fe2ab61be68711819c8fc5b8fbfe8c1ad83ad703d17fb000b1635d10972
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Andrew Bennett
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Erlang::Etf
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/potatosalad/erlang-etf.png)](https://travis-ci.org/potatosalad/erlang-etf)
|
4
|
+
|
5
|
+
Erlang [External Term Format](http://erlang.org/doc/apps/erts/erl_ext_dist.html) (ETF) for Ruby.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'erlang-etf', require: 'erlang/etf'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
```bash
|
18
|
+
$ bundle
|
19
|
+
```
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
```bash
|
24
|
+
$ gem install erlang-etf
|
25
|
+
```
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
### Erlang.term_to_binary(term)
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
Erlang.term_to_binary(:atom)
|
33
|
+
# => "\x83s\x04atom"
|
34
|
+
```
|
35
|
+
|
36
|
+
### Erlang.binary_to_term(binary)
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
Erlang.binary_to_term("\x83s\x04atom")
|
40
|
+
# => :atom
|
41
|
+
```
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
1. Fork it
|
46
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
47
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
48
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
49
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/erlang-etf.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'erlang/etf/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "erlang-etf"
|
8
|
+
spec.version = Erlang::ETF::VERSION
|
9
|
+
spec.authors = ["Andrew Bennett"]
|
10
|
+
spec.email = ["andrew@delorum.com"]
|
11
|
+
spec.description = %q{Erlang External Term Format (ETF) for Ruby}
|
12
|
+
spec.summary = %q{Erlang External Term Format (ETF) for Ruby}
|
13
|
+
spec.homepage = "https://github.com/potatosalad/erlang-etf"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "binary-protocol"
|
22
|
+
spec.add_dependency "erlang-terms"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "pry"
|
26
|
+
spec.add_development_dependency "pry-doc"
|
27
|
+
spec.add_development_dependency "rake"
|
28
|
+
spec.add_development_dependency "rspec"
|
29
|
+
spec.add_development_dependency "simplecov"
|
30
|
+
end
|
data/lib/erlang/etf.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require "binary/protocol"
|
2
|
+
require "erlang/terms"
|
3
|
+
|
4
|
+
require "erlang/etf/version"
|
5
|
+
require "erlang/etf/extensions"
|
6
|
+
require "erlang/etf/terms"
|
7
|
+
|
8
|
+
module Erlang
|
9
|
+
module ETF
|
10
|
+
|
11
|
+
extend self
|
12
|
+
|
13
|
+
ERLANG_MAGIC_BYTE = 131.chr.freeze
|
14
|
+
|
15
|
+
def encode(term, buffer = "")
|
16
|
+
buffer << ERLANG_MAGIC_BYTE
|
17
|
+
term.__erlang_dump__(buffer)
|
18
|
+
end
|
19
|
+
|
20
|
+
def decode(buffer)
|
21
|
+
magic = buffer.read(1)
|
22
|
+
if magic == ERLANG_MAGIC_BYTE
|
23
|
+
Terms.evolve(buffer)
|
24
|
+
else
|
25
|
+
raise NotImplementedError, "unknown Erlang magic byte #{magic.inspect} (should be #{ERLANG_MAGIC_BYTE.inspect})"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.binary_to_term(binary)
|
32
|
+
buffer = binary.respond_to?(:read) ? binary : StringIO.new(binary)
|
33
|
+
ETF.decode(buffer)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.term_to_binary(term, buffer = "")
|
37
|
+
ETF.encode(term, buffer)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Erlang
|
2
|
+
module ETF
|
3
|
+
|
4
|
+
#
|
5
|
+
# 1 | 2 | Len
|
6
|
+
# --- | --- | --------
|
7
|
+
# 100 | Len | AtomName
|
8
|
+
#
|
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.
|
12
|
+
#
|
13
|
+
# Note: The maximum allowed value for Len is 255.
|
14
|
+
#
|
15
|
+
class Atom
|
16
|
+
include Term
|
17
|
+
|
18
|
+
uint8 :tag, always: Terms::ATOM_EXT
|
19
|
+
|
20
|
+
uint16be :len, default: 0 do
|
21
|
+
string :atom_name
|
22
|
+
end
|
23
|
+
|
24
|
+
undef deserialize_atom_name
|
25
|
+
def deserialize_atom_name(buffer)
|
26
|
+
self.atom_name = buffer.read(len).from_utf8_binary
|
27
|
+
end
|
28
|
+
|
29
|
+
undef serialize_atom_name
|
30
|
+
def serialize_atom_name(buffer)
|
31
|
+
buffer << atom_name.to_utf8_binary
|
32
|
+
end
|
33
|
+
|
34
|
+
finalize
|
35
|
+
|
36
|
+
def initialize(atom_name)
|
37
|
+
@atom_name = atom_name
|
38
|
+
@len = atom_name.to_s.bytesize
|
39
|
+
end
|
40
|
+
|
41
|
+
def __ruby_evolve__
|
42
|
+
atom_name.intern
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Erlang
|
2
|
+
module ETF
|
3
|
+
|
4
|
+
#
|
5
|
+
# 1 | 2 | Len
|
6
|
+
# --- | --- | --------
|
7
|
+
# 118 | Len | AtomName
|
8
|
+
#
|
9
|
+
# An atom is stored with a 2 byte unsigned length in big-endian
|
10
|
+
# order, followed by Len bytes containing the AtomName encoded in
|
11
|
+
# UTF-8.
|
12
|
+
#
|
13
|
+
class AtomUTF8
|
14
|
+
include Term
|
15
|
+
|
16
|
+
uint8 :tag, always: Terms::ATOM_UTF8_EXT
|
17
|
+
|
18
|
+
uint16be :len, default: 0 do
|
19
|
+
string :atom_name
|
20
|
+
end
|
21
|
+
|
22
|
+
undef deserialize_atom_name
|
23
|
+
def deserialize_atom_name(buffer)
|
24
|
+
self.atom_name = buffer.read(len).from_utf8_binary
|
25
|
+
end
|
26
|
+
|
27
|
+
undef serialize_atom_name
|
28
|
+
def serialize_atom_name(buffer)
|
29
|
+
buffer << atom_name.to_utf8_binary
|
30
|
+
end
|
31
|
+
|
32
|
+
finalize
|
33
|
+
|
34
|
+
def initialize(atom_name)
|
35
|
+
@atom_name = atom_name
|
36
|
+
@len = atom_name.to_s.bytesize
|
37
|
+
end
|
38
|
+
|
39
|
+
def __ruby_evolve__
|
40
|
+
atom_name.intern
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Erlang
|
2
|
+
module ETF
|
3
|
+
module BERT
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def evolve(tuple)
|
7
|
+
if tuple.elements[1].respond_to?(:atom_name)
|
8
|
+
case tuple.elements[1].atom_name.to_s.intern
|
9
|
+
## boolean ##
|
10
|
+
when :false
|
11
|
+
false
|
12
|
+
when :true
|
13
|
+
true
|
14
|
+
|
15
|
+
## dict ##
|
16
|
+
when :dict
|
17
|
+
if tuple.elements[2].respond_to?(:__ruby_evolve__) and
|
18
|
+
((list = tuple.elements[2].__ruby_evolve__).is_a?(::Erlang::List) or (list.respond_to?(:empty?) and list.empty?))
|
19
|
+
list.inject({}) do |hash, (key, value)|
|
20
|
+
hash[key] = value
|
21
|
+
hash
|
22
|
+
end
|
23
|
+
else
|
24
|
+
unknown(tuple)
|
25
|
+
end
|
26
|
+
|
27
|
+
## nil ##
|
28
|
+
when :nil
|
29
|
+
nil
|
30
|
+
|
31
|
+
## regex ##
|
32
|
+
when :regex
|
33
|
+
if tuple.elements[2].is_a?(Erlang::ETF::Binary) and
|
34
|
+
(tuple.elements[3].is_a?(Erlang::ETF::List) or tuple.elements[3].is_a?(Erlang::ETF::Nil))
|
35
|
+
|
36
|
+
source = tuple.elements[2].__ruby_evolve__
|
37
|
+
opts = tuple.elements[3].__ruby_evolve__
|
38
|
+
|
39
|
+
options = 0
|
40
|
+
options |= ::Regexp::EXTENDED if opts.include?(:extended)
|
41
|
+
options |= ::Regexp::IGNORECASE if opts.include?(:caseless)
|
42
|
+
options |= ::Regexp::MULTILINE if opts.include?(:multiline)
|
43
|
+
::Regexp.new(source, options)
|
44
|
+
else
|
45
|
+
unknown(tuple)
|
46
|
+
end
|
47
|
+
|
48
|
+
## time ##
|
49
|
+
when :time
|
50
|
+
if tuple.arity == 5
|
51
|
+
megaseconds = tuple.elements[2].__ruby_evolve__
|
52
|
+
seconds = tuple.elements[3].__ruby_evolve__
|
53
|
+
microseconds = tuple.elements[4].__ruby_evolve__
|
54
|
+
|
55
|
+
Time.at(megaseconds * 1_000_000 + seconds, microseconds)
|
56
|
+
else
|
57
|
+
unknown(tuple)
|
58
|
+
end
|
59
|
+
|
60
|
+
else
|
61
|
+
unknown(tuple)
|
62
|
+
end
|
63
|
+
else
|
64
|
+
unknown(tuple)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def unknown(tuple)
|
69
|
+
::Erlang::Tuple[*tuple.elements.map(&:__ruby_evolve__)]
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Erlang
|
2
|
+
module ETF
|
3
|
+
|
4
|
+
#
|
5
|
+
# 1 | 4 | Len
|
6
|
+
# --- | --- | ----
|
7
|
+
# 109 | Len | Data
|
8
|
+
#
|
9
|
+
# Binaries are generated with bit syntax expression or with
|
10
|
+
# list_to_binary/1, term_to_binary/1, or as input from binary
|
11
|
+
# ports.
|
12
|
+
# The Len length field is an unsigned 4 byte integer (big endian).
|
13
|
+
#
|
14
|
+
class Binary
|
15
|
+
include Term
|
16
|
+
|
17
|
+
uint8 :tag, always: Terms::BINARY_EXT
|
18
|
+
|
19
|
+
uint32be :len, default: 0 do
|
20
|
+
string :data
|
21
|
+
end
|
22
|
+
|
23
|
+
undef deserialize_data
|
24
|
+
def deserialize_data(buffer)
|
25
|
+
self.data = buffer.read(len).from_utf8_binary
|
26
|
+
end
|
27
|
+
|
28
|
+
undef serialize_data
|
29
|
+
def serialize_data(buffer)
|
30
|
+
buffer << data.to_utf8_binary
|
31
|
+
end
|
32
|
+
|
33
|
+
finalize
|
34
|
+
|
35
|
+
def initialize(data)
|
36
|
+
@data = data
|
37
|
+
end
|
38
|
+
|
39
|
+
def __ruby_evolve__
|
40
|
+
data
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Erlang
|
2
|
+
module ETF
|
3
|
+
|
4
|
+
#
|
5
|
+
# 1 | 4 | 1 | Len
|
6
|
+
# -- | --- | ---- | ----
|
7
|
+
# 77 | Len | Bits | Data
|
8
|
+
#
|
9
|
+
# This term represents a bitstring whose length in bits is not a
|
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
|
13
|
+
# byte in the data field, counting from the most significant bit
|
14
|
+
# towards the least significant.
|
15
|
+
#
|
16
|
+
class BitBinary
|
17
|
+
include Term
|
18
|
+
|
19
|
+
uint8 :tag, always: Terms::BIT_BINARY_EXT
|
20
|
+
|
21
|
+
uint32be :len, always: -> { data.bytesize }
|
22
|
+
|
23
|
+
uint8 :bits
|
24
|
+
|
25
|
+
string :data, default: ""
|
26
|
+
|
27
|
+
undef serialize_data
|
28
|
+
def serialize_data(buffer)
|
29
|
+
buffer << data.to_utf8_binary
|
30
|
+
end
|
31
|
+
|
32
|
+
deserialize do |buffer|
|
33
|
+
len, = buffer.read(BYTES_32).unpack(UINT32BE_PACK)
|
34
|
+
deserialize_bits(buffer)
|
35
|
+
self.data = buffer.read(len).from_utf8_binary
|
36
|
+
self
|
37
|
+
end
|
38
|
+
|
39
|
+
finalize
|
40
|
+
|
41
|
+
def initialize(bits, data = "")
|
42
|
+
self.bits = bits
|
43
|
+
self.data = data
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|