vox-etf 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,170 @@
1
+ /************************************************
2
+ * MIT License
3
+ *
4
+ * Copyright (c) 2017 Discord
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ ************************************************/
24
+
25
+ /*
26
+ * MessagePack system dependencies modified for erlpack.
27
+ *
28
+ * Copyright (C) 2008-2010 FURUHASHI Sadayuki
29
+ *
30
+ * Licensed under the Apache License, Version 2.0 (the "License");
31
+ * you may not use this file except in compliance with the License.
32
+ * You may obtain a copy of the License at
33
+ *
34
+ * http://www.apache.org/licenses/LICENSE-2.0
35
+ *
36
+ * Unless required by applicable law or agreed to in writing, software
37
+ * distributed under the License is distributed on an "AS IS" BASIS,
38
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
39
+ * See the License for the specific language governing permissions and
40
+ * limitations under the License.
41
+ */
42
+ #ifndef ERLPACK_SYSDEP_H__
43
+ #define ERLPACK_SYSDEP_H__
44
+
45
+ #include <stdlib.h>
46
+ #include <stddef.h>
47
+ #if defined(_MSC_VER) && _MSC_VER < 1600
48
+ typedef __int8 int8_t;
49
+ typedef unsigned __int8 uint8_t;
50
+ typedef __int16 int16_t;
51
+ typedef unsigned __int16 uint16_t;
52
+ typedef __int32 int32_t;
53
+ typedef unsigned __int32 uint32_t;
54
+ typedef __int64 int64_t;
55
+ typedef unsigned __int64 uint64_t;
56
+ #elif defined(_MSC_VER) // && _MSC_VER >= 1600
57
+ #include <stdint.h>
58
+ #else
59
+ #include <stdint.h>
60
+ #include <stdbool.h>
61
+ #endif
62
+
63
+ #if defined(__linux__)
64
+ #include <endian.h>
65
+ #endif
66
+
67
+ #ifdef _WIN32
68
+
69
+ #ifdef __cplusplus
70
+ /* numeric_limits<T>::min,max */
71
+ #ifdef max
72
+ #undef max
73
+ #endif
74
+ #ifdef min
75
+ #undef min
76
+ #endif
77
+ #endif
78
+
79
+ #else
80
+ #include <arpa/inet.h> /* __BYTE_ORDER */
81
+ #endif
82
+
83
+ #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
84
+ #if __BYTE_ORDER == __LITTLE_ENDIAN
85
+ #define __LITTLE_ENDIAN__
86
+ #elif __BYTE_ORDER == __BIG_ENDIAN
87
+ #define __BIG_ENDIAN__
88
+ #elif _WIN32
89
+ #define __LITTLE_ENDIAN__
90
+ #endif
91
+ #endif
92
+
93
+ #ifdef __LITTLE_ENDIAN__
94
+
95
+ #ifdef _WIN32
96
+ #if defined(ntohs)
97
+ #define _erlpack_be16(x) ntohs(x)
98
+ #elif defined(_byteswap_ushort) || (defined(_MSC_VER) && _MSC_VER >= 1400)
99
+ #define _erlpack_be16(x) ((uint16_t)_byteswap_ushort((unsigned short)x))
100
+ #else
101
+ #define _erlpack_be16(x) ( \
102
+ ((((uint16_t)x) << 8)) | \
103
+ ((((uint16_t)x) >> 8)))
104
+ #endif
105
+ #else
106
+ #define _erlpack_be16(x) ntohs(x)
107
+ #endif
108
+
109
+ #ifdef _WIN32
110
+ #if defined(ntohl)
111
+ #define _erlpack_be32(x) ntohl(x)
112
+ #elif defined(_byteswap_ulong) || (defined(_MSC_VER) && _MSC_VER >= 1400)
113
+ #define _erlpack_be32(x) ((uint32_t)_byteswap_ulong((unsigned long)x))
114
+ #else
115
+ #define _erlpack_be32(x) \
116
+ (((((uint32_t)x) << 24)) | \
117
+ ((((uint32_t)x) << 8) & 0x00ff0000U) | \
118
+ ((((uint32_t)x) >> 8) & 0x0000ff00U) | \
119
+ ((((uint32_t)x) >> 24)))
120
+ #endif
121
+ #else
122
+ #define _erlpack_be32(x) ntohl(x)
123
+ #endif
124
+
125
+ #if defined(_byteswap_uint64) || (defined(_MSC_VER) && _MSC_VER >= 1400)
126
+ #define _erlpack_be64(x) (_byteswap_uint64(x))
127
+ #elif defined(bswap_64)
128
+ #define _erlpack_be64(x) bswap_64(x)
129
+ #elif defined(__DARWIN_OSSwapInt64)
130
+ #define _erlpack_be64(x) __DARWIN_OSSwapInt64(x)
131
+ #elif defined(__linux__)
132
+ #define _erlpack_be64(x) be64toh(x)
133
+ #else
134
+ #define _erlpack_be64(x) \
135
+ (((((uint64_t)x) << 56)) | \
136
+ ((((uint64_t)x) << 40) & 0x00ff000000000000ULL) | \
137
+ ((((uint64_t)x) << 24) & 0x0000ff0000000000ULL) | \
138
+ ((((uint64_t)x) << 8) & 0x000000ff00000000ULL) | \
139
+ ((((uint64_t)x) >> 8) & 0x00000000ff000000ULL) | \
140
+ ((((uint64_t)x) >> 24) & 0x0000000000ff0000ULL) | \
141
+ ((((uint64_t)x) >> 40) & 0x000000000000ff00ULL) | \
142
+ ((((uint64_t)x) >> 56)))
143
+ #endif
144
+
145
+ #else
146
+ #define _erlpack_be16(x) (x)
147
+ #define _erlpack_be32(x) (x)
148
+ #define _erlpack_be64(x) (x)
149
+ #endif
150
+
151
+ #define _erlpack_store16(to, num) \
152
+ do \
153
+ { \
154
+ uint16_t val = _erlpack_be16(num); \
155
+ memcpy(to, &val, 2); \
156
+ } while (0)
157
+ #define _erlpack_store32(to, num) \
158
+ do \
159
+ { \
160
+ uint32_t val = _erlpack_be32(num); \
161
+ memcpy(to, &val, 4); \
162
+ } while (0)
163
+ #define _erlpack_store64(to, num) \
164
+ do \
165
+ { \
166
+ uint64_t val = _erlpack_be64(num); \
167
+ memcpy(to, &val, 8); \
168
+ } while (0)
169
+
170
+ #endif /* sysdep.h */
@@ -0,0 +1,35 @@
1
+ #include "ruby.h"
2
+ #include "encoder.hpp"
3
+ #include "decoder.hpp"
4
+ #include "etf.hpp"
5
+
6
+ // Decode an ETF term from a ruby string
7
+ // @param self [Object] Vox::ETF
8
+ // @param input [Rice::String] The ETF term to be decoded.
9
+ // @return [Rice::Object] Whatever the term is, as a ruby object.
10
+ VALUE decode(VALUE self, VALUE input)
11
+ {
12
+ Check_Type(input, T_STRING);
13
+
14
+ etf::decoder decoder(input);
15
+ return decoder.decode_term();
16
+ }
17
+
18
+ VALUE encode(VALUE self, VALUE input)
19
+ {
20
+ etf::encoder enc;
21
+ enc.encode_object(input);
22
+ return enc.r_string();
23
+ }
24
+
25
+ /*
26
+ Method called when the shared object is required in ruby.
27
+ Sets up modules and binds methods.
28
+ */
29
+ extern "C" void Init_etf()
30
+ {
31
+ VALUE mVox = rb_define_module("Vox");
32
+ VALUE mETF = rb_define_module_under(mVox, "ETF");
33
+ rb_define_singleton_method(mETF, "decode", reinterpret_cast<VALUE (*)(...)>(decode), 1);
34
+ rb_define_singleton_method(mETF, "encode", reinterpret_cast<VALUE (*)(...)>(encode), 1);
35
+ }
@@ -0,0 +1,58 @@
1
+ #pragma once
2
+
3
+ #include "./etf_reader.hpp"
4
+
5
+ #define ETF_VERSION 131
6
+
7
+ // Term IDs, first byte of any term.
8
+ enum term
9
+ {
10
+ new_float = 70,
11
+ bit_binary = 77,
12
+ atom_cache = 82,
13
+ new_pid = 88,
14
+ new_port = 89,
15
+ newer_reference = 90,
16
+ small_integer = 97,
17
+ integer = 98,
18
+ // annoying
19
+ etf_float = 99,
20
+ atom = 100,
21
+ reference = 101,
22
+ port = 102,
23
+ pid = 103,
24
+ small_tuple = 104,
25
+ large_tuple = 105,
26
+ nil = 106,
27
+ string = 107,
28
+ list = 108,
29
+ binary = 109,
30
+ small_big = 110,
31
+ large_big = 111,
32
+ new_fun = 112,
33
+ // annoying
34
+ etf_export = 113,
35
+ new_reference = 114,
36
+ small_atom = 115,
37
+ map = 116,
38
+ fun = 117,
39
+ atom_utf8 = 118,
40
+ small_atom_utf8 = 119
41
+ };
42
+
43
+ VALUE decode(VALUE self, VALUE input);
44
+ inline VALUE decode_small_tuple(etf_reader *reader);
45
+ inline VALUE decode_large_tuple(etf_reader *reader);
46
+ inline VALUE decode_map(etf_reader *reader);
47
+ inline VALUE decode_list(etf_reader *reader);
48
+ inline VALUE decode_binary(etf_reader *reader);
49
+ inline VALUE decode_string(etf_reader *reader);
50
+ inline VALUE decode_atom(etf_reader *reader);
51
+ inline VALUE decode_small_atom(etf_reader *reader);
52
+ inline VALUE decode_small_bignum(etf_reader *reader);
53
+ inline VALUE decode_large_bignum(etf_reader *reader);
54
+
55
+ VALUE encode(VALUE self, VALUE input);
56
+
57
+ // Setup function for ruby FFI.
58
+ extern "C" void Init_etf();
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('mkmf-rice')
4
+
5
+ find_header('ruby.h')
6
+ find_header('zlib.h')
7
+ find_header('stddef.h')
8
+ find_header('stdlib.h')
9
+ find_header('stdint.h')
10
+ find_header('limits.h')
11
+ find_header('string.h')
12
+
13
+ create_makefile('vox/etf')
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Vox
4
+ module ETF
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('lib/vox/etf/version')
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'vox-etf'
7
+ spec.version = Vox::ETF::VERSION
8
+ spec.authors = ['Matthew Carey']
9
+ spec.email = ['matthew.b.carey@gmail.com']
10
+
11
+ spec.summary = 'ETF decoding/encoding for vox.'
12
+ spec.description = spec.summary
13
+ spec.homepage = 'https://github.com/swarley/vox-etf'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = 'https://github.com/swarley/vox-etf'
19
+ spec.metadata['changelog_uri'] = 'https://github.com/swarley/vox-etf/blob/main/CHANGELOG.md'
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added
23
+ # into git.
24
+ spec.files =
25
+ Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.start_with?('spec/') }
27
+ end
28
+ spec.bindir = 'exe'
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ['lib']
31
+ spec.extensions << 'ext/vox/extconf.rb'
32
+
33
+ spec.add_dependency 'rice', '~> 2.2.0'
34
+ spec.add_development_dependency 'rake', '~> 12.3.3'
35
+ spec.add_development_dependency 'rake-compiler', '~> 1.1.1'
36
+ spec.add_development_dependency 'rspec', '~> 3.9.0'
37
+ spec.add_development_dependency 'rubocop', '~> 0.90.0'
38
+ spec.add_development_dependency 'rubocop-performance', '~> 1.8.0'
39
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.43.2'
40
+ end
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vox-etf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matthew Carey
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-09-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rice
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 12.3.3
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 12.3.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake-compiler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.1.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.1.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.9.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.9.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.90.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.90.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-performance
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.8.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.8.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.43.2
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.43.2
111
+ description: ETF decoding/encoding for vox.
112
+ email:
113
+ - matthew.b.carey@gmail.com
114
+ executables: []
115
+ extensions:
116
+ - ext/vox/extconf.rb
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".rubocop.yml"
122
+ - ".travis.yml"
123
+ - CODE_OF_CONDUCT.md
124
+ - Gemfile
125
+ - LICENSE.txt
126
+ - README.md
127
+ - Rakefile
128
+ - bin/console
129
+ - bin/rake
130
+ - bin/setup
131
+ - ext/vox/decoder.hpp
132
+ - ext/vox/encoder.hpp
133
+ - ext/vox/erlpack/constants.h
134
+ - ext/vox/erlpack/encoder.h
135
+ - ext/vox/erlpack/sysdep.h
136
+ - ext/vox/etf.cpp
137
+ - ext/vox/etf.hpp
138
+ - ext/vox/extconf.rb
139
+ - lib/vox/etf/version.rb
140
+ - vox-etf.gemspec
141
+ homepage: https://github.com/swarley/vox-etf
142
+ licenses:
143
+ - MIT
144
+ metadata:
145
+ homepage_uri: https://github.com/swarley/vox-etf
146
+ source_code_uri: https://github.com/swarley/vox-etf
147
+ changelog_uri: https://github.com/swarley/vox-etf/blob/main/CHANGELOG.md
148
+ post_install_message:
149
+ rdoc_options: []
150
+ require_paths:
151
+ - lib
152
+ required_ruby_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: 2.3.0
157
+ required_rubygems_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ requirements: []
163
+ rubygems_version: 3.1.2
164
+ signing_key:
165
+ specification_version: 4
166
+ summary: ETF decoding/encoding for vox.
167
+ test_files: []