asciipack 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/asciipack.gemspec +1 -1
- data/lib/asciipack/packer.rb +14 -14
- data/lib/asciipack/typemap.rb +19 -19
- data/lib/asciipack/unpacker.rb +9 -9
- data/lib/asciipack/version.rb +1 -1
- data/spec/bench.rb +3 -3
- data/spec/format_spec.rb +18 -15
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be46f7232ac905640a7bd19e3e82cf01749583fe
|
4
|
+
data.tar.gz: b22494e05f3744b0d7a5b29eec137be100a0e9e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49eed811790910f6c0ea1c6d126d3d0b46b96bbbea336012aa7d8793f1b11c1d0728569d4844631bb739305c1ad723177a7e4d91aa407d08bd626c53ee8e8ee6
|
7
|
+
data.tar.gz: 811a435eb193cab0bce7cf632f4091f6d187082a04a827a2e4859a7288a053f9945af1c8842ed7169ef203f6131096037678f43ccb7c85dc76f9dcbb15e44c3d
|
data/README.md
CHANGED
data/asciipack.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = "co000ri@gmail.com"
|
11
11
|
spec.description = %q{AsciiPack is an object serialization inspired by MessagePack.}
|
12
12
|
spec.summary = %q{AsciiPack is an object serialization inspired by MessagePack.}
|
13
|
-
spec.homepage = ""
|
13
|
+
spec.homepage = "http://ksss.github.io/AsciiPack"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
data/lib/asciipack/packer.rb
CHANGED
@@ -44,13 +44,13 @@ module AsciiPack
|
|
44
44
|
when obj.kind_of?(String)
|
45
45
|
case obj.length
|
46
46
|
when 0...0x10
|
47
|
-
|
47
|
+
fixstr obj
|
48
48
|
when 0x10...0x100
|
49
|
-
|
49
|
+
str8 obj
|
50
50
|
when 0x100...0x10000
|
51
|
-
|
51
|
+
str16 obj
|
52
52
|
when 0x10000...0x100000000
|
53
|
-
|
53
|
+
str32 obj
|
54
54
|
else
|
55
55
|
raise "pack size limit over"
|
56
56
|
end
|
@@ -134,20 +134,20 @@ module AsciiPack
|
|
134
134
|
])
|
135
135
|
end
|
136
136
|
|
137
|
-
def
|
137
|
+
def fixstr (obj)
|
138
138
|
(obj.length + 71).chr + obj
|
139
139
|
end
|
140
140
|
|
141
|
-
def
|
142
|
-
|
141
|
+
def str8 (obj)
|
142
|
+
format_str TypeMap.str8, 2, obj
|
143
143
|
end
|
144
144
|
|
145
|
-
def
|
146
|
-
|
145
|
+
def str16 (obj)
|
146
|
+
format_str TypeMap.str16, 4, obj
|
147
147
|
end
|
148
148
|
|
149
|
-
def
|
150
|
-
|
149
|
+
def str32 (obj)
|
150
|
+
format_str TypeMap.str32, 8, obj
|
151
151
|
end
|
152
152
|
|
153
153
|
def map (obj)
|
@@ -195,11 +195,11 @@ module AsciiPack
|
|
195
195
|
type + zero + hex;
|
196
196
|
end
|
197
197
|
|
198
|
-
def
|
199
|
-
hex =
|
198
|
+
def format_str (type, length, str)
|
199
|
+
hex = str.length.to_s(16);
|
200
200
|
len = length - hex.length;
|
201
201
|
zero = '0' * len;
|
202
|
-
type + zero + hex +
|
202
|
+
type + zero + hex + str;
|
203
203
|
end
|
204
204
|
|
205
205
|
def to_s16 (a)
|
data/lib/asciipack/typemap.rb
CHANGED
@@ -15,9 +15,9 @@ module AsciiPack
|
|
15
15
|
:float32 => 'k',
|
16
16
|
:float64 => 'l',
|
17
17
|
# (blank) => 'm',
|
18
|
-
:
|
19
|
-
:
|
20
|
-
:
|
18
|
+
:str8 => 'n',
|
19
|
+
:str16 => 'o',
|
20
|
+
:str32 => 'p',
|
21
21
|
# (blank) => 'q',
|
22
22
|
:map4 => 'r',
|
23
23
|
:map8 => 's',
|
@@ -44,22 +44,22 @@ module AsciiPack
|
|
44
44
|
:positive_fixint_D => 'D',
|
45
45
|
:positive_fixint_E => 'E',
|
46
46
|
:positive_fixint_F => 'F',
|
47
|
-
:
|
48
|
-
:
|
49
|
-
:
|
50
|
-
:
|
51
|
-
:
|
52
|
-
:
|
53
|
-
:
|
54
|
-
:
|
55
|
-
:
|
56
|
-
:
|
57
|
-
:
|
58
|
-
:
|
59
|
-
:
|
60
|
-
:
|
61
|
-
:
|
62
|
-
:
|
47
|
+
:fixstr_0 => 'G',
|
48
|
+
:fixstr_1 => 'H',
|
49
|
+
:fixstr_2 => 'I',
|
50
|
+
:fixstr_3 => 'J',
|
51
|
+
:fixstr_4 => 'K',
|
52
|
+
:fixstr_5 => 'L',
|
53
|
+
:fixstr_6 => 'M',
|
54
|
+
:fixstr_7 => 'N',
|
55
|
+
:fixstr_8 => 'O',
|
56
|
+
:fixstr_9 => 'P',
|
57
|
+
:fixstr_A => 'Q',
|
58
|
+
:fixstr_B => 'R',
|
59
|
+
:fixstr_C => 'S',
|
60
|
+
:fixstr_D => 'T',
|
61
|
+
:fixstr_E => 'U',
|
62
|
+
:fixstr_F => 'V',
|
63
63
|
:nil => 'W',
|
64
64
|
:false => 'X',
|
65
65
|
:true => 'Y',
|
data/lib/asciipack/unpacker.rb
CHANGED
@@ -13,7 +13,7 @@ module AsciiPack
|
|
13
13
|
move
|
14
14
|
case @ch
|
15
15
|
when /[0-9A-F]/; positive_fixint
|
16
|
-
when /[G-V]/;
|
16
|
+
when /[G-V]/; fixstr
|
17
17
|
when TypeMap.int4; int4
|
18
18
|
when TypeMap.int8; int8
|
19
19
|
when TypeMap.int16; int16
|
@@ -32,9 +32,9 @@ module AsciiPack
|
|
32
32
|
when TypeMap.array8; array8
|
33
33
|
when TypeMap.array16; array16
|
34
34
|
when TypeMap.array32; array32
|
35
|
-
when TypeMap.
|
36
|
-
when TypeMap.
|
37
|
-
when TypeMap.
|
35
|
+
when TypeMap.str8; str8
|
36
|
+
when TypeMap.str16; str16
|
37
|
+
when TypeMap.str32; str32
|
38
38
|
when TypeMap.nil; nil
|
39
39
|
when TypeMap.false; false
|
40
40
|
when TypeMap.true; true
|
@@ -155,22 +155,22 @@ private
|
|
155
155
|
def array16; array(4) end
|
156
156
|
def array32; array(8) end
|
157
157
|
|
158
|
-
def
|
159
|
-
len = @ch.ord - 71 # 71 = TypeMap.
|
158
|
+
def fixstr
|
159
|
+
len = @ch.ord - 71 # 71 = TypeMap.fixstr_0.ord
|
160
160
|
cut(len)
|
161
161
|
end
|
162
162
|
|
163
|
-
def
|
163
|
+
def str8
|
164
164
|
len = cut(2).to_i(16)
|
165
165
|
cut(len)
|
166
166
|
end
|
167
167
|
|
168
|
-
def
|
168
|
+
def str16
|
169
169
|
len = cut(4).to_i(16)
|
170
170
|
cut(len)
|
171
171
|
end
|
172
172
|
|
173
|
-
def
|
173
|
+
def str32
|
174
174
|
len = cut(8).to_i(16)
|
175
175
|
cut(len)
|
176
176
|
end
|
data/lib/asciipack/version.rb
CHANGED
data/spec/bench.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#! /usr/
|
1
|
+
#! /usr/str/env ruby
|
2
2
|
|
3
3
|
lib = File.expand_path('../../lib', __FILE__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
@@ -42,8 +42,8 @@ end
|
|
42
42
|
{
|
43
43
|
"positive fixint" => 0,
|
44
44
|
"uint 4" => 16,
|
45
|
-
"
|
46
|
-
"
|
45
|
+
"fixstr" => "",
|
46
|
+
"str 8" => '0123456789abcdef',
|
47
47
|
"float 64" => 1/3,
|
48
48
|
"map 4" => {},
|
49
49
|
"array 4" => [],
|
data/spec/format_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# encoding:
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -6,6 +6,7 @@ describe AsciiPack do
|
|
6
6
|
it "intro" do
|
7
7
|
expect(AsciiPack.pack({"compact"=>true,"binary"=>0})).to eq('r2NcompactYMbinary0')
|
8
8
|
end
|
9
|
+
|
9
10
|
it "int 4" do
|
10
11
|
format -1, T.int4, 2
|
11
12
|
format -8, T.int4, 2
|
@@ -73,27 +74,29 @@ describe AsciiPack do
|
|
73
74
|
expect(AsciiPack.pack(-1 / 0.0)).to eq(T.float64 + 'fff0000000000000')
|
74
75
|
end
|
75
76
|
|
76
|
-
it "
|
77
|
-
format "", T.
|
78
|
-
format " ", T.
|
79
|
-
format "
|
80
|
-
format "
|
77
|
+
it "fixstr" do
|
78
|
+
format "", T.fixstr_0, 1
|
79
|
+
format " ", T.fixstr_1, 2
|
80
|
+
format "あ", T.fixstr_1, 2
|
81
|
+
format "漢字", T.fixstr_2, 3
|
82
|
+
format " " * 0xe, T.fixstr_E, 15
|
83
|
+
format " " * 0xf, T.fixstr_F, 16
|
81
84
|
end
|
82
85
|
|
83
|
-
it "
|
84
|
-
format "a" * 0x10, T.
|
85
|
-
format "a" * 0xff, T.
|
86
|
+
it "str 8" do
|
87
|
+
format "a" * 0x10, T.str8, 3 + 0x10
|
88
|
+
format "a" * 0xff, T.str8, 3 + 0xff
|
86
89
|
end
|
87
90
|
|
88
|
-
it "
|
89
|
-
format "a" * 0x100, T.
|
90
|
-
format "a" * 0xffff, T.
|
91
|
+
it "str 16" do
|
92
|
+
format "a" * 0x100, T.str16, 5 + 0x100
|
93
|
+
format "a" * 0xffff, T.str16, 5 + 0xffff
|
91
94
|
end
|
92
95
|
|
93
|
-
it "
|
94
|
-
format "a" * 0x10000, T.
|
96
|
+
it "str 32" do
|
97
|
+
format "a" * 0x10000, T.str32, 9 + 0x10000
|
95
98
|
# FIXME too late
|
96
|
-
# format "a" * 0xffffffff, T.
|
99
|
+
# format "a" * 0xffffffff, T.str32, 9 + 0xffffffff
|
97
100
|
end
|
98
101
|
|
99
102
|
it "map 4" do
|
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.1.
|
4
|
+
version: 0.1.1
|
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-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -72,7 +72,7 @@ files:
|
|
72
72
|
- spec/bench.rb
|
73
73
|
- spec/format_spec.rb
|
74
74
|
- spec/spec_helper.rb
|
75
|
-
homepage:
|
75
|
+
homepage: http://ksss.github.io/AsciiPack
|
76
76
|
licenses:
|
77
77
|
- MIT
|
78
78
|
metadata: {}
|
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
92
|
version: '0'
|
93
93
|
requirements: []
|
94
94
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.
|
95
|
+
rubygems_version: 2.1.6
|
96
96
|
signing_key:
|
97
97
|
specification_version: 4
|
98
98
|
summary: AsciiPack is an object serialization inspired by MessagePack.
|