jruby-msgpack 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +55 -0
- data/Rakefile +6 -0
- data/ext/javassist.jar +0 -0
- data/ext/msgpack-0.6.6-SNAPSHOT.jar +0 -0
- data/jruby-msgpack.gemspec +20 -0
- data/lib/jruby-msgpack.rb +6 -0
- data/lib/jruby-msgpack/type_mapper.rb +22 -0
- data/lib/jruby-msgpack/unpacker.rb +27 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/unpacker_spec.rb +52 -0
- metadata +107 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Andy Lindeman
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# jruby-msgpack
|
2
|
+
|
3
|
+
[](http://travis-ci.org/alindeman/jruby-msgpack)
|
4
|
+
|
5
|
+
Helps bridge that gap between the native Java msgpack library and JRuby!
|
6
|
+
|
7
|
+
Implemented:
|
8
|
+
|
9
|
+
* `MessagePack::Unpacker`
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
gem 'jruby-msgpack'
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install jruby-msgpack
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
### Unpacking a File (or Other IO)
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require "jruby-msgpack"
|
31
|
+
|
32
|
+
unpacker = MessagePack::Unpacker.new
|
33
|
+
File.open("/my/file.mpac", "r") do |io|
|
34
|
+
begin
|
35
|
+
buffer = ""
|
36
|
+
while io.sysread(1024, buffer)
|
37
|
+
unpacker.feed(buffer)
|
38
|
+
|
39
|
+
unpacker.each do |obj|
|
40
|
+
puts obj
|
41
|
+
end
|
42
|
+
end
|
43
|
+
rescue EOFError
|
44
|
+
# EOF reached
|
45
|
+
end
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
1. Fork it
|
52
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
53
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
54
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
55
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/ext/javassist.jar
ADDED
Binary file
|
Binary file
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.authors = ["Andy Lindeman"]
|
5
|
+
gem.email = ["alindeman@gmail.com"]
|
6
|
+
gem.description = %q{MessagePack for JRuby using the native Java library}
|
7
|
+
gem.summary = %q{MessagePack for JRuby using the native Java library}
|
8
|
+
gem.homepage = "https://github.com/alindeman/jruby-msgpack"
|
9
|
+
|
10
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
11
|
+
gem.files = `git ls-files`.split("\n")
|
12
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
13
|
+
gem.name = "jruby-msgpack"
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
gem.version = "0.0.1"
|
16
|
+
|
17
|
+
gem.add_development_dependency "rspec", ">=2.8.0"
|
18
|
+
gem.add_development_dependency "rake"
|
19
|
+
gem.add_development_dependency "jruby-openssl"
|
20
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module MessagePack
|
2
|
+
class TypeMapper
|
3
|
+
def to_ruby_object(message_pack_object)
|
4
|
+
case message_pack_object.type
|
5
|
+
when org.msgpack.type.ValueType::ARRAY
|
6
|
+
message_pack_object.asArrayValue.elementArray.map { |o| to_ruby_object(o) }
|
7
|
+
when org.msgpack.type.ValueType::BOOLEAN
|
8
|
+
message_pack_object.asBooleanValue.getBoolean
|
9
|
+
when org.msgpack.type.ValueType::FLOAT
|
10
|
+
message_pack_object.asFloatValue.getDouble
|
11
|
+
when org.msgpack.type.ValueType::INTEGER
|
12
|
+
message_pack_object.asIntegerValue.getLong
|
13
|
+
when org.msgpack.type.ValueType::MAP
|
14
|
+
Hash[message_pack_object.asMapValue.map { |k, v| [to_ruby_object(k), to_ruby_object(v)] }]
|
15
|
+
when org.msgpack.type.ValueType::NIL
|
16
|
+
nil
|
17
|
+
when org.msgpack.type.ValueType::RAW
|
18
|
+
message_pack_object.asRawValue.getString
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "type_mapper")
|
2
|
+
|
3
|
+
module MessagePack
|
4
|
+
class Unpacker
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@msgpack = org.msgpack.MessagePack.new
|
9
|
+
@unpacker = org.msgpack.unpacker.MessagePackBufferUnpacker.new(@msgpack)
|
10
|
+
@mapper = TypeMapper.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def feed(bytes)
|
14
|
+
if bytes.respond_to?(:to_java_bytes)
|
15
|
+
@unpacker.feed(bytes.to_java_bytes)
|
16
|
+
else
|
17
|
+
@unpacker.feed(bytes)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def each
|
22
|
+
@unpacker.each do |mpo|
|
23
|
+
yield @mapper.to_ruby_object(mpo)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "lib", "jruby-msgpack")
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe MessagePack::Unpacker do
|
4
|
+
it "unpacks arrays" do
|
5
|
+
bytes = org.msgpack.MessagePack.new.write(["a", "b", "c"])
|
6
|
+
|
7
|
+
subject.feed(bytes)
|
8
|
+
subject.first.should == ["a", "b", "c"]
|
9
|
+
end
|
10
|
+
|
11
|
+
it "unpacks booleans" do
|
12
|
+
bytes = org.msgpack.MessagePack.new.write(true)
|
13
|
+
|
14
|
+
subject.feed(bytes)
|
15
|
+
subject.first.should == true
|
16
|
+
end
|
17
|
+
|
18
|
+
it "unpacks floats" do
|
19
|
+
bytes = org.msgpack.MessagePack.new.write(3.1415)
|
20
|
+
|
21
|
+
subject.feed(bytes)
|
22
|
+
subject.first.should == 3.1415
|
23
|
+
end
|
24
|
+
|
25
|
+
it "unpacks integers" do
|
26
|
+
bytes = org.msgpack.MessagePack.new.write(12345)
|
27
|
+
|
28
|
+
subject.feed(bytes)
|
29
|
+
subject.first.should == 12345
|
30
|
+
end
|
31
|
+
|
32
|
+
it "unpacks maps" do
|
33
|
+
bytes = org.msgpack.MessagePack.new.write("foo" => "bar")
|
34
|
+
|
35
|
+
subject.feed(bytes)
|
36
|
+
subject.first.should == {"foo" => "bar"}
|
37
|
+
end
|
38
|
+
|
39
|
+
it "unpacks nils" do
|
40
|
+
bytes = org.msgpack.MessagePack.new.write(nil)
|
41
|
+
|
42
|
+
subject.feed(bytes)
|
43
|
+
subject.first.should == nil
|
44
|
+
end
|
45
|
+
|
46
|
+
it "unpacks strings" do
|
47
|
+
bytes = org.msgpack.MessagePack.new.write("abc123")
|
48
|
+
|
49
|
+
subject.feed(bytes)
|
50
|
+
subject.first.should == "abc123"
|
51
|
+
end
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jruby-msgpack
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Andy Lindeman
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2012-02-23 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.8.0
|
23
|
+
requirement: *id001
|
24
|
+
prerelease: false
|
25
|
+
type: :development
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rake
|
28
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
requirement: *id002
|
35
|
+
prerelease: false
|
36
|
+
type: :development
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: jruby-openssl
|
39
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "0"
|
45
|
+
requirement: *id003
|
46
|
+
prerelease: false
|
47
|
+
type: :development
|
48
|
+
description: MessagePack for JRuby using the native Java library
|
49
|
+
email:
|
50
|
+
- alindeman@gmail.com
|
51
|
+
executables: []
|
52
|
+
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files: []
|
56
|
+
|
57
|
+
files:
|
58
|
+
- .gitignore
|
59
|
+
- .travis.yml
|
60
|
+
- Gemfile
|
61
|
+
- LICENSE
|
62
|
+
- README.md
|
63
|
+
- Rakefile
|
64
|
+
- ext/javassist.jar
|
65
|
+
- ext/msgpack-0.6.6-SNAPSHOT.jar
|
66
|
+
- jruby-msgpack.gemspec
|
67
|
+
- lib/jruby-msgpack.rb
|
68
|
+
- lib/jruby-msgpack/type_mapper.rb
|
69
|
+
- lib/jruby-msgpack/unpacker.rb
|
70
|
+
- spec/spec_helper.rb
|
71
|
+
- spec/unpacker_spec.rb
|
72
|
+
homepage: https://github.com/alindeman/jruby-msgpack
|
73
|
+
licenses: []
|
74
|
+
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
hash: 2
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
hash: 2
|
95
|
+
segments:
|
96
|
+
- 0
|
97
|
+
version: "0"
|
98
|
+
requirements: []
|
99
|
+
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 1.8.9
|
102
|
+
signing_key:
|
103
|
+
specification_version: 3
|
104
|
+
summary: MessagePack for JRuby using the native Java library
|
105
|
+
test_files:
|
106
|
+
- spec/spec_helper.rb
|
107
|
+
- spec/unpacker_spec.rb
|