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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2ed12a4882ea2f096a50dba7dd1832324432d90d
4
- data.tar.gz: 4437fc5441e2c033a8201a135bff2738f522c320
3
+ metadata.gz: be46f7232ac905640a7bd19e3e82cf01749583fe
4
+ data.tar.gz: b22494e05f3744b0d7a5b29eec137be100a0e9e8
5
5
  SHA512:
6
- metadata.gz: 79fe2fde39fc99168eb2ce30db2b9078102414af5154ad98d4193917df1f3ef9de7e8a31c33625e77a072a54e729aac8a44730a33320f29b4f36a9d4084b100f
7
- data.tar.gz: 451a0f8d12f1928f1057d8b60aebc74abfc5c5739ce7aa1e9fd95f1933b1c03b3238f32299f4b373eee1c60b50ea9c487b63e62ef83981dc1799ee744d13e08b
6
+ metadata.gz: 49eed811790910f6c0ea1c6d126d3d0b46b96bbbea336012aa7d8793f1b11c1d0728569d4844631bb739305c1ad723177a7e4d91aa407d08bd626c53ee8e8ee6
7
+ data.tar.gz: 811a435eb193cab0bce7cf632f4091f6d187082a04a827a2e4859a7288a053f9945af1c8842ed7169ef203f6131096037678f43ccb7c85dc76f9dcbb15e44c3d
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  ```ruby
8
8
  demo = {"compact"=>true,"binary"=>0}
9
9
  ap = AsciiPack.pack demo
10
- p ap #=> "r2NcompactYMschema0"
10
+ p ap #=> "r2NcompactYMbinary0"
11
11
 
12
12
  unpacked = AsciiPack.unpack ap
13
13
  p unpacked #=> {"compact"=>true,"binary"=>0}
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($/)
@@ -44,13 +44,13 @@ module AsciiPack
44
44
  when obj.kind_of?(String)
45
45
  case obj.length
46
46
  when 0...0x10
47
- fixbin obj
47
+ fixstr obj
48
48
  when 0x10...0x100
49
- bin8 obj
49
+ str8 obj
50
50
  when 0x100...0x10000
51
- bin16 obj
51
+ str16 obj
52
52
  when 0x10000...0x100000000
53
- bin32 obj
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 fixbin (obj)
137
+ def fixstr (obj)
138
138
  (obj.length + 71).chr + obj
139
139
  end
140
140
 
141
- def bin8 (obj)
142
- format_bin TypeMap.bin8, 2, obj
141
+ def str8 (obj)
142
+ format_str TypeMap.str8, 2, obj
143
143
  end
144
144
 
145
- def bin16 (obj)
146
- format_bin TypeMap.bin16, 4, obj
145
+ def str16 (obj)
146
+ format_str TypeMap.str16, 4, obj
147
147
  end
148
148
 
149
- def bin32 (obj)
150
- format_bin TypeMap.bin32, 8, obj
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 format_bin (type, length, bin)
199
- hex = bin.length.to_s(16);
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 + bin;
202
+ type + zero + hex + str;
203
203
  end
204
204
 
205
205
  def to_s16 (a)
@@ -15,9 +15,9 @@ module AsciiPack
15
15
  :float32 => 'k',
16
16
  :float64 => 'l',
17
17
  # (blank) => 'm',
18
- :bin8 => 'n',
19
- :bin16 => 'o',
20
- :bin32 => 'p',
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
- :fixbin_0 => 'G',
48
- :fixbin_1 => 'H',
49
- :fixbin_2 => 'I',
50
- :fixbin_3 => 'J',
51
- :fixbin_4 => 'K',
52
- :fixbin_5 => 'L',
53
- :fixbin_6 => 'M',
54
- :fixbin_7 => 'N',
55
- :fixbin_8 => 'O',
56
- :fixbin_9 => 'P',
57
- :fixbin_A => 'Q',
58
- :fixbin_B => 'R',
59
- :fixbin_C => 'S',
60
- :fixbin_D => 'T',
61
- :fixbin_E => 'U',
62
- :fixbin_F => 'V',
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',
@@ -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]/; fixbin
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.bin8; bin8
36
- when TypeMap.bin16; bin16
37
- when TypeMap.bin32; bin32
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 fixbin
159
- len = @ch.ord - 71 # 71 = TypeMap.fixbin_0.ord
158
+ def fixstr
159
+ len = @ch.ord - 71 # 71 = TypeMap.fixstr_0.ord
160
160
  cut(len)
161
161
  end
162
162
 
163
- def bin8
163
+ def str8
164
164
  len = cut(2).to_i(16)
165
165
  cut(len)
166
166
  end
167
167
 
168
- def bin16
168
+ def str16
169
169
  len = cut(4).to_i(16)
170
170
  cut(len)
171
171
  end
172
172
 
173
- def bin32
173
+ def str32
174
174
  len = cut(8).to_i(16)
175
175
  cut(len)
176
176
  end
@@ -1,3 +1,3 @@
1
1
  module AsciiPack
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/spec/bench.rb CHANGED
@@ -1,4 +1,4 @@
1
- #! /usr/bin/env ruby
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
- "fixbin" => "",
46
- "bin 8" => '0123456789abcdef',
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: ascii-8bit
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 "fixbin" do
77
- format "", T.fixbin_0, 1
78
- format " ", T.fixbin_1, 2
79
- format " " * 0xe, T.fixbin_E, 15
80
- format " " * 0xf, T.fixbin_F, 16
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 "bin 8" do
84
- format "a" * 0x10, T.bin8, 3 + 0x10
85
- format "a" * 0xff, T.bin8, 3 + 0xff
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 "bin 16" do
89
- format "a" * 0x100, T.bin16, 5 + 0x100
90
- format "a" * 0xffff, T.bin16, 5 + 0xffff
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 "bin 32" do
94
- format "a" * 0x10000, T.bin32, 9 + 0x10000
96
+ it "str 32" do
97
+ format "a" * 0x10000, T.str32, 9 + 0x10000
95
98
  # FIXME too late
96
- # format "a" * 0xffffffff, T.bin32, 9 + 0xffffffff
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.0
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-09 00:00:00.000000000 Z
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.0.3
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.