asciipack 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/ext/asciipack/packer.c +8 -14
- data/lib/asciipack/version.rb +1 -1
- data/spec/mem_spec.rb +15 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99e8c97fe92ccf81fcf5f3a6d769b9a0bc7fff80
|
4
|
+
data.tar.gz: 37fe12bd66fc3ddb09637c544148dfd0102eec7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9df66b102da5d7724c8a9022a0005e634bfa2d018f981a64eeb01346a96f1120bc5c2536ea993c9a3abb301bb9ea75f31a6a224de3b78d2e331d96ffee8fa10
|
7
|
+
data.tar.gz: b88a190b4a8be5b532e884540769e4ab6da395e7a0259e9f2246bbb73d22e3a1554fdac982e3a77cb16d74007445d95b8adb858322dcbe83cc3247cbcdf23ec8
|
data/.gitignore
CHANGED
data/ext/asciipack/packer.c
CHANGED
@@ -46,18 +46,12 @@ Packer_realloc (packer_t* ptr, size_t require)
|
|
46
46
|
size_t newsize = ptr->memsize;
|
47
47
|
size_t len = ptr->ch - ptr->buffer;
|
48
48
|
size_t require_size = require + len;
|
49
|
-
char* mem = NULL;
|
50
|
-
char* p;
|
51
49
|
|
52
50
|
while (newsize < require_size) {
|
53
51
|
newsize *= 2;
|
54
52
|
}
|
55
53
|
|
56
|
-
|
57
|
-
if (mem == NULL) {
|
58
|
-
return NULL;
|
59
|
-
}
|
60
|
-
ptr->buffer = mem;
|
54
|
+
ptr->buffer = realloc(ptr->buffer, sizeof(char) * newsize);
|
61
55
|
ptr->ch = ptr->buffer + len;
|
62
56
|
ptr->memsize = newsize;
|
63
57
|
return ptr->buffer;
|
@@ -258,7 +252,7 @@ Packer_float (packer_t* ptr, VALUE floatnum)
|
|
258
252
|
uint64_t u64;
|
259
253
|
} converter = {float64};
|
260
254
|
|
261
|
-
Packer_check(ptr,
|
255
|
+
Packer_check(ptr, 17);
|
262
256
|
Packer_write_buffer_1(ptr, 'l');
|
263
257
|
Packer_write_uint64(ptr, converter.u64);
|
264
258
|
}
|
@@ -268,21 +262,20 @@ Packer_str (packer_t* ptr, VALUE string)
|
|
268
262
|
{
|
269
263
|
uint32_t len = RSTRING_LEN(string);
|
270
264
|
char* p = RSTRING_PTR(string);
|
271
|
-
uint8_t n = 0;
|
272
265
|
|
273
266
|
if (len < 0x10) {
|
274
267
|
Packer_check(ptr, 1);
|
275
268
|
Packer_write_buffer_1(ptr, 'G' + len);
|
276
269
|
} else if (len < 0x100) {
|
277
|
-
Packer_check(ptr,
|
270
|
+
Packer_check(ptr, 3);
|
278
271
|
Packer_write_buffer_1(ptr, 'n');
|
279
272
|
Packer_write_positive_num(ptr, len, 2);
|
280
273
|
} else if (len < 0x10000) {
|
281
|
-
Packer_check(ptr,
|
274
|
+
Packer_check(ptr, 5);
|
282
275
|
Packer_write_buffer_1(ptr, 'o');
|
283
276
|
Packer_write_positive_num(ptr, len, 4);
|
284
277
|
} else {
|
285
|
-
Packer_check(ptr,
|
278
|
+
Packer_check(ptr, 9);
|
286
279
|
Packer_write_buffer_1(ptr, 'p');
|
287
280
|
Packer_write_positive_num(ptr, len, 8);
|
288
281
|
}
|
@@ -336,7 +329,6 @@ static void
|
|
336
329
|
Packer_map (packer_t* ptr, VALUE hash)
|
337
330
|
{
|
338
331
|
uint32_t len = RHASH_SIZE(hash);
|
339
|
-
uint32_t i = 0;
|
340
332
|
|
341
333
|
if (len < 0x10) {
|
342
334
|
Packer_check(ptr, 2);
|
@@ -363,12 +355,14 @@ Packer_map (packer_t* ptr, VALUE hash)
|
|
363
355
|
static VALUE
|
364
356
|
Packer_pack (VALUE self, VALUE obj)
|
365
357
|
{
|
358
|
+
VALUE str;
|
359
|
+
|
366
360
|
PACKER(self, ptr);
|
367
361
|
|
368
362
|
Packer_write(ptr, obj);
|
369
363
|
|
370
364
|
*ptr->ch = '\0';
|
371
|
-
|
365
|
+
str = rb_str_new(ptr->buffer, ptr->ch - ptr->buffer);
|
372
366
|
free(ptr->buffer);
|
373
367
|
return str;
|
374
368
|
}
|
data/lib/asciipack/version.rb
CHANGED
data/spec/mem_spec.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
here = File.dirname(File.expand_path(__FILE__))
|
6
|
+
|
7
|
+
describe AsciiPack do
|
8
|
+
it "num" do
|
9
|
+
obj = [0,0xf,0xff,0xffff,0xffffffff,0xffffffffffffffff,-1,-0x80,-0x8000,-0x80000000,-0x8000000000000000,0.1,1.0000000000000002,-0.1,0.0,1/3,Float::INFINITY]
|
10
|
+
obj = obj * 1000
|
11
|
+
ap = AsciiPack.pack(obj)
|
12
|
+
expect(AsciiPack.unpack(ap)).to eq(obj)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asciipack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ksss
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -89,6 +89,7 @@ files:
|
|
89
89
|
- lib/asciipack/version.rb
|
90
90
|
- spec/bench.rb
|
91
91
|
- spec/format_spec.rb
|
92
|
+
- spec/mem_spec.rb
|
92
93
|
- spec/spec_helper.rb
|
93
94
|
homepage: http://ksss.github.io/AsciiPack
|
94
95
|
licenses:
|
@@ -117,5 +118,6 @@ summary: AsciiPack is an object serialization inspired by MessagePack.
|
|
117
118
|
test_files:
|
118
119
|
- spec/bench.rb
|
119
120
|
- spec/format_spec.rb
|
121
|
+
- spec/mem_spec.rb
|
120
122
|
- spec/spec_helper.rb
|
121
123
|
has_rdoc:
|