vox-etf 0.1.3 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/vox/decoder.hpp +8 -2
- data/ext/vox/encoder.hpp +31 -11
- data/ext/vox/etf.hpp +1 -0
- data/ext/vox/extconf.rb +5 -2
- data/lib/vox/etf/version.rb +1 -1
- data/vox-etf.gemspec +0 -1
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8d2deb457e60eb111c3f25ee95afcf9532e369ec4dff759908d48c92c93d3cf
|
4
|
+
data.tar.gz: d003df24854077a8b6192506f62db5888c417acaf35872b9ddd6bebf7c37f720
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be499bd7ec49e3e1ee4945b808979a2a8bf331ac871f227a90a8ff77d28a87eddc32cea4f7e6e722d3d09d88a1a226c05d6b4760ef1ccf517b786fe9799c1429
|
7
|
+
data.tar.gz: 7bfa5417c8d0fbe5a2226fe2bb506af46cbb22d1736ef7b99029bec0074c35080b30e84450296ce23c0589cf6394349eca4f8e2376099cc60eccd9af796528c6
|
data/ext/vox/decoder.hpp
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
#pragma once
|
2
2
|
#include <zlib.h>
|
3
|
+
#include "./etf.hpp"
|
3
4
|
#include "ruby.h"
|
4
5
|
#include "erlpack/sysdep.h"
|
5
6
|
#include "erlpack/constants.h"
|
@@ -360,11 +361,12 @@ namespace etf
|
|
360
361
|
|
361
362
|
VALUE decode_compressed()
|
362
363
|
{
|
364
|
+
#if HAVE_ZLIB_H
|
363
365
|
const uint32_t decompressed_size = read32();
|
364
366
|
|
365
|
-
|
367
|
+
unsigned long source_size = decompressed_size;
|
366
368
|
uint8_t *out_buffer = (uint8_t *)malloc(decompressed_size);
|
367
|
-
const int ret = uncompress(out_buffer, &source_size, (const unsigned char *)(data + offset), (
|
369
|
+
const int ret = uncompress(out_buffer, &source_size, (const unsigned char *)(data + offset), (uLong)(size - offset));
|
368
370
|
|
369
371
|
offset += source_size;
|
370
372
|
if (ret != Z_OK)
|
@@ -378,6 +380,10 @@ namespace etf
|
|
378
380
|
VALUE value = decompressed.decode_term();
|
379
381
|
free(out_buffer);
|
380
382
|
return value;
|
383
|
+
#else
|
384
|
+
rb_raise(rb_eArgError, "vox-etf was compiled without zlib support can cannot decode the compressed term.");
|
385
|
+
return Qnil;
|
386
|
+
#endif
|
381
387
|
}
|
382
388
|
};
|
383
389
|
} // namespace etf
|
data/ext/vox/encoder.hpp
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#include "erlpack/encoder.h"
|
2
2
|
#include "erlpack/constants.h"
|
3
|
-
#include "etf.hpp"
|
3
|
+
#include "./etf.hpp"
|
4
|
+
#include "ruby.h"
|
4
5
|
|
5
6
|
namespace etf
|
6
7
|
{
|
@@ -98,11 +99,11 @@ namespace etf
|
|
98
99
|
|
99
100
|
void encode_fixnum(VALUE fixnum)
|
100
101
|
{
|
101
|
-
|
102
|
-
if (
|
103
|
-
erlpack_append_small_integer(erl_buff, (
|
102
|
+
uint32_t n = NUM2UINT(fixnum);
|
103
|
+
if (n > 0 && n <= UINT8_MAX)
|
104
|
+
erlpack_append_small_integer(erl_buff, (uint8_t)n);
|
104
105
|
else
|
105
|
-
erlpack_append_integer(erl_buff,
|
106
|
+
erlpack_append_integer(erl_buff, n);
|
106
107
|
}
|
107
108
|
|
108
109
|
void encode_bignum(VALUE bignum)
|
@@ -137,18 +138,30 @@ namespace etf
|
|
137
138
|
|
138
139
|
void encode_array(VALUE array)
|
139
140
|
{
|
140
|
-
|
141
|
-
|
142
|
-
|
141
|
+
uint64_t size = RARRAY_LEN(array);
|
142
|
+
if (size == 0)
|
143
|
+
{
|
144
|
+
erlpack_append_nil_ext(erl_buff);
|
145
|
+
return;
|
146
|
+
}
|
147
|
+
else if (size > UINT32_MAX)
|
148
|
+
{
|
149
|
+
rb_raise(rb_eRangeError, "Array size is too large to fit into a 32 bit integer.");
|
150
|
+
return;
|
151
|
+
}
|
152
|
+
|
153
|
+
erlpack_append_list_header(erl_buff, size);
|
154
|
+
for (size_t index = 0; index < size; index++)
|
143
155
|
{
|
144
156
|
encode_object(RARRAY_AREF(array, index));
|
145
157
|
}
|
158
|
+
|
159
|
+
erlpack_append_nil_ext(erl_buff);
|
146
160
|
}
|
147
161
|
|
148
162
|
void encode_symbol(VALUE symbol)
|
149
163
|
{
|
150
|
-
|
151
|
-
erlpack_append_atom_utf8(erl_buff, RSTRING_PTR(str), RSTRING_LEN(str));
|
164
|
+
encode_string(rb_sym2str(symbol));
|
152
165
|
}
|
153
166
|
|
154
167
|
void encode_string(VALUE string)
|
@@ -158,13 +171,20 @@ namespace etf
|
|
158
171
|
|
159
172
|
void encode_hash(VALUE hash)
|
160
173
|
{
|
161
|
-
|
174
|
+
uint64_t size = RHASH_SIZE(hash);
|
175
|
+
if (size > UINT32_MAX)
|
176
|
+
{
|
177
|
+
rb_raise(rb_eRangeError, "Hash size is too large to fit into a 32 bit integer");
|
178
|
+
return;
|
179
|
+
}
|
180
|
+
|
162
181
|
erlpack_append_map_header(erl_buff, size);
|
163
182
|
VALUE keys = rb_funcall(hash, rb_intern("keys"), 0);
|
164
183
|
|
165
184
|
for (uint32_t index = 0; index < size * 2; index += 2)
|
166
185
|
{
|
167
186
|
VALUE key = RARRAY_AREF(keys, index / 2);
|
187
|
+
// Normalize keys to strings because discord
|
168
188
|
encode_object(key);
|
169
189
|
encode_object(rb_hash_aref(hash, key));
|
170
190
|
}
|
data/ext/vox/etf.hpp
CHANGED
data/ext/vox/extconf.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require('mkmf
|
3
|
+
require('mkmf')
|
4
4
|
|
5
5
|
find_header('ruby.h')
|
6
|
-
find_header('zlib.h')
|
7
6
|
find_header('stddef.h')
|
8
7
|
find_header('stdlib.h')
|
9
8
|
find_header('stdint.h')
|
10
9
|
find_header('limits.h')
|
11
10
|
find_header('string.h')
|
11
|
+
have_header('zlib.h')
|
12
|
+
have_library('z')
|
13
|
+
|
14
|
+
create_header
|
12
15
|
|
13
16
|
create_makefile('vox/etf')
|
data/lib/vox/etf/version.rb
CHANGED
data/vox-etf.gemspec
CHANGED
@@ -30,7 +30,6 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.require_paths = ['lib']
|
31
31
|
spec.extensions << 'ext/vox/extconf.rb'
|
32
32
|
|
33
|
-
spec.add_dependency 'rice', '~> 2.2.0'
|
34
33
|
spec.add_development_dependency 'rake', '~> 12.3.3'
|
35
34
|
spec.add_development_dependency 'rake-compiler', '~> 1.1.1'
|
36
35
|
spec.add_development_dependency 'rspec', '~> 3.9.0'
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vox-etf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Carey
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-09-
|
11
|
+
date: 2020-09-14 00:00:00.000000000 Z
|
12
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
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: rake
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|