msgpack 1.1.0-java → 1.2.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/msgpack.rb +32 -0
- data/lib/msgpack/core_ext.rb +139 -0
- data/lib/msgpack/factory.rb +21 -0
- data/lib/msgpack/version.rb +1 -1
- data/spec/factory_spec.rb +26 -0
- data/spec/packer_spec.rb +22 -0
- metadata +11 -12
- data/lib/msgpack/msgpack.jar +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76195c9f274420256ead6849c75009c188463b05
|
4
|
+
data.tar.gz: f1ce6c52929a86fca9732a613eb3cd1c2f4cd158
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8bb780d31189fef84bf81a637cf0e8eec0132d058da7c3531ff80db02bc7a0a3dcc574b0da769525cc61bcca8f9db47108315e7f8328df3fe57d091c2f9fb8fd
|
7
|
+
data.tar.gz: b0674e2b240d88c99977df9c7e2c943a51cbc3904e211c835edc8b5aaa96bfee4a1b41fc344728451177b642de0584cbe362a57da788f127f99f49394f982969
|
data/lib/msgpack.rb
CHANGED
@@ -16,3 +16,35 @@ require "msgpack/packer"
|
|
16
16
|
require "msgpack/unpacker"
|
17
17
|
require "msgpack/factory"
|
18
18
|
require "msgpack/symbol"
|
19
|
+
require "msgpack/core_ext"
|
20
|
+
|
21
|
+
module MessagePack
|
22
|
+
DefaultFactory = MessagePack::Factory.new
|
23
|
+
|
24
|
+
def load(src, param = nil)
|
25
|
+
unpacker = nil
|
26
|
+
|
27
|
+
if src.is_a? String
|
28
|
+
unpacker = DefaultFactory.unpacker param
|
29
|
+
unpacker.feed src
|
30
|
+
else
|
31
|
+
unpacker = DefaultFactory.unpacker src, param
|
32
|
+
end
|
33
|
+
|
34
|
+
unpacker.full_unpack
|
35
|
+
end
|
36
|
+
alias :unpack :load
|
37
|
+
|
38
|
+
module_function :load
|
39
|
+
module_function :unpack
|
40
|
+
|
41
|
+
def pack(v, *rest)
|
42
|
+
packer = DefaultFactory.packer(*rest)
|
43
|
+
packer.write v
|
44
|
+
packer.full_pack
|
45
|
+
end
|
46
|
+
alias :dump :pack
|
47
|
+
|
48
|
+
module_function :pack
|
49
|
+
module_function :dump
|
50
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
module MessagePack
|
2
|
+
module CoreExt
|
3
|
+
def to_msgpack(packer_or_io = nil)
|
4
|
+
if packer_or_io
|
5
|
+
if packer_or_io.is_a?(MessagePack::Packer)
|
6
|
+
to_msgpack_with_packer packer_or_io
|
7
|
+
else
|
8
|
+
MessagePack.pack(self, packer_or_io)
|
9
|
+
end
|
10
|
+
else
|
11
|
+
MessagePack.pack(self)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class NilClass
|
18
|
+
include MessagePack::CoreExt
|
19
|
+
|
20
|
+
private
|
21
|
+
def to_msgpack_with_packer(packer)
|
22
|
+
packer.write_nil
|
23
|
+
packer
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class TrueClass
|
28
|
+
include MessagePack::CoreExt
|
29
|
+
|
30
|
+
private
|
31
|
+
def to_msgpack_with_packer(packer)
|
32
|
+
packer.write_true
|
33
|
+
packer
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class FalseClass
|
38
|
+
include MessagePack::CoreExt
|
39
|
+
|
40
|
+
private
|
41
|
+
def to_msgpack_with_packer(packer)
|
42
|
+
packer.write_false
|
43
|
+
packer
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class Float
|
48
|
+
include MessagePack::CoreExt
|
49
|
+
|
50
|
+
private
|
51
|
+
def to_msgpack_with_packer(packer)
|
52
|
+
packer.write_float self
|
53
|
+
packer
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class String
|
58
|
+
include MessagePack::CoreExt
|
59
|
+
|
60
|
+
private
|
61
|
+
def to_msgpack_with_packer(packer)
|
62
|
+
packer.write_string self
|
63
|
+
packer
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class Array
|
68
|
+
include MessagePack::CoreExt
|
69
|
+
|
70
|
+
private
|
71
|
+
def to_msgpack_with_packer(packer)
|
72
|
+
packer.write_array self
|
73
|
+
packer
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
class Hash
|
78
|
+
include MessagePack::CoreExt
|
79
|
+
|
80
|
+
private
|
81
|
+
def to_msgpack_with_packer(packer)
|
82
|
+
packer.write_hash self
|
83
|
+
packer
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
class Symbol
|
88
|
+
include MessagePack::CoreExt
|
89
|
+
|
90
|
+
private
|
91
|
+
def to_msgpack_with_packer(packer)
|
92
|
+
packer.write_symbol self
|
93
|
+
packer
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
if 1.class.name == "Integer"
|
98
|
+
class Integer
|
99
|
+
include MessagePack::CoreExt
|
100
|
+
|
101
|
+
private
|
102
|
+
def to_msgpack_with_packer(packer)
|
103
|
+
packer.write_int self
|
104
|
+
packer
|
105
|
+
end
|
106
|
+
end
|
107
|
+
else
|
108
|
+
class Fixnum
|
109
|
+
include MessagePack::CoreExt
|
110
|
+
|
111
|
+
private
|
112
|
+
def to_msgpack_with_packer(packer)
|
113
|
+
packer.write_int self
|
114
|
+
packer
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
class Bignum
|
119
|
+
include MessagePack::CoreExt
|
120
|
+
|
121
|
+
private
|
122
|
+
def to_msgpack_with_packer(packer)
|
123
|
+
packer.write_int self
|
124
|
+
packer
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
module MessagePack
|
130
|
+
class ExtensionValue
|
131
|
+
include CoreExt
|
132
|
+
|
133
|
+
private
|
134
|
+
def to_msgpack_with_packer(packer)
|
135
|
+
packer.write_extension self
|
136
|
+
packer
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
data/lib/msgpack/factory.rb
CHANGED
@@ -56,5 +56,26 @@ module MessagePack
|
|
56
56
|
raise ArgumentError, "class or type id"
|
57
57
|
end
|
58
58
|
end
|
59
|
+
|
60
|
+
def load(src, param = nil)
|
61
|
+
unpacker = nil
|
62
|
+
|
63
|
+
if src.is_a? String
|
64
|
+
unpacker = unpacker(param)
|
65
|
+
unpacker.feed(src)
|
66
|
+
else
|
67
|
+
unpacker = unpacker(src, param)
|
68
|
+
end
|
69
|
+
|
70
|
+
unpacker.full_unpack
|
71
|
+
end
|
72
|
+
alias :unpack :load
|
73
|
+
|
74
|
+
def dump(v, *rest)
|
75
|
+
packer = packer(*rest)
|
76
|
+
packer.write(v)
|
77
|
+
packer.full_pack
|
78
|
+
end
|
79
|
+
alias :pack :dump
|
59
80
|
end
|
60
81
|
end
|
data/lib/msgpack/version.rb
CHANGED
data/spec/factory_spec.rb
CHANGED
@@ -44,6 +44,32 @@ describe MessagePack::Factory do
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
+
describe '#dump and #load' do
|
48
|
+
it 'can be used like a standard coder' do
|
49
|
+
subject.register_type(0x00, Symbol)
|
50
|
+
expect(subject.load(subject.dump(:symbol))).to be == :symbol
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'is alias as pack and unpack' do
|
54
|
+
subject.register_type(0x00, Symbol)
|
55
|
+
expect(subject.unpack(subject.pack(:symbol))).to be == :symbol
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'accept options' do
|
59
|
+
hash = subject.unpack(MessagePack.pack('k' => 'v'), symbolize_keys: true)
|
60
|
+
expect(hash).to be == { k: 'v' }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#freeze' do
|
65
|
+
it 'can freeze factory instance to deny new registrations anymore' do
|
66
|
+
subject.register_type(0x00, Symbol)
|
67
|
+
subject.freeze
|
68
|
+
expect(subject.frozen?).to be_truthy
|
69
|
+
expect{ subject.register_type(0x01, Array) }.to raise_error(RuntimeError, "can't modify frozen Factory")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
47
73
|
class MyType
|
48
74
|
def initialize(a, b)
|
49
75
|
@a = a
|
data/spec/packer_spec.rb
CHANGED
@@ -178,6 +178,28 @@ describe MessagePack::Packer do
|
|
178
178
|
Array.new.to_msgpack.class.should == String
|
179
179
|
end
|
180
180
|
|
181
|
+
it 'to_msgpack with packer equals to_msgpack' do
|
182
|
+
nil.to_msgpack(MessagePack::Packer.new).to_str.should == nil.to_msgpack
|
183
|
+
true.to_msgpack(MessagePack::Packer.new).to_str.should == true.to_msgpack
|
184
|
+
false.to_msgpack(MessagePack::Packer.new).to_str.should == false.to_msgpack
|
185
|
+
1.to_msgpack(MessagePack::Packer.new).to_str.should == 1.to_msgpack
|
186
|
+
1.0.to_msgpack(MessagePack::Packer.new).to_str.should == 1.0.to_msgpack
|
187
|
+
"".to_msgpack(MessagePack::Packer.new).to_str.should == "".to_msgpack
|
188
|
+
Hash.new.to_msgpack(MessagePack::Packer.new).to_str.should == Hash.new.to_msgpack
|
189
|
+
Array.new.to_msgpack(MessagePack::Packer.new).to_str.should == Array.new.to_msgpack
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'raises type error on wrong type' do
|
193
|
+
packer = MessagePack::Packer.new
|
194
|
+
expect { packer.write_float "hello" }.to raise_error(TypeError)
|
195
|
+
expect { packer.write_string 1 }.to raise_error(TypeError)
|
196
|
+
expect { packer.write_array "hello" }.to raise_error(TypeError)
|
197
|
+
expect { packer.write_hash "hello" }.to raise_error(TypeError)
|
198
|
+
expect { packer.write_symbol "hello" }.to raise_error(TypeError)
|
199
|
+
expect { packer.write_int "hello" }.to raise_error(TypeError)
|
200
|
+
expect { packer.write_extension "hello" }.to raise_error(TypeError)
|
201
|
+
end
|
202
|
+
|
181
203
|
class CustomPack01
|
182
204
|
def to_msgpack(pk=nil)
|
183
205
|
return MessagePack.pack(self, pk) unless pk.class == MessagePack::Packer
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: msgpack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Sadayuki Furuhashi
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2017-
|
13
|
+
date: 2017-12-07 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
@@ -29,17 +29,17 @@ dependencies:
|
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- - "
|
32
|
+
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: 0
|
34
|
+
version: '0'
|
35
35
|
name: rake
|
36
36
|
prerelease: false
|
37
37
|
type: :development
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
|
-
- - "
|
40
|
+
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: 0
|
42
|
+
version: '0'
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
@@ -71,17 +71,17 @@ dependencies:
|
|
71
71
|
- !ruby/object:Gem::Dependency
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- - "
|
74
|
+
- - ">="
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version: 0
|
76
|
+
version: '0'
|
77
77
|
name: yard
|
78
78
|
prerelease: false
|
79
79
|
type: :development
|
80
80
|
version_requirements: !ruby/object:Gem::Requirement
|
81
81
|
requirements:
|
82
|
-
- - "
|
82
|
+
- - ">="
|
83
83
|
- !ruby/object:Gem::Version
|
84
|
-
version: 0
|
84
|
+
version: '0'
|
85
85
|
- !ruby/object:Gem::Dependency
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
@@ -106,8 +106,8 @@ extensions: []
|
|
106
106
|
extra_rdoc_files: []
|
107
107
|
files:
|
108
108
|
- lib/msgpack.rb
|
109
|
+
- lib/msgpack/core_ext.rb
|
109
110
|
- lib/msgpack/factory.rb
|
110
|
-
- lib/msgpack/msgpack.jar
|
111
111
|
- lib/msgpack/packer.rb
|
112
112
|
- lib/msgpack/symbol.rb
|
113
113
|
- lib/msgpack/unpacker.rb
|
@@ -183,4 +183,3 @@ test_files:
|
|
183
183
|
- spec/spec_helper.rb
|
184
184
|
- spec/unpack_spec.rb
|
185
185
|
- spec/unpacker_spec.rb
|
186
|
-
has_rdoc: false
|
data/lib/msgpack/msgpack.jar
DELETED
Binary file
|