bin_utils 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/ext/bin_utils/extconf.rb +5 -2
- data/ext/bin_utils/native.c +962 -774
- data/lib/bin_utils.rb +3 -1
- data/lib/bin_utils/version.rb +1 -1
- metadata +13 -17
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MmIxYzY2OWZjNTMyM2YyNzI0NDBiOGEwNTc4ZDRiYmNjNTdhOWY1ZQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZDM4MzEwZGQ2OGVmOTJhMjlkY2RiMzgyMTljZDdlYmVhOTVjYmUxMg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZDE3ZTlmYjc3MDRjNzA2NTFlMzMzY2VlYzAxZjhkZWU0YzczNGU3M2NiNzgz
|
10
|
+
NDhkNjM3ZjM2NmI3ZGU1ZDA0MjNmYTFkMTRmODA4Y2JjOWFkYmJjMmUwZGQ0
|
11
|
+
M2ZmZmE3N2ViOTcxMWY4MDE4NjA0OWE4MWE4MzkxZTcyNWYzNzI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
M2QzMGE4YTdlMjBjMDg2MjUxNDM5ZjczZGMzZDA5YjViODUzYmY3MzkxN2Qy
|
14
|
+
OWMzZTBkOWRmNzlkYTY1YjVjMzI2MGMyOWI0MDBiODhjNjVmMTJlYzBhZDA1
|
15
|
+
YTY0ODlhYjdhOGFhZmNlNmI3MTFkNjYzN2EwZTk1YjM3OTgyNzI=
|
data/ext/bin_utils/extconf.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
-
|
1
|
+
begin
|
2
|
+
unless RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx'
|
3
|
+
raise "Uh"
|
4
|
+
end
|
2
5
|
require 'mkmf'
|
3
6
|
# rubinius has no rb_str_drop_bytes
|
4
7
|
have_func('rb_str_drop_bytes')
|
5
8
|
create_makefile("bin_utils")
|
6
|
-
|
9
|
+
rescue
|
7
10
|
File.open(File.dirname(__FILE__) + "/Makefile", 'w') do |f|
|
8
11
|
f.write("install:\n\t#nothing to build")
|
9
12
|
end
|
data/ext/bin_utils/native.c
CHANGED
@@ -61,16 +61,31 @@ ID rshft;
|
|
61
61
|
ID band;
|
62
62
|
#ifndef HAVE_RB_STR_DROP_BYTES
|
63
63
|
/* rubinius has no rb_str_drop_bytes */
|
64
|
-
ID
|
64
|
+
ID aslice;
|
65
65
|
static VALUE
|
66
66
|
rb_str_drop_bytes(VALUE str, long bytes)
|
67
67
|
{
|
68
|
-
VALUE args[
|
69
|
-
rb_funcall2(str,
|
68
|
+
VALUE args[2] = {0, INT2FIX(bytes)};
|
69
|
+
rb_funcall2(str, aslice, 2, args);
|
70
70
|
return str;
|
71
71
|
}
|
72
72
|
#endif
|
73
73
|
|
74
|
+
static int64_t
|
75
|
+
safe_int64_t(VALUE i)
|
76
|
+
{
|
77
|
+
if (FIXNUM_P(i)) {
|
78
|
+
return NUM2I64(i);
|
79
|
+
}
|
80
|
+
else {
|
81
|
+
VALUE argm = UINT2NUM(0xffffffff);
|
82
|
+
VALUE arg32 = INT2FIX(32);
|
83
|
+
uint64_t i0 = NUM2I64(rb_funcall2(i, band, 1, &argm));
|
84
|
+
i = rb_funcall2(i, rshft, 1, &arg32);
|
85
|
+
return i0 + (NUM2I64(rb_funcall2(i, band, 1, &argm)) << 32);
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
74
89
|
static long
|
75
90
|
check_size(long i, long strlen, long ilen)
|
76
91
|
{
|
@@ -81,788 +96,768 @@ check_size(long i, long strlen, long ilen)
|
|
81
96
|
return i;
|
82
97
|
}
|
83
98
|
|
84
|
-
static
|
85
|
-
|
99
|
+
static VALUE
|
100
|
+
check_argc(int argc, VALUE *argv)
|
86
101
|
{
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
return
|
102
|
+
if (argc == 0 || argc > 2) {
|
103
|
+
rb_raise(rb_eArgError, "accepts 1 or 2 arguments: (string[, offset=0])");
|
104
|
+
}
|
105
|
+
return argc == 2 ? argv[1] : INT2FIX(0);
|
91
106
|
}
|
92
107
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
i = check_size(i, RSTRING_LEN(rstr), 1);
|
99
|
-
return (int8_t)(RSTRING_PTR(rstr)[i]);
|
100
|
-
}
|
108
|
+
typedef struct append_args {
|
109
|
+
VALUE str;
|
110
|
+
int argc;
|
111
|
+
VALUE *argv;
|
112
|
+
} append_args;
|
101
113
|
|
102
|
-
|
103
|
-
|
114
|
+
typedef struct append_args2 {
|
115
|
+
VALUE str;
|
116
|
+
int argc;
|
117
|
+
VALUE *argv;
|
118
|
+
VALUE int0;
|
119
|
+
} append_args2;
|
120
|
+
|
121
|
+
static void
|
122
|
+
check_argc_append(int argc, VALUE *argv, append_args *args, int bits)
|
104
123
|
{
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
124
|
+
if (argc < 1) {
|
125
|
+
rb_raise(rb_eArgError, "accepts at least 1 argument: (string[, *int%ds])", bits);
|
126
|
+
}
|
127
|
+
args->str = RTEST(argv[0]) ? argv[0] : rb_str_new(0, 0);
|
128
|
+
if (argc == 2 && TYPE(argv[1]) == T_ARRAY) {
|
129
|
+
args->argc = RARRAY_LEN(argv[1]);
|
130
|
+
args->argv = RARRAY_PTR(argv[1]);
|
131
|
+
}
|
132
|
+
else {
|
133
|
+
args->argc = argc-1;
|
134
|
+
args->argv = argv+1;
|
135
|
+
}
|
114
136
|
}
|
115
137
|
|
116
|
-
static
|
117
|
-
|
138
|
+
static void
|
139
|
+
check_argc_append_2(int argc, VALUE *argv, append_args2 *args, int bits, int bits1)
|
118
140
|
{
|
119
|
-
|
120
|
-
|
141
|
+
if (argc < 2) {
|
142
|
+
rb_raise(rb_eArgError, "accepts at least 2 arguments: (string, int%d[, *int%ds])", bits, bits1);
|
143
|
+
}
|
144
|
+
args->str = RTEST(argv[0]) ? argv[0] : rb_str_new(0, 0);
|
145
|
+
args->int0 = argv[1];
|
146
|
+
if (argc == 3 && TYPE(argv[2]) == T_ARRAY) {
|
147
|
+
args->argc = RARRAY_LEN(argv[2]);
|
148
|
+
args->argv = RARRAY_PTR(argv[2]);
|
149
|
+
}
|
150
|
+
else {
|
151
|
+
args->argc = argc-2;
|
152
|
+
args->argv = argv+2;
|
153
|
+
}
|
121
154
|
}
|
122
155
|
|
123
|
-
|
124
|
-
|
156
|
+
|
157
|
+
static uint32_t
|
158
|
+
get_int8(VALUE rstr, VALUE ri)
|
125
159
|
{
|
126
160
|
long i = NUM2LONG(ri);
|
127
161
|
const uint8_t *ptr;
|
128
|
-
uint32_t byte0, byte1;
|
129
162
|
StringValue(rstr);
|
130
|
-
i = check_size(i, RSTRING_LEN(rstr),
|
163
|
+
i = check_size(i, RSTRING_LEN(rstr), 1);
|
131
164
|
ptr = (const uint8_t*)RSTRING_PTR(rstr);
|
132
|
-
|
133
|
-
|
134
|
-
|
165
|
+
return
|
166
|
+
(((uint32_t)ptr[i + 0]) << 0 ) |
|
167
|
+
(uint32_t)0;
|
135
168
|
}
|
136
169
|
|
137
170
|
static int32_t
|
138
|
-
|
171
|
+
get_sint8(VALUE rstr, VALUE ri)
|
139
172
|
{
|
140
|
-
int32_t res =
|
141
|
-
return res - ((res >>
|
173
|
+
int32_t res = (int32_t)get_int8(rstr, ri);
|
174
|
+
return res - ((res >> 7) << 8);
|
142
175
|
}
|
143
176
|
|
144
|
-
static
|
145
|
-
|
177
|
+
static VALUE
|
178
|
+
rb_get_int8(int argc, VALUE *argv, VALUE self)
|
146
179
|
{
|
147
|
-
|
148
|
-
const uint8_t *ptr;
|
149
|
-
uint32_t byte0, byte1, byte2;
|
150
|
-
StringValue(rstr);
|
151
|
-
i = check_size(i, RSTRING_LEN(rstr), 3);
|
152
|
-
ptr = (const uint8_t*)RSTRING_PTR(rstr);
|
153
|
-
byte0 = ptr[i];
|
154
|
-
byte1 = ptr[i+1];
|
155
|
-
byte2 = ptr[i+2];
|
156
|
-
return byte0 + (byte1 << 8) + (byte2 << 16);
|
180
|
+
return INT2FIX(get_int8(argv[0], check_argc(argc, argv)));
|
157
181
|
}
|
158
182
|
|
159
|
-
static
|
160
|
-
|
183
|
+
static VALUE
|
184
|
+
rb_get_sint8(int argc, VALUE *argv, VALUE self)
|
161
185
|
{
|
162
|
-
|
163
|
-
return res - ((res >> 23) << 24);
|
186
|
+
return INT2FIX(get_sint8(argv[0], check_argc(argc, argv)));
|
164
187
|
}
|
165
188
|
|
166
|
-
static
|
167
|
-
|
189
|
+
static VALUE
|
190
|
+
rb_slice_int8(VALUE self, VALUE rstr)
|
168
191
|
{
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
StringValue(rstr);
|
173
|
-
i = check_size(i, RSTRING_LEN(rstr), 3);
|
174
|
-
ptr = (const uint8_t*)RSTRING_PTR(rstr);
|
175
|
-
byte0 = ptr[i+2];
|
176
|
-
byte1 = ptr[i+1];
|
177
|
-
byte2 = ptr[i];
|
178
|
-
return byte0 + (byte1 << 8) + (byte2 << 16);
|
192
|
+
uint32_t res = get_int8(rstr, INT2FIX(0));
|
193
|
+
rb_str_drop_bytes(rstr, 1);
|
194
|
+
return INT2FIX(res);
|
179
195
|
}
|
180
196
|
|
181
|
-
static
|
182
|
-
|
197
|
+
static VALUE
|
198
|
+
rb_slice_sint8(VALUE self, VALUE rstr)
|
183
199
|
{
|
184
|
-
int32_t res =
|
185
|
-
|
200
|
+
int32_t res = get_sint8(rstr, INT2FIX(0));
|
201
|
+
rb_str_drop_bytes(rstr, 1);
|
202
|
+
return INT2FIX(res);
|
186
203
|
}
|
187
204
|
|
188
|
-
static
|
189
|
-
|
205
|
+
static void
|
206
|
+
append_int8(VALUE rstr, int32_t v)
|
190
207
|
{
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
ptr = (const uint8_t*)RSTRING_PTR(rstr);
|
197
|
-
|
198
|
-
byte0 = ptr[i];
|
199
|
-
byte1 = ptr[i+1];
|
200
|
-
byte2 = ptr[i+2];
|
201
|
-
byte3 = ptr[i+3];
|
202
|
-
return byte0 + (byte1 << 8) + (byte2 << 16) + (byte3 << 24);
|
208
|
+
char a[] = {
|
209
|
+
(v >> 0) & 0xff,
|
210
|
+
0
|
211
|
+
};
|
212
|
+
rb_str_cat(rstr, a, 1);
|
203
213
|
}
|
204
214
|
|
205
|
-
static
|
206
|
-
|
215
|
+
static VALUE
|
216
|
+
append_var_int8(int argc, VALUE* argv, VALUE str)
|
217
|
+
{
|
218
|
+
int i;
|
219
|
+
for(i = 0; i < argc; i++) {
|
220
|
+
|
221
|
+
append_int8(str, NUM2INT(argv[i]));
|
222
|
+
|
223
|
+
}
|
224
|
+
return str;
|
225
|
+
}
|
226
|
+
|
227
|
+
static VALUE
|
228
|
+
rb_append_int8(int argc, VALUE* argv, VALUE self)
|
207
229
|
{
|
208
|
-
|
230
|
+
append_args args;
|
231
|
+
check_argc_append(argc, argv, &args, 8);
|
232
|
+
return append_var_int8(args.argc, args.argv, args.str);
|
209
233
|
}
|
210
234
|
|
235
|
+
#define append_var_int8_le append_var_int8
|
236
|
+
#define append_var_int8_be append_var_int8
|
211
237
|
static uint32_t
|
212
|
-
|
238
|
+
get_int16_le(VALUE rstr, VALUE ri)
|
213
239
|
{
|
214
240
|
long i = NUM2LONG(ri);
|
215
241
|
const uint8_t *ptr;
|
216
|
-
uint32_t byte0, byte1, byte2, byte3;
|
217
242
|
StringValue(rstr);
|
218
|
-
i = check_size(i, RSTRING_LEN(rstr),
|
243
|
+
i = check_size(i, RSTRING_LEN(rstr), 2);
|
219
244
|
ptr = (const uint8_t*)RSTRING_PTR(rstr);
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
return byte0 + (byte1 << 8) + (byte2 << 16) + (byte3 << 24);
|
245
|
+
return
|
246
|
+
(((uint32_t)ptr[i + 0]) << 0 ) |
|
247
|
+
(((uint32_t)ptr[i + 1]) << 8 ) |
|
248
|
+
(uint32_t)0;
|
225
249
|
}
|
226
250
|
|
227
251
|
static int32_t
|
228
|
-
|
252
|
+
get_sint16_le(VALUE rstr, VALUE ri)
|
229
253
|
{
|
230
|
-
|
254
|
+
int32_t res = (int32_t)get_int16_le(rstr, ri);
|
255
|
+
return res - ((res >> 15) << 16);
|
231
256
|
}
|
232
257
|
|
233
|
-
static
|
234
|
-
|
258
|
+
static VALUE
|
259
|
+
rb_get_int16_le(int argc, VALUE *argv, VALUE self)
|
235
260
|
{
|
236
|
-
|
237
|
-
const uint8_t *ptr;
|
238
|
-
uint32_t byte0, byte1, byte2, byte3;
|
239
|
-
int64_t res;
|
240
|
-
StringValue(rstr);
|
241
|
-
i = check_size(i, RSTRING_LEN(rstr), 5);
|
242
|
-
ptr = (const uint8_t*)RSTRING_PTR(rstr);
|
243
|
-
|
244
|
-
byte0 = ptr[i];
|
245
|
-
byte1 = ptr[i+1];
|
246
|
-
byte2 = ptr[i+2];
|
247
|
-
byte3 = ptr[i+3];
|
248
|
-
res = byte0 + (byte1 << 8) + (byte2 << 16) + (byte3 << 24);
|
249
|
-
byte0 = ptr[i+4];
|
250
|
-
return res + ((int64_t)byte0 << 32);
|
261
|
+
return INT2FIX(get_int16_le(argv[0], check_argc(argc, argv)));
|
251
262
|
}
|
252
263
|
|
253
|
-
static
|
254
|
-
|
264
|
+
static VALUE
|
265
|
+
rb_get_sint16_le(int argc, VALUE *argv, VALUE self)
|
255
266
|
{
|
256
|
-
|
257
|
-
return res - ((res >> 39) << 40);
|
267
|
+
return INT2FIX(get_sint16_le(argv[0], check_argc(argc, argv)));
|
258
268
|
}
|
259
269
|
|
260
|
-
static
|
261
|
-
|
270
|
+
static VALUE
|
271
|
+
rb_slice_int16_le(VALUE self, VALUE rstr)
|
262
272
|
{
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
int64_t res;
|
267
|
-
StringValue(rstr);
|
268
|
-
i = check_size(i, RSTRING_LEN(rstr), 5);
|
269
|
-
ptr = (const uint8_t*)RSTRING_PTR(rstr);
|
270
|
-
|
271
|
-
byte0 = ptr[i+4];
|
272
|
-
byte1 = ptr[i+3];
|
273
|
-
byte2 = ptr[i+2];
|
274
|
-
byte3 = ptr[i+1];
|
275
|
-
res = byte0 + (byte1 << 8) + (byte2 << 16) + (byte3 << 24);
|
276
|
-
byte0 = ptr[i];
|
277
|
-
return res + ((int64_t)byte0 << 32);
|
273
|
+
uint32_t res = get_int16_le(rstr, INT2FIX(0));
|
274
|
+
rb_str_drop_bytes(rstr, 2);
|
275
|
+
return INT2FIX(res);
|
278
276
|
}
|
279
277
|
|
280
|
-
static
|
281
|
-
|
278
|
+
static VALUE
|
279
|
+
rb_slice_sint16_le(VALUE self, VALUE rstr)
|
282
280
|
{
|
283
|
-
|
284
|
-
|
281
|
+
int32_t res = get_sint16_le(rstr, INT2FIX(0));
|
282
|
+
rb_str_drop_bytes(rstr, 2);
|
283
|
+
return INT2FIX(res);
|
285
284
|
}
|
286
285
|
|
287
|
-
static
|
288
|
-
|
286
|
+
static void
|
287
|
+
append_int16_le(VALUE rstr, int32_t v)
|
289
288
|
{
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
ptr = (const uint8_t*)RSTRING_PTR(rstr);
|
297
|
-
|
298
|
-
byte0 = ptr[i];
|
299
|
-
byte1 = ptr[i+1];
|
300
|
-
byte2 = ptr[i+2];
|
301
|
-
byte3 = ptr[i+3];
|
302
|
-
res = byte0 + (byte1 << 8) + (byte2 << 16) + (byte3 << 24);
|
303
|
-
byte0 = ptr[i+4];
|
304
|
-
byte1 = ptr[i+5];
|
305
|
-
res1 = byte0 + (byte1 << 8);
|
306
|
-
return res + (res1 << 32);
|
289
|
+
char a[] = {
|
290
|
+
(v >> 0) & 0xff,
|
291
|
+
(v >> 8) & 0xff,
|
292
|
+
0
|
293
|
+
};
|
294
|
+
rb_str_cat(rstr, a, 2);
|
307
295
|
}
|
308
296
|
|
309
|
-
static
|
310
|
-
|
297
|
+
static VALUE
|
298
|
+
append_var_int16_le(int argc, VALUE* argv, VALUE str)
|
311
299
|
{
|
312
|
-
|
313
|
-
|
314
|
-
}
|
300
|
+
int i;
|
301
|
+
for(i = 0; i < argc; i++) {
|
315
302
|
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
const uint8_t *ptr;
|
321
|
-
uint32_t byte0, byte1, byte2, byte3;
|
322
|
-
int64_t res, res1;
|
323
|
-
StringValue(rstr);
|
324
|
-
i = check_size(i, RSTRING_LEN(rstr), 6);
|
325
|
-
ptr = (const uint8_t*)RSTRING_PTR(rstr);
|
326
|
-
|
327
|
-
byte0 = ptr[i+5];
|
328
|
-
byte1 = ptr[i+4];
|
329
|
-
byte2 = ptr[i+3];
|
330
|
-
byte3 = ptr[i+2];
|
331
|
-
res = byte0 + (byte1 << 8) + (byte2 << 16) + (byte3 << 24);
|
332
|
-
byte0 = ptr[i+1];
|
333
|
-
byte1 = ptr[i+0];
|
334
|
-
res1 = byte0 + (byte1 << 8);
|
335
|
-
return res + (res1 << 32);
|
303
|
+
append_int16_le(str, NUM2INT(argv[i]));
|
304
|
+
|
305
|
+
}
|
306
|
+
return str;
|
336
307
|
}
|
337
308
|
|
338
|
-
static
|
339
|
-
|
309
|
+
static VALUE
|
310
|
+
rb_append_int16_le(int argc, VALUE* argv, VALUE self)
|
340
311
|
{
|
341
|
-
|
342
|
-
|
312
|
+
append_args args;
|
313
|
+
check_argc_append(argc, argv, &args, 16);
|
314
|
+
return append_var_int16_le(args.argc, args.argv, args.str);
|
343
315
|
}
|
344
316
|
|
345
|
-
static
|
346
|
-
|
317
|
+
static uint32_t
|
318
|
+
get_int24_le(VALUE rstr, VALUE ri)
|
347
319
|
{
|
348
320
|
long i = NUM2LONG(ri);
|
349
321
|
const uint8_t *ptr;
|
350
|
-
uint32_t byte0, byte1, byte2, byte3;
|
351
|
-
int64_t res, res1;
|
352
322
|
StringValue(rstr);
|
353
|
-
i = check_size(i, RSTRING_LEN(rstr),
|
323
|
+
i = check_size(i, RSTRING_LEN(rstr), 3);
|
354
324
|
ptr = (const uint8_t*)RSTRING_PTR(rstr);
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
res = byte0 + (byte1 << 8) + (byte2 << 16) + (byte3 << 24);
|
361
|
-
byte0 = ptr[i+4];
|
362
|
-
byte1 = ptr[i+5];
|
363
|
-
byte2 = ptr[i+6];
|
364
|
-
res1 = byte0 + (byte1 << 8) + (byte2 << 16);
|
365
|
-
return res + (res1 << 32);
|
325
|
+
return
|
326
|
+
(((uint32_t)ptr[i + 0]) << 0 ) |
|
327
|
+
(((uint32_t)ptr[i + 1]) << 8 ) |
|
328
|
+
(((uint32_t)ptr[i + 2]) << 16 ) |
|
329
|
+
(uint32_t)0;
|
366
330
|
}
|
367
331
|
|
368
|
-
static
|
369
|
-
|
332
|
+
static int32_t
|
333
|
+
get_sint24_le(VALUE rstr, VALUE ri)
|
370
334
|
{
|
371
|
-
|
372
|
-
return res - ((res >>
|
335
|
+
int32_t res = (int32_t)get_int24_le(rstr, ri);
|
336
|
+
return res - ((res >> 23) << 24);
|
373
337
|
}
|
374
338
|
|
375
|
-
static
|
376
|
-
|
339
|
+
static VALUE
|
340
|
+
rb_get_int24_le(int argc, VALUE *argv, VALUE self)
|
377
341
|
{
|
378
|
-
|
379
|
-
const uint8_t *ptr;
|
380
|
-
uint32_t byte0, byte1, byte2, byte3;
|
381
|
-
int64_t res, res1;
|
382
|
-
StringValue(rstr);
|
383
|
-
i = check_size(i, RSTRING_LEN(rstr), 7);
|
384
|
-
ptr = (const uint8_t*)RSTRING_PTR(rstr);
|
385
|
-
|
386
|
-
byte0 = ptr[i+6];
|
387
|
-
byte1 = ptr[i+5];
|
388
|
-
byte2 = ptr[i+4];
|
389
|
-
byte3 = ptr[i+3];
|
390
|
-
res = byte0 + (byte1 << 8) + (byte2 << 16) + (byte3 << 24);
|
391
|
-
byte0 = ptr[i+2];
|
392
|
-
byte1 = ptr[i+1];
|
393
|
-
byte2 = ptr[i];
|
394
|
-
res1 = byte0 + (byte1 << 8) + (byte2 << 16);
|
395
|
-
return res + (res1 << 32);
|
342
|
+
return INT2FIX(get_int24_le(argv[0], check_argc(argc, argv)));
|
396
343
|
}
|
397
344
|
|
398
|
-
static
|
399
|
-
|
345
|
+
static VALUE
|
346
|
+
rb_get_sint24_le(int argc, VALUE *argv, VALUE self)
|
400
347
|
{
|
401
|
-
|
402
|
-
return res - ((res >> 55) << 56);
|
348
|
+
return INT2FIX(get_sint24_le(argv[0], check_argc(argc, argv)));
|
403
349
|
}
|
404
350
|
|
405
|
-
static
|
406
|
-
|
351
|
+
static VALUE
|
352
|
+
rb_slice_int24_le(VALUE self, VALUE rstr)
|
407
353
|
{
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
int64_t res, res1;
|
412
|
-
StringValue(rstr);
|
413
|
-
i = check_size(i, RSTRING_LEN(rstr), 8);
|
414
|
-
ptr = (const uint8_t*)RSTRING_PTR(rstr);
|
415
|
-
|
416
|
-
byte0 = ptr[i];
|
417
|
-
byte1 = ptr[i+1];
|
418
|
-
byte2 = ptr[i+2];
|
419
|
-
byte3 = ptr[i+3];
|
420
|
-
res = byte0 + (byte1 << 8) + (byte2 << 16) + (byte3 << 24);
|
421
|
-
byte0 = ptr[i+4];
|
422
|
-
byte1 = ptr[i+5];
|
423
|
-
byte2 = ptr[i+6];
|
424
|
-
byte3 = ptr[i+7];
|
425
|
-
res1 = byte0 + (byte1 << 8) + (byte2 << 16) + (byte3 << 24);
|
426
|
-
return res + (res1 << 32);
|
354
|
+
uint32_t res = get_int24_le(rstr, INT2FIX(0));
|
355
|
+
rb_str_drop_bytes(rstr, 3);
|
356
|
+
return INT2FIX(res);
|
427
357
|
}
|
428
358
|
|
429
|
-
static
|
430
|
-
|
359
|
+
static VALUE
|
360
|
+
rb_slice_sint24_le(VALUE self, VALUE rstr)
|
431
361
|
{
|
432
|
-
|
362
|
+
int32_t res = get_sint24_le(rstr, INT2FIX(0));
|
363
|
+
rb_str_drop_bytes(rstr, 3);
|
364
|
+
return INT2FIX(res);
|
433
365
|
}
|
434
366
|
|
435
|
-
static
|
436
|
-
|
367
|
+
static void
|
368
|
+
append_int24_le(VALUE rstr, int32_t v)
|
437
369
|
{
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
byte0 = ptr[i+7];
|
447
|
-
byte1 = ptr[i+6];
|
448
|
-
byte2 = ptr[i+5];
|
449
|
-
byte3 = ptr[i+4];
|
450
|
-
res = byte0 + (byte1 << 8) + (byte2 << 16) + (byte3 << 24);
|
451
|
-
byte0 = ptr[i+3];
|
452
|
-
byte1 = ptr[i+2];
|
453
|
-
byte2 = ptr[i+1];
|
454
|
-
byte3 = ptr[i];
|
455
|
-
res1 = byte0 + (byte1 << 8) + (byte2 << 16) + (byte3 << 24);
|
456
|
-
return res + (res1 << 32);
|
370
|
+
char a[] = {
|
371
|
+
(v >> 0) & 0xff,
|
372
|
+
(v >> 8) & 0xff,
|
373
|
+
(v >> 16) & 0xff,
|
374
|
+
0
|
375
|
+
};
|
376
|
+
rb_str_cat(rstr, a, 3);
|
457
377
|
}
|
458
378
|
|
459
|
-
static
|
460
|
-
|
379
|
+
static VALUE
|
380
|
+
append_var_int24_le(int argc, VALUE* argv, VALUE str)
|
461
381
|
{
|
462
|
-
|
382
|
+
int i;
|
383
|
+
for(i = 0; i < argc; i++) {
|
384
|
+
|
385
|
+
append_int24_le(str, NUM2INT(argv[i]));
|
386
|
+
|
387
|
+
}
|
388
|
+
return str;
|
463
389
|
}
|
464
390
|
|
465
|
-
static
|
466
|
-
|
391
|
+
static VALUE
|
392
|
+
rb_append_int24_le(int argc, VALUE* argv, VALUE self)
|
467
393
|
{
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
res += *ptr;
|
472
|
-
break;
|
473
|
-
}
|
474
|
-
if (res > LLU(0xFFFFFFFFFFFFFFFF) / 128) {
|
475
|
-
rb_raise(rb_eArgError, "BER integer is greater then 2**64, could not parse such big");
|
476
|
-
}
|
477
|
-
res = (res + ((*ptr) - 128)) * 128;
|
478
|
-
ptr++;
|
479
|
-
if (++(*i) >= max) {
|
480
|
-
rb_raise(rb_eArgError, "String unexpectedly finished while parsing BER integer");
|
481
|
-
}
|
482
|
-
}
|
483
|
-
return res;
|
394
|
+
append_args args;
|
395
|
+
check_argc_append(argc, argv, &args, 24);
|
396
|
+
return append_var_int24_le(args.argc, args.argv, args.str);
|
484
397
|
}
|
485
398
|
|
486
|
-
static
|
487
|
-
|
399
|
+
static uint32_t
|
400
|
+
get_int32_le(VALUE rstr, VALUE ri)
|
488
401
|
{
|
489
|
-
long i = NUM2LONG(ri)
|
402
|
+
long i = NUM2LONG(ri);
|
490
403
|
const uint8_t *ptr;
|
491
404
|
StringValue(rstr);
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
405
|
+
i = check_size(i, RSTRING_LEN(rstr), 4);
|
406
|
+
ptr = (const uint8_t*)RSTRING_PTR(rstr);
|
407
|
+
return
|
408
|
+
(((uint32_t)ptr[i + 0]) << 0 ) |
|
409
|
+
(((uint32_t)ptr[i + 1]) << 8 ) |
|
410
|
+
(((uint32_t)ptr[i + 2]) << 16 ) |
|
411
|
+
(((uint32_t)ptr[i + 3]) << 24 ) |
|
412
|
+
(uint32_t)0;
|
496
413
|
}
|
497
414
|
|
498
|
-
static
|
499
|
-
|
415
|
+
static int32_t
|
416
|
+
get_sint32_le(VALUE rstr, VALUE ri)
|
500
417
|
{
|
501
|
-
|
502
|
-
|
503
|
-
}
|
504
|
-
else {
|
505
|
-
VALUE argm = UINT2NUM(0xffffffff);
|
506
|
-
VALUE arg32 = INT2FIX(32);
|
507
|
-
uint64_t i0 = NUM2I64(rb_funcall2(i, band, 1, &argm));
|
508
|
-
i = rb_funcall2(i, rshft, 1, &arg32);
|
509
|
-
return i0 + (NUM2I64(rb_funcall2(i, band, 1, &argm)) << 32);
|
510
|
-
}
|
418
|
+
int32_t res = (int32_t)get_int32_le(rstr, ri);
|
419
|
+
return res;
|
511
420
|
}
|
512
421
|
|
513
422
|
static VALUE
|
514
|
-
|
423
|
+
rb_get_int32_le(int argc, VALUE *argv, VALUE self)
|
515
424
|
{
|
516
|
-
|
517
|
-
rb_raise(rb_eArgError, "accepts 1 or 2 arguments: (string[, offset=0])");
|
518
|
-
}
|
519
|
-
return argc == 2 ? argv[1] : INT2FIX(0);
|
425
|
+
return UINT2NUM(get_int32_le(argv[0], check_argc(argc, argv)));
|
520
426
|
}
|
521
427
|
|
522
|
-
/**** GET ****/
|
523
|
-
/**** 32bit ***/
|
524
428
|
static VALUE
|
525
|
-
|
429
|
+
rb_get_sint32_le(int argc, VALUE *argv, VALUE self)
|
526
430
|
{
|
527
|
-
return
|
431
|
+
return INT2NUM(get_sint32_le(argv[0], check_argc(argc, argv)));
|
528
432
|
}
|
529
433
|
|
530
434
|
static VALUE
|
531
|
-
|
435
|
+
rb_slice_int32_le(VALUE self, VALUE rstr)
|
532
436
|
{
|
533
|
-
|
437
|
+
uint32_t res = get_int32_le(rstr, INT2FIX(0));
|
438
|
+
rb_str_drop_bytes(rstr, 4);
|
439
|
+
return UINT2NUM(res);
|
534
440
|
}
|
535
441
|
|
536
442
|
static VALUE
|
537
|
-
|
443
|
+
rb_slice_sint32_le(VALUE self, VALUE rstr)
|
538
444
|
{
|
539
|
-
|
445
|
+
int32_t res = get_sint32_le(rstr, INT2FIX(0));
|
446
|
+
rb_str_drop_bytes(rstr, 4);
|
447
|
+
return INT2NUM(res);
|
540
448
|
}
|
541
449
|
|
542
|
-
static
|
543
|
-
|
450
|
+
static void
|
451
|
+
append_int32_le(VALUE rstr, int32_t v)
|
544
452
|
{
|
545
|
-
|
453
|
+
char a[] = {
|
454
|
+
(v >> 0) & 0xff,
|
455
|
+
(v >> 8) & 0xff,
|
456
|
+
(v >> 16) & 0xff,
|
457
|
+
(v >> 24) & 0xff,
|
458
|
+
0
|
459
|
+
};
|
460
|
+
rb_str_cat(rstr, a, 4);
|
546
461
|
}
|
547
462
|
|
548
463
|
static VALUE
|
549
|
-
|
464
|
+
append_var_int32_le(int argc, VALUE* argv, VALUE str)
|
550
465
|
{
|
551
|
-
|
552
|
-
|
466
|
+
int i;
|
467
|
+
for(i = 0; i < argc; i++) {
|
553
468
|
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
return
|
469
|
+
append_int32_le(str, (int32_t)NUM2I64(argv[i]));
|
470
|
+
|
471
|
+
}
|
472
|
+
return str;
|
558
473
|
}
|
559
474
|
|
560
475
|
static VALUE
|
561
|
-
|
476
|
+
rb_append_int32_le(int argc, VALUE* argv, VALUE self)
|
562
477
|
{
|
563
|
-
|
478
|
+
append_args args;
|
479
|
+
check_argc_append(argc, argv, &args, 32);
|
480
|
+
return append_var_int32_le(args.argc, args.argv, args.str);
|
564
481
|
}
|
565
482
|
|
566
|
-
static
|
567
|
-
|
483
|
+
static uint32_t
|
484
|
+
get_int16_be(VALUE rstr, VALUE ri)
|
568
485
|
{
|
569
|
-
|
486
|
+
long i = NUM2LONG(ri);
|
487
|
+
const uint8_t *ptr;
|
488
|
+
StringValue(rstr);
|
489
|
+
i = check_size(i, RSTRING_LEN(rstr), 2);
|
490
|
+
ptr = (const uint8_t*)RSTRING_PTR(rstr);
|
491
|
+
return
|
492
|
+
(((uint32_t)ptr[i + 1]) << 0 ) |
|
493
|
+
(((uint32_t)ptr[i + 0]) << 8 ) |
|
494
|
+
(uint32_t)0;
|
570
495
|
}
|
571
496
|
|
572
|
-
static
|
573
|
-
|
497
|
+
static int32_t
|
498
|
+
get_sint16_be(VALUE rstr, VALUE ri)
|
574
499
|
{
|
575
|
-
|
500
|
+
int32_t res = (int32_t)get_int16_be(rstr, ri);
|
501
|
+
return res - ((res >> 15) << 16);
|
576
502
|
}
|
577
503
|
|
578
504
|
static VALUE
|
579
|
-
|
505
|
+
rb_get_int16_be(int argc, VALUE *argv, VALUE self)
|
580
506
|
{
|
581
|
-
return INT2FIX(
|
507
|
+
return INT2FIX(get_int16_be(argv[0], check_argc(argc, argv)));
|
582
508
|
}
|
583
509
|
|
584
510
|
static VALUE
|
585
|
-
|
511
|
+
rb_get_sint16_be(int argc, VALUE *argv, VALUE self)
|
586
512
|
{
|
587
|
-
return
|
513
|
+
return INT2FIX(get_sint16_be(argv[0], check_argc(argc, argv)));
|
588
514
|
}
|
589
515
|
|
590
516
|
static VALUE
|
591
|
-
|
517
|
+
rb_slice_int16_be(VALUE self, VALUE rstr)
|
592
518
|
{
|
593
|
-
|
519
|
+
uint32_t res = get_int16_be(rstr, INT2FIX(0));
|
520
|
+
rb_str_drop_bytes(rstr, 2);
|
521
|
+
return INT2FIX(res);
|
594
522
|
}
|
595
523
|
|
596
524
|
static VALUE
|
597
|
-
|
525
|
+
rb_slice_sint16_be(VALUE self, VALUE rstr)
|
598
526
|
{
|
599
|
-
|
527
|
+
int32_t res = get_sint16_be(rstr, INT2FIX(0));
|
528
|
+
rb_str_drop_bytes(rstr, 2);
|
529
|
+
return INT2FIX(res);
|
600
530
|
}
|
601
531
|
|
602
|
-
static
|
603
|
-
|
532
|
+
static void
|
533
|
+
append_int16_be(VALUE rstr, int32_t v)
|
604
534
|
{
|
605
|
-
|
535
|
+
char a[] = {
|
536
|
+
(v >> 8) & 0xff,
|
537
|
+
(v >> 0) & 0xff,
|
538
|
+
0
|
539
|
+
};
|
540
|
+
rb_str_cat(rstr, a, 2);
|
606
541
|
}
|
607
|
-
/*** 32BIT END ***/
|
608
542
|
|
609
|
-
/*** 64BIT ***/
|
610
543
|
static VALUE
|
611
|
-
|
544
|
+
append_var_int16_be(int argc, VALUE* argv, VALUE str)
|
612
545
|
{
|
613
|
-
|
546
|
+
int i;
|
547
|
+
for(i = 0; i < argc; i++) {
|
548
|
+
|
549
|
+
append_int16_be(str, NUM2INT(argv[i]));
|
550
|
+
|
551
|
+
}
|
552
|
+
return str;
|
614
553
|
}
|
615
554
|
|
616
555
|
static VALUE
|
617
|
-
|
556
|
+
rb_append_int16_be(int argc, VALUE* argv, VALUE self)
|
618
557
|
{
|
619
|
-
|
558
|
+
append_args args;
|
559
|
+
check_argc_append(argc, argv, &args, 16);
|
560
|
+
return append_var_int16_be(args.argc, args.argv, args.str);
|
620
561
|
}
|
621
562
|
|
622
|
-
static
|
623
|
-
|
563
|
+
static uint32_t
|
564
|
+
get_int24_be(VALUE rstr, VALUE ri)
|
624
565
|
{
|
625
|
-
|
566
|
+
long i = NUM2LONG(ri);
|
567
|
+
const uint8_t *ptr;
|
568
|
+
StringValue(rstr);
|
569
|
+
i = check_size(i, RSTRING_LEN(rstr), 3);
|
570
|
+
ptr = (const uint8_t*)RSTRING_PTR(rstr);
|
571
|
+
return
|
572
|
+
(((uint32_t)ptr[i + 2]) << 0 ) |
|
573
|
+
(((uint32_t)ptr[i + 1]) << 8 ) |
|
574
|
+
(((uint32_t)ptr[i + 0]) << 16 ) |
|
575
|
+
(uint32_t)0;
|
626
576
|
}
|
627
577
|
|
628
|
-
static
|
629
|
-
|
578
|
+
static int32_t
|
579
|
+
get_sint24_be(VALUE rstr, VALUE ri)
|
630
580
|
{
|
631
|
-
|
581
|
+
int32_t res = (int32_t)get_int24_be(rstr, ri);
|
582
|
+
return res - ((res >> 23) << 24);
|
632
583
|
}
|
633
584
|
|
634
585
|
static VALUE
|
635
|
-
|
586
|
+
rb_get_int24_be(int argc, VALUE *argv, VALUE self)
|
636
587
|
{
|
637
|
-
return
|
588
|
+
return INT2FIX(get_int24_be(argv[0], check_argc(argc, argv)));
|
638
589
|
}
|
639
590
|
|
640
591
|
static VALUE
|
641
|
-
|
592
|
+
rb_get_sint24_be(int argc, VALUE *argv, VALUE self)
|
642
593
|
{
|
643
|
-
return
|
594
|
+
return INT2FIX(get_sint24_be(argv[0], check_argc(argc, argv)));
|
644
595
|
}
|
645
596
|
|
646
597
|
static VALUE
|
647
|
-
|
598
|
+
rb_slice_int24_be(VALUE self, VALUE rstr)
|
648
599
|
{
|
649
|
-
|
600
|
+
uint32_t res = get_int24_be(rstr, INT2FIX(0));
|
601
|
+
rb_str_drop_bytes(rstr, 3);
|
602
|
+
return INT2FIX(res);
|
650
603
|
}
|
651
604
|
|
652
605
|
static VALUE
|
653
|
-
|
606
|
+
rb_slice_sint24_be(VALUE self, VALUE rstr)
|
654
607
|
{
|
655
|
-
|
608
|
+
int32_t res = get_sint24_be(rstr, INT2FIX(0));
|
609
|
+
rb_str_drop_bytes(rstr, 3);
|
610
|
+
return INT2FIX(res);
|
656
611
|
}
|
657
612
|
|
658
|
-
static
|
659
|
-
|
613
|
+
static void
|
614
|
+
append_int24_be(VALUE rstr, int32_t v)
|
660
615
|
{
|
661
|
-
|
616
|
+
char a[] = {
|
617
|
+
(v >> 16) & 0xff,
|
618
|
+
(v >> 8) & 0xff,
|
619
|
+
(v >> 0) & 0xff,
|
620
|
+
0
|
621
|
+
};
|
622
|
+
rb_str_cat(rstr, a, 3);
|
662
623
|
}
|
663
624
|
|
664
625
|
static VALUE
|
665
|
-
|
626
|
+
append_var_int24_be(int argc, VALUE* argv, VALUE str)
|
666
627
|
{
|
667
|
-
|
628
|
+
int i;
|
629
|
+
for(i = 0; i < argc; i++) {
|
630
|
+
|
631
|
+
append_int24_be(str, NUM2INT(argv[i]));
|
632
|
+
|
633
|
+
}
|
634
|
+
return str;
|
668
635
|
}
|
669
636
|
|
670
637
|
static VALUE
|
671
|
-
|
638
|
+
rb_append_int24_be(int argc, VALUE* argv, VALUE self)
|
672
639
|
{
|
673
|
-
|
640
|
+
append_args args;
|
641
|
+
check_argc_append(argc, argv, &args, 24);
|
642
|
+
return append_var_int24_be(args.argc, args.argv, args.str);
|
674
643
|
}
|
675
644
|
|
676
|
-
static
|
677
|
-
|
645
|
+
static uint32_t
|
646
|
+
get_int32_be(VALUE rstr, VALUE ri)
|
678
647
|
{
|
679
|
-
|
648
|
+
long i = NUM2LONG(ri);
|
649
|
+
const uint8_t *ptr;
|
650
|
+
StringValue(rstr);
|
651
|
+
i = check_size(i, RSTRING_LEN(rstr), 4);
|
652
|
+
ptr = (const uint8_t*)RSTRING_PTR(rstr);
|
653
|
+
return
|
654
|
+
(((uint32_t)ptr[i + 3]) << 0 ) |
|
655
|
+
(((uint32_t)ptr[i + 2]) << 8 ) |
|
656
|
+
(((uint32_t)ptr[i + 1]) << 16 ) |
|
657
|
+
(((uint32_t)ptr[i + 0]) << 24 ) |
|
658
|
+
(uint32_t)0;
|
680
659
|
}
|
681
660
|
|
682
|
-
static
|
683
|
-
|
661
|
+
static int32_t
|
662
|
+
get_sint32_be(VALUE rstr, VALUE ri)
|
684
663
|
{
|
685
|
-
|
664
|
+
int32_t res = (int32_t)get_int32_be(rstr, ri);
|
665
|
+
return res;
|
686
666
|
}
|
687
667
|
|
688
668
|
static VALUE
|
689
|
-
|
669
|
+
rb_get_int32_be(int argc, VALUE *argv, VALUE self)
|
690
670
|
{
|
691
|
-
return
|
671
|
+
return UINT2NUM(get_int32_be(argv[0], check_argc(argc, argv)));
|
692
672
|
}
|
693
673
|
|
694
674
|
static VALUE
|
695
|
-
|
675
|
+
rb_get_sint32_be(int argc, VALUE *argv, VALUE self)
|
696
676
|
{
|
697
|
-
return
|
677
|
+
return INT2NUM(get_sint32_be(argv[0], check_argc(argc, argv)));
|
698
678
|
}
|
699
679
|
|
700
680
|
static VALUE
|
701
|
-
|
681
|
+
rb_slice_int32_be(VALUE self, VALUE rstr)
|
702
682
|
{
|
703
|
-
|
683
|
+
uint32_t res = get_int32_be(rstr, INT2FIX(0));
|
684
|
+
rb_str_drop_bytes(rstr, 4);
|
685
|
+
return UINT2NUM(res);
|
704
686
|
}
|
705
|
-
/*** 64BIT END ***/
|
706
687
|
|
707
688
|
static VALUE
|
708
|
-
|
689
|
+
rb_slice_sint32_be(VALUE self, VALUE rstr)
|
709
690
|
{
|
710
|
-
|
691
|
+
int32_t res = get_sint32_be(rstr, INT2FIX(0));
|
692
|
+
rb_str_drop_bytes(rstr, 4);
|
693
|
+
return INT2NUM(res);
|
711
694
|
}
|
712
|
-
/** GET END **/
|
713
695
|
|
714
|
-
|
715
|
-
|
716
|
-
static VALUE
|
717
|
-
rb_slice_int8(VALUE self, VALUE rstr)
|
696
|
+
static void
|
697
|
+
append_int32_be(VALUE rstr, int32_t v)
|
718
698
|
{
|
719
|
-
|
720
|
-
|
721
|
-
|
699
|
+
char a[] = {
|
700
|
+
(v >> 24) & 0xff,
|
701
|
+
(v >> 16) & 0xff,
|
702
|
+
(v >> 8) & 0xff,
|
703
|
+
(v >> 0) & 0xff,
|
704
|
+
0
|
705
|
+
};
|
706
|
+
rb_str_cat(rstr, a, 4);
|
722
707
|
}
|
723
708
|
|
724
709
|
static VALUE
|
725
|
-
|
710
|
+
append_var_int32_be(int argc, VALUE* argv, VALUE str)
|
726
711
|
{
|
727
|
-
|
728
|
-
|
729
|
-
return INT2FIX(res);
|
730
|
-
}
|
712
|
+
int i;
|
713
|
+
for(i = 0; i < argc; i++) {
|
731
714
|
|
732
|
-
|
733
|
-
rb_slice_int16_le(VALUE self, VALUE rstr)
|
734
|
-
{
|
735
|
-
int32_t res = get_int16_le(rstr, INT2FIX(0));
|
736
|
-
rb_str_drop_bytes(rstr, 2);
|
737
|
-
return INT2FIX(res);
|
738
|
-
}
|
715
|
+
append_int32_be(str, (int32_t)NUM2I64(argv[i]));
|
739
716
|
|
740
|
-
|
741
|
-
|
742
|
-
{
|
743
|
-
int32_t res = get_sint16_le(rstr, INT2FIX(0));
|
744
|
-
rb_str_drop_bytes(rstr, 2);
|
745
|
-
return INT2FIX(res);
|
717
|
+
}
|
718
|
+
return str;
|
746
719
|
}
|
747
720
|
|
748
721
|
static VALUE
|
749
|
-
|
722
|
+
rb_append_int32_be(int argc, VALUE* argv, VALUE self)
|
750
723
|
{
|
751
|
-
|
752
|
-
|
753
|
-
return
|
724
|
+
append_args args;
|
725
|
+
check_argc_append(argc, argv, &args, 32);
|
726
|
+
return append_var_int32_be(args.argc, args.argv, args.str);
|
754
727
|
}
|
755
728
|
|
756
|
-
|
757
|
-
|
729
|
+
|
730
|
+
|
731
|
+
|
732
|
+
static uint64_t
|
733
|
+
get_int40_le(VALUE rstr, VALUE ri)
|
758
734
|
{
|
759
|
-
|
760
|
-
|
761
|
-
|
735
|
+
long i = NUM2LONG(ri);
|
736
|
+
const uint8_t *ptr;
|
737
|
+
StringValue(rstr);
|
738
|
+
i = check_size(i, RSTRING_LEN(rstr), 5);
|
739
|
+
ptr = (const uint8_t*)RSTRING_PTR(rstr);
|
740
|
+
return (uint64_t)(
|
741
|
+
(((uint32_t)ptr[i + 0]) << 0) |
|
742
|
+
(((uint32_t)ptr[i + 1]) << 8) |
|
743
|
+
(((uint32_t)ptr[i + 2]) << 16) |
|
744
|
+
(((uint32_t)ptr[i + 3]) << 24) |
|
745
|
+
0) | ((uint64_t)(
|
746
|
+
(((uint32_t)ptr[i + 4]) << 0) |
|
747
|
+
0) << 32);
|
762
748
|
}
|
763
749
|
|
764
|
-
static
|
765
|
-
|
750
|
+
static int64_t
|
751
|
+
get_sint40_le(VALUE rstr, VALUE ri)
|
766
752
|
{
|
767
|
-
|
768
|
-
|
769
|
-
return INT2FIX(res);
|
753
|
+
int64_t res = (int64_t)get_int40_le(rstr, ri);
|
754
|
+
return res - ((res >> 39) << 40);
|
770
755
|
}
|
771
756
|
|
772
757
|
static VALUE
|
773
|
-
|
758
|
+
rb_get_int40_le(int argc, VALUE *argv, VALUE self)
|
774
759
|
{
|
775
|
-
|
776
|
-
rb_str_drop_bytes(rstr, 3);
|
777
|
-
return INT2FIX(res);
|
760
|
+
return I642NUM(get_int40_le(argv[0], check_argc(argc, argv)));
|
778
761
|
}
|
779
762
|
|
780
763
|
static VALUE
|
781
|
-
|
764
|
+
rb_get_sint40_le(int argc, VALUE *argv, VALUE self)
|
782
765
|
{
|
783
|
-
|
784
|
-
rb_str_drop_bytes(rstr, 3);
|
785
|
-
return INT2FIX(res);
|
766
|
+
return I642NUM(get_sint40_le(argv[0], check_argc(argc, argv)));
|
786
767
|
}
|
787
768
|
|
788
769
|
static VALUE
|
789
|
-
|
770
|
+
rb_slice_int40_le(VALUE self, VALUE rstr)
|
790
771
|
{
|
791
|
-
|
792
|
-
rb_str_drop_bytes(rstr,
|
793
|
-
return
|
772
|
+
uint64_t res = get_int40_le(rstr, INT2FIX(0));
|
773
|
+
rb_str_drop_bytes(rstr, 5);
|
774
|
+
return I642NUM(res);
|
794
775
|
}
|
795
776
|
|
796
777
|
static VALUE
|
797
|
-
|
778
|
+
rb_slice_sint40_le(VALUE self, VALUE rstr)
|
798
779
|
{
|
799
|
-
|
800
|
-
rb_str_drop_bytes(rstr,
|
801
|
-
return
|
780
|
+
uint64_t res = get_sint40_le(rstr, INT2FIX(0));
|
781
|
+
rb_str_drop_bytes(rstr, 5);
|
782
|
+
return I642NUM(res);
|
802
783
|
}
|
803
784
|
|
804
|
-
static
|
805
|
-
|
785
|
+
static void
|
786
|
+
append_int40_le(VALUE rstr, int64_t v)
|
806
787
|
{
|
807
|
-
|
808
|
-
|
809
|
-
|
788
|
+
char a[] = {
|
789
|
+
(v >> 0) & 0xff,
|
790
|
+
(v >> 8) & 0xff,
|
791
|
+
(v >> 16) & 0xff,
|
792
|
+
(v >> 24) & 0xff,
|
793
|
+
(v >> 32) & 0xff,
|
794
|
+
0
|
795
|
+
};
|
796
|
+
rb_str_cat(rstr, a, 5);
|
810
797
|
}
|
811
798
|
|
812
799
|
static VALUE
|
813
|
-
|
800
|
+
append_var_int40_le(int argc, VALUE* argv, VALUE str)
|
814
801
|
{
|
815
|
-
|
816
|
-
|
817
|
-
|
802
|
+
int i;
|
803
|
+
for(i = 0; i < argc; i++) {
|
804
|
+
|
805
|
+
append_int40_le(str, NUM2I64(argv[i]));
|
806
|
+
|
807
|
+
}
|
808
|
+
return str;
|
818
809
|
}
|
819
810
|
|
820
811
|
static VALUE
|
821
|
-
|
812
|
+
rb_append_int40_le(int argc, VALUE* argv, VALUE self)
|
822
813
|
{
|
823
|
-
|
824
|
-
|
825
|
-
return
|
814
|
+
append_args args;
|
815
|
+
check_argc_append(argc, argv, &args, 40);
|
816
|
+
return append_var_int40_le(args.argc, args.argv, args.str);
|
826
817
|
}
|
827
|
-
/*** 32BIT END ***/
|
828
818
|
|
829
|
-
|
830
|
-
|
831
|
-
rb_slice_int40_le(VALUE self, VALUE rstr)
|
819
|
+
static uint64_t
|
820
|
+
get_int48_le(VALUE rstr, VALUE ri)
|
832
821
|
{
|
833
|
-
|
834
|
-
|
835
|
-
|
822
|
+
long i = NUM2LONG(ri);
|
823
|
+
const uint8_t *ptr;
|
824
|
+
StringValue(rstr);
|
825
|
+
i = check_size(i, RSTRING_LEN(rstr), 6);
|
826
|
+
ptr = (const uint8_t*)RSTRING_PTR(rstr);
|
827
|
+
return (uint64_t)(
|
828
|
+
(((uint32_t)ptr[i + 0]) << 0) |
|
829
|
+
(((uint32_t)ptr[i + 1]) << 8) |
|
830
|
+
(((uint32_t)ptr[i + 2]) << 16) |
|
831
|
+
(((uint32_t)ptr[i + 3]) << 24) |
|
832
|
+
0) | ((uint64_t)(
|
833
|
+
(((uint32_t)ptr[i + 4]) << 0) |
|
834
|
+
(((uint32_t)ptr[i + 5]) << 8) |
|
835
|
+
0) << 32);
|
836
836
|
}
|
837
837
|
|
838
|
-
static
|
839
|
-
|
838
|
+
static int64_t
|
839
|
+
get_sint48_le(VALUE rstr, VALUE ri)
|
840
840
|
{
|
841
|
-
int64_t res =
|
842
|
-
|
843
|
-
return I642NUM(res);
|
841
|
+
int64_t res = (int64_t)get_int48_le(rstr, ri);
|
842
|
+
return res - ((res >> 47) << 48);
|
844
843
|
}
|
845
844
|
|
846
845
|
static VALUE
|
847
|
-
|
846
|
+
rb_get_int48_le(int argc, VALUE *argv, VALUE self)
|
848
847
|
{
|
849
|
-
|
850
|
-
rb_str_drop_bytes(rstr, 5);
|
851
|
-
return I642NUM(res);
|
848
|
+
return I642NUM(get_int48_le(argv[0], check_argc(argc, argv)));
|
852
849
|
}
|
853
850
|
|
854
851
|
static VALUE
|
855
|
-
|
852
|
+
rb_get_sint48_le(int argc, VALUE *argv, VALUE self)
|
856
853
|
{
|
857
|
-
|
858
|
-
rb_str_drop_bytes(rstr, 5);
|
859
|
-
return I642NUM(res);
|
854
|
+
return I642NUM(get_sint48_le(argv[0], check_argc(argc, argv)));
|
860
855
|
}
|
861
856
|
|
862
857
|
static VALUE
|
863
858
|
rb_slice_int48_le(VALUE self, VALUE rstr)
|
864
859
|
{
|
865
|
-
|
860
|
+
uint64_t res = get_int48_le(rstr, INT2FIX(0));
|
866
861
|
rb_str_drop_bytes(rstr, 6);
|
867
862
|
return I642NUM(res);
|
868
863
|
}
|
@@ -870,476 +865,669 @@ rb_slice_int48_le(VALUE self, VALUE rstr)
|
|
870
865
|
static VALUE
|
871
866
|
rb_slice_sint48_le(VALUE self, VALUE rstr)
|
872
867
|
{
|
873
|
-
|
868
|
+
uint64_t res = get_sint48_le(rstr, INT2FIX(0));
|
874
869
|
rb_str_drop_bytes(rstr, 6);
|
875
870
|
return I642NUM(res);
|
876
871
|
}
|
877
872
|
|
878
|
-
static
|
879
|
-
|
873
|
+
static void
|
874
|
+
append_int48_le(VALUE rstr, int64_t v)
|
880
875
|
{
|
881
|
-
|
882
|
-
|
883
|
-
|
876
|
+
char a[] = {
|
877
|
+
(v >> 0) & 0xff,
|
878
|
+
(v >> 8) & 0xff,
|
879
|
+
(v >> 16) & 0xff,
|
880
|
+
(v >> 24) & 0xff,
|
881
|
+
(v >> 32) & 0xff,
|
882
|
+
(v >> 40) & 0xff,
|
883
|
+
0
|
884
|
+
};
|
885
|
+
rb_str_cat(rstr, a, 6);
|
884
886
|
}
|
885
887
|
|
886
888
|
static VALUE
|
887
|
-
|
889
|
+
append_var_int48_le(int argc, VALUE* argv, VALUE str)
|
888
890
|
{
|
889
|
-
|
890
|
-
|
891
|
-
|
891
|
+
int i;
|
892
|
+
for(i = 0; i < argc; i++) {
|
893
|
+
|
894
|
+
append_int48_le(str, NUM2I64(argv[i]));
|
895
|
+
|
896
|
+
}
|
897
|
+
return str;
|
892
898
|
}
|
893
899
|
|
894
900
|
static VALUE
|
895
|
-
|
901
|
+
rb_append_int48_le(int argc, VALUE* argv, VALUE self)
|
896
902
|
{
|
897
|
-
|
898
|
-
|
899
|
-
return
|
903
|
+
append_args args;
|
904
|
+
check_argc_append(argc, argv, &args, 48);
|
905
|
+
return append_var_int48_le(args.argc, args.argv, args.str);
|
906
|
+
}
|
907
|
+
|
908
|
+
static uint64_t
|
909
|
+
get_int56_le(VALUE rstr, VALUE ri)
|
910
|
+
{
|
911
|
+
long i = NUM2LONG(ri);
|
912
|
+
const uint8_t *ptr;
|
913
|
+
StringValue(rstr);
|
914
|
+
i = check_size(i, RSTRING_LEN(rstr), 7);
|
915
|
+
ptr = (const uint8_t*)RSTRING_PTR(rstr);
|
916
|
+
return (uint64_t)(
|
917
|
+
(((uint32_t)ptr[i + 0]) << 0) |
|
918
|
+
(((uint32_t)ptr[i + 1]) << 8) |
|
919
|
+
(((uint32_t)ptr[i + 2]) << 16) |
|
920
|
+
(((uint32_t)ptr[i + 3]) << 24) |
|
921
|
+
0) | ((uint64_t)(
|
922
|
+
(((uint32_t)ptr[i + 4]) << 0) |
|
923
|
+
(((uint32_t)ptr[i + 5]) << 8) |
|
924
|
+
(((uint32_t)ptr[i + 6]) << 16) |
|
925
|
+
0) << 32);
|
926
|
+
}
|
927
|
+
|
928
|
+
static int64_t
|
929
|
+
get_sint56_le(VALUE rstr, VALUE ri)
|
930
|
+
{
|
931
|
+
int64_t res = (int64_t)get_int56_le(rstr, ri);
|
932
|
+
return res - ((res >> 55) << 56);
|
900
933
|
}
|
901
934
|
|
902
935
|
static VALUE
|
903
|
-
|
936
|
+
rb_get_int56_le(int argc, VALUE *argv, VALUE self)
|
904
937
|
{
|
905
|
-
|
906
|
-
rb_str_drop_bytes(rstr, 7);
|
907
|
-
return I642NUM(res);
|
938
|
+
return I642NUM(get_int56_le(argv[0], check_argc(argc, argv)));
|
908
939
|
}
|
909
940
|
|
910
941
|
static VALUE
|
911
|
-
|
942
|
+
rb_get_sint56_le(int argc, VALUE *argv, VALUE self)
|
912
943
|
{
|
913
|
-
|
914
|
-
rb_str_drop_bytes(rstr, 7);
|
915
|
-
return I642NUM(res);
|
944
|
+
return I642NUM(get_sint56_le(argv[0], check_argc(argc, argv)));
|
916
945
|
}
|
917
946
|
|
918
947
|
static VALUE
|
919
|
-
|
948
|
+
rb_slice_int56_le(VALUE self, VALUE rstr)
|
920
949
|
{
|
921
|
-
|
950
|
+
uint64_t res = get_int56_le(rstr, INT2FIX(0));
|
922
951
|
rb_str_drop_bytes(rstr, 7);
|
923
952
|
return I642NUM(res);
|
924
953
|
}
|
925
954
|
|
926
955
|
static VALUE
|
927
|
-
|
956
|
+
rb_slice_sint56_le(VALUE self, VALUE rstr)
|
928
957
|
{
|
929
|
-
uint64_t res =
|
930
|
-
rb_str_drop_bytes(rstr,
|
931
|
-
return
|
958
|
+
uint64_t res = get_sint56_le(rstr, INT2FIX(0));
|
959
|
+
rb_str_drop_bytes(rstr, 7);
|
960
|
+
return I642NUM(res);
|
932
961
|
}
|
933
962
|
|
934
|
-
static
|
935
|
-
|
963
|
+
static void
|
964
|
+
append_int56_le(VALUE rstr, int64_t v)
|
936
965
|
{
|
937
|
-
|
938
|
-
|
939
|
-
|
966
|
+
char a[] = {
|
967
|
+
(v >> 0) & 0xff,
|
968
|
+
(v >> 8) & 0xff,
|
969
|
+
(v >> 16) & 0xff,
|
970
|
+
(v >> 24) & 0xff,
|
971
|
+
(v >> 32) & 0xff,
|
972
|
+
(v >> 40) & 0xff,
|
973
|
+
(v >> 48) & 0xff,
|
974
|
+
0
|
975
|
+
};
|
976
|
+
rb_str_cat(rstr, a, 7);
|
940
977
|
}
|
941
978
|
|
942
979
|
static VALUE
|
943
|
-
|
980
|
+
append_var_int56_le(int argc, VALUE* argv, VALUE str)
|
944
981
|
{
|
945
|
-
|
946
|
-
|
947
|
-
|
982
|
+
int i;
|
983
|
+
for(i = 0; i < argc; i++) {
|
984
|
+
|
985
|
+
append_int56_le(str, NUM2I64(argv[i]));
|
986
|
+
|
987
|
+
}
|
988
|
+
return str;
|
948
989
|
}
|
949
990
|
|
950
991
|
static VALUE
|
951
|
-
|
992
|
+
rb_append_int56_le(int argc, VALUE* argv, VALUE self)
|
952
993
|
{
|
953
|
-
|
954
|
-
|
955
|
-
return
|
994
|
+
append_args args;
|
995
|
+
check_argc_append(argc, argv, &args, 56);
|
996
|
+
return append_var_int56_le(args.argc, args.argv, args.str);
|
956
997
|
}
|
957
|
-
/*** 64BIT END ***/
|
958
998
|
|
959
999
|
static uint64_t
|
960
|
-
|
1000
|
+
get_int64_le(VALUE rstr, VALUE ri)
|
961
1001
|
{
|
962
|
-
long
|
1002
|
+
long i = NUM2LONG(ri);
|
963
1003
|
const uint8_t *ptr;
|
964
1004
|
StringValue(rstr);
|
965
|
-
|
1005
|
+
i = check_size(i, RSTRING_LEN(rstr), 8);
|
966
1006
|
ptr = (const uint8_t*)RSTRING_PTR(rstr);
|
967
|
-
return
|
1007
|
+
return (uint64_t)(
|
1008
|
+
(((uint32_t)ptr[i + 0]) << 0) |
|
1009
|
+
(((uint32_t)ptr[i + 1]) << 8) |
|
1010
|
+
(((uint32_t)ptr[i + 2]) << 16) |
|
1011
|
+
(((uint32_t)ptr[i + 3]) << 24) |
|
1012
|
+
0) | ((uint64_t)(
|
1013
|
+
(((uint32_t)ptr[i + 4]) << 0) |
|
1014
|
+
(((uint32_t)ptr[i + 5]) << 8) |
|
1015
|
+
(((uint32_t)ptr[i + 6]) << 16) |
|
1016
|
+
(((uint32_t)ptr[i + 7]) << 24) |
|
1017
|
+
0) << 32);
|
1018
|
+
}
|
1019
|
+
|
1020
|
+
static int64_t
|
1021
|
+
get_sint64_le(VALUE rstr, VALUE ri)
|
1022
|
+
{
|
1023
|
+
int64_t res = (int64_t)get_int64_le(rstr, ri);
|
1024
|
+
return res;
|
968
1025
|
}
|
969
1026
|
|
970
1027
|
static VALUE
|
971
|
-
|
1028
|
+
rb_get_int64_le(int argc, VALUE *argv, VALUE self)
|
972
1029
|
{
|
973
|
-
|
974
|
-
|
975
|
-
|
1030
|
+
return U642NUM(get_int64_le(argv[0], check_argc(argc, argv)));
|
1031
|
+
}
|
1032
|
+
|
1033
|
+
static VALUE
|
1034
|
+
rb_get_sint64_le(int argc, VALUE *argv, VALUE self)
|
1035
|
+
{
|
1036
|
+
return I642NUM(get_sint64_le(argv[0], check_argc(argc, argv)));
|
1037
|
+
}
|
1038
|
+
|
1039
|
+
static VALUE
|
1040
|
+
rb_slice_int64_le(VALUE self, VALUE rstr)
|
1041
|
+
{
|
1042
|
+
uint64_t res = get_int64_le(rstr, INT2FIX(0));
|
1043
|
+
rb_str_drop_bytes(rstr, 8);
|
976
1044
|
return U642NUM(res);
|
977
1045
|
}
|
978
|
-
/** SLICE END **/
|
979
1046
|
|
980
|
-
|
981
|
-
|
982
|
-
append_int8(VALUE rstr, int32_t v)
|
1047
|
+
static VALUE
|
1048
|
+
rb_slice_sint64_le(VALUE self, VALUE rstr)
|
983
1049
|
{
|
984
|
-
|
985
|
-
|
1050
|
+
uint64_t res = get_sint64_le(rstr, INT2FIX(0));
|
1051
|
+
rb_str_drop_bytes(rstr, 8);
|
1052
|
+
return I642NUM(res);
|
986
1053
|
}
|
987
1054
|
|
988
1055
|
static void
|
989
|
-
|
1056
|
+
append_int64_le(VALUE rstr, int64_t v)
|
990
1057
|
{
|
991
|
-
char a[
|
992
|
-
|
1058
|
+
char a[] = {
|
1059
|
+
(v >> 0) & 0xff,
|
1060
|
+
(v >> 8) & 0xff,
|
1061
|
+
(v >> 16) & 0xff,
|
1062
|
+
(v >> 24) & 0xff,
|
1063
|
+
(v >> 32) & 0xff,
|
1064
|
+
(v >> 40) & 0xff,
|
1065
|
+
(v >> 48) & 0xff,
|
1066
|
+
(v >> 56) & 0xff,
|
1067
|
+
0
|
1068
|
+
};
|
1069
|
+
rb_str_cat(rstr, a, 8);
|
993
1070
|
}
|
994
1071
|
|
995
|
-
static
|
996
|
-
|
1072
|
+
static VALUE
|
1073
|
+
append_var_int64_le(int argc, VALUE* argv, VALUE str)
|
997
1074
|
{
|
998
|
-
|
999
|
-
|
1075
|
+
int i;
|
1076
|
+
for(i = 0; i < argc; i++) {
|
1077
|
+
|
1078
|
+
append_int64_le(str, safe_int64_t(argv[i]));
|
1079
|
+
|
1080
|
+
}
|
1081
|
+
return str;
|
1000
1082
|
}
|
1001
1083
|
|
1002
|
-
static
|
1003
|
-
|
1084
|
+
static VALUE
|
1085
|
+
rb_append_int64_le(int argc, VALUE* argv, VALUE self)
|
1004
1086
|
{
|
1005
|
-
|
1006
|
-
|
1087
|
+
append_args args;
|
1088
|
+
check_argc_append(argc, argv, &args, 64);
|
1089
|
+
return append_var_int64_le(args.argc, args.argv, args.str);
|
1007
1090
|
}
|
1008
1091
|
|
1009
|
-
static
|
1010
|
-
|
1092
|
+
static uint64_t
|
1093
|
+
get_int40_be(VALUE rstr, VALUE ri)
|
1011
1094
|
{
|
1012
|
-
|
1013
|
-
|
1095
|
+
long i = NUM2LONG(ri);
|
1096
|
+
const uint8_t *ptr;
|
1097
|
+
StringValue(rstr);
|
1098
|
+
i = check_size(i, RSTRING_LEN(rstr), 5);
|
1099
|
+
ptr = (const uint8_t*)RSTRING_PTR(rstr);
|
1100
|
+
return (uint64_t)(
|
1101
|
+
(((uint32_t)ptr[i + 4]) << 0) |
|
1102
|
+
(((uint32_t)ptr[i + 3]) << 8) |
|
1103
|
+
(((uint32_t)ptr[i + 2]) << 16) |
|
1104
|
+
(((uint32_t)ptr[i + 1]) << 24) |
|
1105
|
+
0) | ((uint64_t)(
|
1106
|
+
(((uint32_t)ptr[i + 0]) << 0) |
|
1107
|
+
0) << 32);
|
1014
1108
|
}
|
1015
1109
|
|
1016
|
-
static
|
1017
|
-
|
1110
|
+
static int64_t
|
1111
|
+
get_sint40_be(VALUE rstr, VALUE ri)
|
1018
1112
|
{
|
1019
|
-
|
1020
|
-
|
1113
|
+
int64_t res = (int64_t)get_int40_be(rstr, ri);
|
1114
|
+
return res - ((res >> 39) << 40);
|
1021
1115
|
}
|
1022
1116
|
|
1023
|
-
static
|
1024
|
-
|
1117
|
+
static VALUE
|
1118
|
+
rb_get_int40_be(int argc, VALUE *argv, VALUE self)
|
1025
1119
|
{
|
1026
|
-
|
1027
|
-
rb_str_cat(rstr, a, 4);
|
1120
|
+
return I642NUM(get_int40_be(argv[0], check_argc(argc, argv)));
|
1028
1121
|
}
|
1029
1122
|
|
1030
|
-
static
|
1031
|
-
|
1123
|
+
static VALUE
|
1124
|
+
rb_get_sint40_be(int argc, VALUE *argv, VALUE self)
|
1032
1125
|
{
|
1033
|
-
|
1034
|
-
(v >> 32) & 255};
|
1035
|
-
rb_str_cat(rstr, a, 5);
|
1126
|
+
return I642NUM(get_sint40_be(argv[0], check_argc(argc, argv)));
|
1036
1127
|
}
|
1037
1128
|
|
1038
|
-
static
|
1039
|
-
|
1129
|
+
static VALUE
|
1130
|
+
rb_slice_int40_be(VALUE self, VALUE rstr)
|
1040
1131
|
{
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1132
|
+
uint64_t res = get_int40_be(rstr, INT2FIX(0));
|
1133
|
+
rb_str_drop_bytes(rstr, 5);
|
1134
|
+
return I642NUM(res);
|
1044
1135
|
}
|
1045
1136
|
|
1046
|
-
static
|
1047
|
-
|
1137
|
+
static VALUE
|
1138
|
+
rb_slice_sint40_be(VALUE self, VALUE rstr)
|
1048
1139
|
{
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1140
|
+
uint64_t res = get_sint40_be(rstr, INT2FIX(0));
|
1141
|
+
rb_str_drop_bytes(rstr, 5);
|
1142
|
+
return I642NUM(res);
|
1052
1143
|
}
|
1053
1144
|
|
1054
1145
|
static void
|
1055
|
-
|
1146
|
+
append_int40_be(VALUE rstr, int64_t v)
|
1056
1147
|
{
|
1057
|
-
char a[
|
1058
|
-
|
1059
|
-
|
1148
|
+
char a[] = {
|
1149
|
+
(v >> 32) & 0xff,
|
1150
|
+
(v >> 24) & 0xff,
|
1151
|
+
(v >> 16) & 0xff,
|
1152
|
+
(v >> 8) & 0xff,
|
1153
|
+
(v >> 0) & 0xff,
|
1154
|
+
0
|
1155
|
+
};
|
1156
|
+
rb_str_cat(rstr, a, 5);
|
1060
1157
|
}
|
1061
1158
|
|
1062
|
-
static
|
1063
|
-
|
1159
|
+
static VALUE
|
1160
|
+
append_var_int40_be(int argc, VALUE* argv, VALUE str)
|
1064
1161
|
{
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1162
|
+
int i;
|
1163
|
+
for(i = 0; i < argc; i++) {
|
1164
|
+
|
1165
|
+
append_int40_be(str, NUM2I64(argv[i]));
|
1166
|
+
|
1167
|
+
}
|
1168
|
+
return str;
|
1068
1169
|
}
|
1069
1170
|
|
1070
|
-
static
|
1071
|
-
|
1171
|
+
static VALUE
|
1172
|
+
rb_append_int40_be(int argc, VALUE* argv, VALUE self)
|
1072
1173
|
{
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1174
|
+
append_args args;
|
1175
|
+
check_argc_append(argc, argv, &args, 40);
|
1176
|
+
return append_var_int40_be(args.argc, args.argv, args.str);
|
1076
1177
|
}
|
1077
1178
|
|
1078
|
-
static
|
1079
|
-
|
1179
|
+
static uint64_t
|
1180
|
+
get_int48_be(VALUE rstr, VALUE ri)
|
1080
1181
|
{
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1182
|
+
long i = NUM2LONG(ri);
|
1183
|
+
const uint8_t *ptr;
|
1184
|
+
StringValue(rstr);
|
1185
|
+
i = check_size(i, RSTRING_LEN(rstr), 6);
|
1186
|
+
ptr = (const uint8_t*)RSTRING_PTR(rstr);
|
1187
|
+
return (uint64_t)(
|
1188
|
+
(((uint32_t)ptr[i + 5]) << 0) |
|
1189
|
+
(((uint32_t)ptr[i + 4]) << 8) |
|
1190
|
+
(((uint32_t)ptr[i + 3]) << 16) |
|
1191
|
+
(((uint32_t)ptr[i + 2]) << 24) |
|
1192
|
+
0) | ((uint64_t)(
|
1193
|
+
(((uint32_t)ptr[i + 1]) << 0) |
|
1194
|
+
(((uint32_t)ptr[i + 0]) << 8) |
|
1195
|
+
0) << 32);
|
1084
1196
|
}
|
1085
1197
|
|
1086
|
-
static
|
1087
|
-
|
1198
|
+
static int64_t
|
1199
|
+
get_sint48_be(VALUE rstr, VALUE ri)
|
1088
1200
|
{
|
1089
|
-
|
1090
|
-
|
1091
|
-
rb_str_cat(rstr, a, 8);
|
1201
|
+
int64_t res = (int64_t)get_int48_be(rstr, ri);
|
1202
|
+
return res - ((res >> 47) << 48);
|
1092
1203
|
}
|
1093
1204
|
|
1094
|
-
static
|
1095
|
-
|
1205
|
+
static VALUE
|
1206
|
+
rb_get_int48_be(int argc, VALUE *argv, VALUE self)
|
1096
1207
|
{
|
1097
|
-
|
1098
|
-
char a[11] = {128, 128, 128, 128,
|
1099
|
-
128, 128 ,128 ,128,
|
1100
|
-
128, 128, 0};
|
1101
|
-
do {
|
1102
|
-
a[i] += ber % 128;
|
1103
|
-
ber /= 128;
|
1104
|
-
i--;
|
1105
|
-
} while (ber);
|
1106
|
-
i++;
|
1107
|
-
rb_str_cat(rstr, a+i, 11-i);
|
1108
|
-
|
1109
|
-
return 11-i;
|
1208
|
+
return I642NUM(get_int48_be(argv[0], check_argc(argc, argv)));
|
1110
1209
|
}
|
1111
1210
|
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
}
|
1211
|
+
static VALUE
|
1212
|
+
rb_get_sint48_be(int argc, VALUE *argv, VALUE self)
|
1213
|
+
{
|
1214
|
+
return I642NUM(get_sint48_be(argv[0], check_argc(argc, argv)));
|
1215
|
+
}
|
1117
1216
|
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1217
|
+
static VALUE
|
1218
|
+
rb_slice_int48_be(VALUE self, VALUE rstr)
|
1219
|
+
{
|
1220
|
+
uint64_t res = get_int48_be(rstr, INT2FIX(0));
|
1221
|
+
rb_str_drop_bytes(rstr, 6);
|
1222
|
+
return I642NUM(res);
|
1223
|
+
}
|
1124
1224
|
|
1125
|
-
static
|
1126
|
-
|
1225
|
+
static VALUE
|
1226
|
+
rb_slice_sint48_be(VALUE self, VALUE rstr)
|
1127
1227
|
{
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
args->str = RTEST(argv[0]) ? argv[0] : rb_str_new(0, 0);
|
1132
|
-
if (argc == 2 && TYPE(argv[1]) == T_ARRAY) {
|
1133
|
-
args->argc = RARRAY_LEN(argv[1]);
|
1134
|
-
args->argv = RARRAY_PTR(argv[1]);
|
1135
|
-
}
|
1136
|
-
else {
|
1137
|
-
args->argc = argc-1;
|
1138
|
-
args->argv = argv+1;
|
1139
|
-
}
|
1228
|
+
uint64_t res = get_sint48_be(rstr, INT2FIX(0));
|
1229
|
+
rb_str_drop_bytes(rstr, 6);
|
1230
|
+
return I642NUM(res);
|
1140
1231
|
}
|
1141
1232
|
|
1142
1233
|
static void
|
1143
|
-
|
1234
|
+
append_int48_be(VALUE rstr, int64_t v)
|
1144
1235
|
{
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
}
|
1154
|
-
|
1155
|
-
args->argc = argc-2;
|
1156
|
-
args->argv = argv+2;
|
1157
|
-
}
|
1236
|
+
char a[] = {
|
1237
|
+
(v >> 40) & 0xff,
|
1238
|
+
(v >> 32) & 0xff,
|
1239
|
+
(v >> 24) & 0xff,
|
1240
|
+
(v >> 16) & 0xff,
|
1241
|
+
(v >> 8) & 0xff,
|
1242
|
+
(v >> 0) & 0xff,
|
1243
|
+
0
|
1244
|
+
};
|
1245
|
+
rb_str_cat(rstr, a, 6);
|
1158
1246
|
}
|
1159
1247
|
|
1160
|
-
/*** 32BIT **/
|
1161
1248
|
static VALUE
|
1162
|
-
|
1249
|
+
append_var_int48_be(int argc, VALUE* argv, VALUE str)
|
1163
1250
|
{
|
1164
1251
|
int i;
|
1165
1252
|
for(i = 0; i < argc; i++) {
|
1166
|
-
|
1253
|
+
|
1254
|
+
append_int48_be(str, NUM2I64(argv[i]));
|
1255
|
+
|
1167
1256
|
}
|
1168
1257
|
return str;
|
1169
1258
|
}
|
1170
|
-
#define append_var_int8_le append_var_int8
|
1171
|
-
#define append_var_int8_be append_var_int8
|
1172
1259
|
|
1173
1260
|
static VALUE
|
1174
|
-
|
1261
|
+
rb_append_int48_be(int argc, VALUE* argv, VALUE self)
|
1175
1262
|
{
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1263
|
+
append_args args;
|
1264
|
+
check_argc_append(argc, argv, &args, 48);
|
1265
|
+
return append_var_int48_be(args.argc, args.argv, args.str);
|
1266
|
+
}
|
1267
|
+
|
1268
|
+
static uint64_t
|
1269
|
+
get_int56_be(VALUE rstr, VALUE ri)
|
1270
|
+
{
|
1271
|
+
long i = NUM2LONG(ri);
|
1272
|
+
const uint8_t *ptr;
|
1273
|
+
StringValue(rstr);
|
1274
|
+
i = check_size(i, RSTRING_LEN(rstr), 7);
|
1275
|
+
ptr = (const uint8_t*)RSTRING_PTR(rstr);
|
1276
|
+
return (uint64_t)(
|
1277
|
+
(((uint32_t)ptr[i + 6]) << 0) |
|
1278
|
+
(((uint32_t)ptr[i + 5]) << 8) |
|
1279
|
+
(((uint32_t)ptr[i + 4]) << 16) |
|
1280
|
+
(((uint32_t)ptr[i + 3]) << 24) |
|
1281
|
+
0) | ((uint64_t)(
|
1282
|
+
(((uint32_t)ptr[i + 2]) << 0) |
|
1283
|
+
(((uint32_t)ptr[i + 1]) << 8) |
|
1284
|
+
(((uint32_t)ptr[i + 0]) << 16) |
|
1285
|
+
0) << 32);
|
1286
|
+
}
|
1287
|
+
|
1288
|
+
static int64_t
|
1289
|
+
get_sint56_be(VALUE rstr, VALUE ri)
|
1290
|
+
{
|
1291
|
+
int64_t res = (int64_t)get_int56_be(rstr, ri);
|
1292
|
+
return res - ((res >> 55) << 56);
|
1181
1293
|
}
|
1182
1294
|
|
1183
1295
|
static VALUE
|
1184
|
-
|
1296
|
+
rb_get_int56_be(int argc, VALUE *argv, VALUE self)
|
1185
1297
|
{
|
1186
|
-
|
1187
|
-
for(i = 0; i < argc; i++) {
|
1188
|
-
append_int24_le(str, NUM2INT(argv[i]));
|
1189
|
-
}
|
1190
|
-
return str;
|
1298
|
+
return I642NUM(get_int56_be(argv[0], check_argc(argc, argv)));
|
1191
1299
|
}
|
1192
1300
|
|
1193
1301
|
static VALUE
|
1194
|
-
|
1302
|
+
rb_get_sint56_be(int argc, VALUE *argv, VALUE self)
|
1195
1303
|
{
|
1196
|
-
|
1197
|
-
for(i = 0; i < argc; i++) {
|
1198
|
-
append_int32_le(str, (int32_t)NUM2I64(argv[i]));
|
1199
|
-
}
|
1200
|
-
return str;
|
1304
|
+
return I642NUM(get_sint56_be(argv[0], check_argc(argc, argv)));
|
1201
1305
|
}
|
1202
1306
|
|
1203
1307
|
static VALUE
|
1204
|
-
|
1308
|
+
rb_slice_int56_be(VALUE self, VALUE rstr)
|
1205
1309
|
{
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
}
|
1210
|
-
return str;
|
1310
|
+
uint64_t res = get_int56_be(rstr, INT2FIX(0));
|
1311
|
+
rb_str_drop_bytes(rstr, 7);
|
1312
|
+
return I642NUM(res);
|
1211
1313
|
}
|
1212
1314
|
|
1213
1315
|
static VALUE
|
1214
|
-
|
1316
|
+
rb_slice_sint56_be(VALUE self, VALUE rstr)
|
1215
1317
|
{
|
1216
|
-
|
1217
|
-
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1318
|
+
uint64_t res = get_sint56_be(rstr, INT2FIX(0));
|
1319
|
+
rb_str_drop_bytes(rstr, 7);
|
1320
|
+
return I642NUM(res);
|
1321
|
+
}
|
1322
|
+
|
1323
|
+
static void
|
1324
|
+
append_int56_be(VALUE rstr, int64_t v)
|
1325
|
+
{
|
1326
|
+
char a[] = {
|
1327
|
+
(v >> 48) & 0xff,
|
1328
|
+
(v >> 40) & 0xff,
|
1329
|
+
(v >> 32) & 0xff,
|
1330
|
+
(v >> 24) & 0xff,
|
1331
|
+
(v >> 16) & 0xff,
|
1332
|
+
(v >> 8) & 0xff,
|
1333
|
+
(v >> 0) & 0xff,
|
1334
|
+
0
|
1335
|
+
};
|
1336
|
+
rb_str_cat(rstr, a, 7);
|
1221
1337
|
}
|
1222
1338
|
|
1223
1339
|
static VALUE
|
1224
|
-
|
1340
|
+
append_var_int56_be(int argc, VALUE* argv, VALUE str)
|
1225
1341
|
{
|
1226
1342
|
int i;
|
1227
1343
|
for(i = 0; i < argc; i++) {
|
1228
|
-
|
1344
|
+
|
1345
|
+
append_int56_be(str, NUM2I64(argv[i]));
|
1346
|
+
|
1229
1347
|
}
|
1230
1348
|
return str;
|
1231
1349
|
}
|
1232
|
-
/*** 32BIT END ***/
|
1233
1350
|
|
1234
|
-
/*** 64BIT ***/
|
1235
1351
|
static VALUE
|
1236
|
-
|
1352
|
+
rb_append_int56_be(int argc, VALUE* argv, VALUE self)
|
1237
1353
|
{
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1354
|
+
append_args args;
|
1355
|
+
check_argc_append(argc, argv, &args, 56);
|
1356
|
+
return append_var_int56_be(args.argc, args.argv, args.str);
|
1357
|
+
}
|
1358
|
+
|
1359
|
+
static uint64_t
|
1360
|
+
get_int64_be(VALUE rstr, VALUE ri)
|
1361
|
+
{
|
1362
|
+
long i = NUM2LONG(ri);
|
1363
|
+
const uint8_t *ptr;
|
1364
|
+
StringValue(rstr);
|
1365
|
+
i = check_size(i, RSTRING_LEN(rstr), 8);
|
1366
|
+
ptr = (const uint8_t*)RSTRING_PTR(rstr);
|
1367
|
+
return (uint64_t)(
|
1368
|
+
(((uint32_t)ptr[i + 7]) << 0) |
|
1369
|
+
(((uint32_t)ptr[i + 6]) << 8) |
|
1370
|
+
(((uint32_t)ptr[i + 5]) << 16) |
|
1371
|
+
(((uint32_t)ptr[i + 4]) << 24) |
|
1372
|
+
0) | ((uint64_t)(
|
1373
|
+
(((uint32_t)ptr[i + 3]) << 0) |
|
1374
|
+
(((uint32_t)ptr[i + 2]) << 8) |
|
1375
|
+
(((uint32_t)ptr[i + 1]) << 16) |
|
1376
|
+
(((uint32_t)ptr[i + 0]) << 24) |
|
1377
|
+
0) << 32);
|
1378
|
+
}
|
1379
|
+
|
1380
|
+
static int64_t
|
1381
|
+
get_sint64_be(VALUE rstr, VALUE ri)
|
1382
|
+
{
|
1383
|
+
int64_t res = (int64_t)get_int64_be(rstr, ri);
|
1384
|
+
return res;
|
1243
1385
|
}
|
1244
1386
|
|
1245
1387
|
static VALUE
|
1246
|
-
|
1388
|
+
rb_get_int64_be(int argc, VALUE *argv, VALUE self)
|
1247
1389
|
{
|
1248
|
-
|
1249
|
-
for(i = 0; i < argc; i++) {
|
1250
|
-
append_int48_le(str, NUM2I64(argv[i]));
|
1251
|
-
}
|
1252
|
-
return str;
|
1390
|
+
return U642NUM(get_int64_be(argv[0], check_argc(argc, argv)));
|
1253
1391
|
}
|
1254
1392
|
|
1255
1393
|
static VALUE
|
1256
|
-
|
1394
|
+
rb_get_sint64_be(int argc, VALUE *argv, VALUE self)
|
1257
1395
|
{
|
1258
|
-
|
1259
|
-
for(i = 0; i < argc; i++) {
|
1260
|
-
append_int56_le(str, NUM2I64(argv[i]));
|
1261
|
-
}
|
1262
|
-
return str;
|
1396
|
+
return I642NUM(get_sint64_be(argv[0], check_argc(argc, argv)));
|
1263
1397
|
}
|
1264
1398
|
|
1265
1399
|
static VALUE
|
1266
|
-
|
1400
|
+
rb_slice_int64_be(VALUE self, VALUE rstr)
|
1267
1401
|
{
|
1268
|
-
|
1269
|
-
|
1270
|
-
|
1271
|
-
}
|
1272
|
-
return str;
|
1402
|
+
uint64_t res = get_int64_be(rstr, INT2FIX(0));
|
1403
|
+
rb_str_drop_bytes(rstr, 8);
|
1404
|
+
return U642NUM(res);
|
1273
1405
|
}
|
1274
1406
|
|
1275
1407
|
static VALUE
|
1276
|
-
|
1408
|
+
rb_slice_sint64_be(VALUE self, VALUE rstr)
|
1277
1409
|
{
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1410
|
+
uint64_t res = get_sint64_be(rstr, INT2FIX(0));
|
1411
|
+
rb_str_drop_bytes(rstr, 8);
|
1412
|
+
return I642NUM(res);
|
1413
|
+
}
|
1414
|
+
|
1415
|
+
static void
|
1416
|
+
append_int64_be(VALUE rstr, int64_t v)
|
1417
|
+
{
|
1418
|
+
char a[] = {
|
1419
|
+
(v >> 56) & 0xff,
|
1420
|
+
(v >> 48) & 0xff,
|
1421
|
+
(v >> 40) & 0xff,
|
1422
|
+
(v >> 32) & 0xff,
|
1423
|
+
(v >> 24) & 0xff,
|
1424
|
+
(v >> 16) & 0xff,
|
1425
|
+
(v >> 8) & 0xff,
|
1426
|
+
(v >> 0) & 0xff,
|
1427
|
+
0
|
1428
|
+
};
|
1429
|
+
rb_str_cat(rstr, a, 8);
|
1283
1430
|
}
|
1284
1431
|
|
1285
1432
|
static VALUE
|
1286
|
-
|
1433
|
+
append_var_int64_be(int argc, VALUE* argv, VALUE str)
|
1287
1434
|
{
|
1288
1435
|
int i;
|
1289
1436
|
for(i = 0; i < argc; i++) {
|
1290
|
-
|
1437
|
+
|
1438
|
+
append_int64_be(str, safe_int64_t(argv[i]));
|
1439
|
+
|
1291
1440
|
}
|
1292
1441
|
return str;
|
1293
1442
|
}
|
1294
1443
|
|
1295
1444
|
static VALUE
|
1296
|
-
|
1445
|
+
rb_append_int64_be(int argc, VALUE* argv, VALUE self)
|
1297
1446
|
{
|
1298
|
-
|
1299
|
-
|
1300
|
-
|
1447
|
+
append_args args;
|
1448
|
+
check_argc_append(argc, argv, &args, 64);
|
1449
|
+
return append_var_int64_be(args.argc, args.argv, args.str);
|
1450
|
+
}
|
1451
|
+
|
1452
|
+
|
1453
|
+
/* BER */
|
1454
|
+
static uint64_t
|
1455
|
+
parse_ber(const uint8_t *ptr, long max, long *i)
|
1456
|
+
{
|
1457
|
+
uint64_t res = 0;
|
1458
|
+
while (1) {
|
1459
|
+
if (*ptr < 128) {
|
1460
|
+
res += *ptr;
|
1461
|
+
break;
|
1462
|
+
}
|
1463
|
+
if (res > LLU(0xFFFFFFFFFFFFFFFF) / 128) {
|
1464
|
+
rb_raise(rb_eArgError, "BER integer is greater then 2**64, could not parse such big");
|
1465
|
+
}
|
1466
|
+
res = (res + ((*ptr) - 128)) * 128;
|
1467
|
+
ptr++;
|
1468
|
+
if (++(*i) >= max) {
|
1469
|
+
rb_raise(rb_eArgError, "String unexpectedly finished while parsing BER integer");
|
1470
|
+
}
|
1301
1471
|
}
|
1302
|
-
return
|
1472
|
+
return res;
|
1473
|
+
}
|
1474
|
+
|
1475
|
+
static uint64_t
|
1476
|
+
get_ber(VALUE rstr, VALUE ri)
|
1477
|
+
{
|
1478
|
+
long i = NUM2LONG(ri), len;
|
1479
|
+
const uint8_t *ptr;
|
1480
|
+
StringValue(rstr);
|
1481
|
+
len = RSTRING_LEN(rstr);
|
1482
|
+
i = check_size(i, len, 1);
|
1483
|
+
ptr = (const uint8_t*)RSTRING_PTR(rstr) + i;
|
1484
|
+
return parse_ber(ptr, len, &i);
|
1303
1485
|
}
|
1304
1486
|
|
1305
1487
|
static VALUE
|
1306
|
-
|
1488
|
+
rb_get_ber(int argc, VALUE *argv, VALUE self)
|
1307
1489
|
{
|
1308
|
-
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1490
|
+
return U642NUM(get_ber(argv[0], check_argc(argc, argv)));
|
1491
|
+
}
|
1492
|
+
|
1493
|
+
static uint64_t
|
1494
|
+
slice_ber(VALUE rstr, long *i)
|
1495
|
+
{
|
1496
|
+
long len;
|
1497
|
+
const uint8_t *ptr;
|
1498
|
+
StringValue(rstr);
|
1499
|
+
len = RSTRING_LEN(rstr);
|
1500
|
+
ptr = (const uint8_t*)RSTRING_PTR(rstr);
|
1501
|
+
return parse_ber(ptr, len, i);
|
1313
1502
|
}
|
1314
|
-
/*** 64BIT END **/
|
1315
1503
|
|
1504
|
+
static VALUE
|
1505
|
+
rb_slice_ber(VALUE self, VALUE rstr)
|
1506
|
+
{
|
1507
|
+
long i = 0;
|
1508
|
+
int64_t res = slice_ber(rstr, &i);
|
1509
|
+
rb_str_drop_bytes(rstr, i+1);
|
1510
|
+
return U642NUM(res);
|
1511
|
+
}
|
1316
1512
|
|
1317
|
-
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
1322
|
-
|
1323
|
-
|
1513
|
+
static int
|
1514
|
+
append_ber(VALUE rstr, uint64_t ber)
|
1515
|
+
{
|
1516
|
+
int i = 10;
|
1517
|
+
char a[11] = {128, 128, 128, 128,
|
1518
|
+
128, 128 ,128 ,128,
|
1519
|
+
128, 128, 0};
|
1520
|
+
do {
|
1521
|
+
a[i] += ber % 128;
|
1522
|
+
ber /= 128;
|
1523
|
+
i--;
|
1524
|
+
} while (ber);
|
1525
|
+
i++;
|
1526
|
+
rb_str_cat(rstr, a+i, 11-i);
|
1527
|
+
|
1528
|
+
return 11-i;
|
1324
1529
|
}
|
1325
1530
|
|
1326
|
-
append_func(int8, 8)
|
1327
|
-
append_func(int16_le, 16)
|
1328
|
-
append_func(int24_le, 24)
|
1329
|
-
append_func(int32_le, 32)
|
1330
|
-
append_func(int40_le, 40)
|
1331
|
-
append_func(int48_le, 48)
|
1332
|
-
append_func(int56_le, 56)
|
1333
|
-
append_func(int64_le, 64)
|
1334
|
-
append_func(int16_be, 16)
|
1335
|
-
append_func(int24_be, 24)
|
1336
|
-
append_func(int32_be, 32)
|
1337
|
-
append_func(int40_be, 40)
|
1338
|
-
append_func(int48_be, 48)
|
1339
|
-
append_func(int56_be, 56)
|
1340
|
-
append_func(int64_be, 64)
|
1341
|
-
|
1342
|
-
/** APPEND END **/
|
1343
1531
|
|
1344
1532
|
/** APPEND BERSIZE **/
|
1345
1533
|
#define append_bersize_func(type, bytes) \
|
@@ -1600,7 +1788,7 @@ Init_bin_utils()
|
|
1600
1788
|
rshft = rb_intern(">>");
|
1601
1789
|
band = rb_intern("&");
|
1602
1790
|
#ifndef HAVE_RB_STR_DROP_BYTES
|
1603
|
-
|
1791
|
+
aslice = rb_intern("slice!");
|
1604
1792
|
#endif
|
1605
1793
|
|
1606
1794
|
rb_define_method(mod_native, "get_ber", rb_get_ber, -1);
|