ffi-msgpack 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.specopts +1 -0
- data/.yardopts +1 -0
- data/ChangeLog.md +8 -0
- data/Gemfile +24 -0
- data/LICENSE.txt +23 -0
- data/README.md +91 -0
- data/Rakefile +39 -0
- data/VERSION +1 -0
- data/ffi-msgpack.gemspec +101 -0
- data/lib/ffi/msgpack.rb +3 -0
- data/lib/ffi/msgpack/exceptions/parse_error.rb +6 -0
- data/lib/ffi/msgpack/extensions.rb +8 -0
- data/lib/ffi/msgpack/extensions/array.rb +7 -0
- data/lib/ffi/msgpack/extensions/false_class.rb +7 -0
- data/lib/ffi/msgpack/extensions/float.rb +7 -0
- data/lib/ffi/msgpack/extensions/hash.rb +7 -0
- data/lib/ffi/msgpack/extensions/integer.rb +7 -0
- data/lib/ffi/msgpack/extensions/nil_class.rb +7 -0
- data/lib/ffi/msgpack/extensions/string.rb +7 -0
- data/lib/ffi/msgpack/extensions/true_class.rb +7 -0
- data/lib/ffi/msgpack/msg_array.rb +35 -0
- data/lib/ffi/msgpack/msg_key_value.rb +33 -0
- data/lib/ffi/msgpack/msg_map.rb +41 -0
- data/lib/ffi/msgpack/msg_object.rb +276 -0
- data/lib/ffi/msgpack/msg_object_union.rb +20 -0
- data/lib/ffi/msgpack/msg_raw.rb +42 -0
- data/lib/ffi/msgpack/msgpack.rb +127 -0
- data/lib/ffi/msgpack/packable.rb +20 -0
- data/lib/ffi/msgpack/packer.rb +153 -0
- data/lib/ffi/msgpack/types.rb +30 -0
- data/lib/ffi/msgpack/unpacker.rb +248 -0
- data/lib/ffi/msgpack/zone.rb +18 -0
- data/lib/ffi/msgpack/zone_chunk_list.rb +13 -0
- data/lib/ffi/msgpack/zone_finalizer.rb +14 -0
- data/lib/ffi/msgpack/zone_finalizer_array.rb +13 -0
- data/spec/msg_object_spec.rb +193 -0
- data/spec/packer_spec.rb +62 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/unpacker_spec.rb +69 -0
- metadata +190 -0
data/.gitignore
ADDED
data/.specopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour --format specdoc
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--markup markdown --title 'FFI MsgPack Documentation' --protected --files ChangeLog.md,LICENSE.txt
|
data/ChangeLog.md
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
|
3
|
+
group :runtime do
|
4
|
+
gem 'ffi', '~> 0.6.0'
|
5
|
+
end
|
6
|
+
|
7
|
+
group :development do
|
8
|
+
gem 'bundler', '~> 0.9.25'
|
9
|
+
gem 'rake', '~> 0.8.7'
|
10
|
+
gem 'jeweler', '~> 1.4.0', :git => 'git://github.com/technicalpickles/jeweler.git'
|
11
|
+
end
|
12
|
+
|
13
|
+
group :doc do
|
14
|
+
case RUBY_PLATFORM
|
15
|
+
when 'java'
|
16
|
+
gem 'maruku', '~> 0.6.0'
|
17
|
+
else
|
18
|
+
gem 'rdiscount', '~> 1.6.3'
|
19
|
+
end
|
20
|
+
|
21
|
+
gem 'yard', '~> 0.5.3'
|
22
|
+
end
|
23
|
+
|
24
|
+
gem 'rspec', '~> 1.3.0', :group => [:development, :test]
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
The MIT License
|
3
|
+
|
4
|
+
Copyright (c) 2010 Hal Brodigan
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
a copy of this software and associated documentation files (the
|
8
|
+
'Software'), to deal in the Software without restriction, including
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
the following conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be
|
15
|
+
included in all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
20
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
21
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
22
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
23
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
# ffi-msgpack
|
2
|
+
|
3
|
+
* [github.com/postmodern/ffi-msgpack](http://github.com/postmodern/ffi-msgpack/)
|
4
|
+
* [github.com/postmodern/ffi-msgpack/issues](http://github.com/postmodern/ffi-msgpack/issues)
|
5
|
+
* Postmodern (postmodern.mod3 at gmail.com)
|
6
|
+
|
7
|
+
## Description
|
8
|
+
|
9
|
+
Ruby FFI bindings for the [msgpack](http://msgpack.sourceforge.net/) library.
|
10
|
+
|
11
|
+
## Features
|
12
|
+
|
13
|
+
* Can pack and unpack `nil`, `true`, `false`, Integers, Floats, Strings,
|
14
|
+
Arrays and Hashes.
|
15
|
+
* Provides a buffered / callback driven packer.
|
16
|
+
* Provides a buffered / streaming unpacker.
|
17
|
+
|
18
|
+
## Examples
|
19
|
+
|
20
|
+
Pack an Object:
|
21
|
+
|
22
|
+
require 'ffi/msgpack'
|
23
|
+
|
24
|
+
FFI::MsgPack.pack([1,'x',true])
|
25
|
+
# => "\x93\x01\xA1x\xC3"
|
26
|
+
|
27
|
+
Pack one or more Objects into a Buffer:
|
28
|
+
|
29
|
+
packer = FFI::MsgPack::Packer.create
|
30
|
+
packer << 1
|
31
|
+
packer << 'x'
|
32
|
+
packer << true
|
33
|
+
|
34
|
+
packer.buffer
|
35
|
+
# => "\x01\xA1x\xC3"
|
36
|
+
packer.total
|
37
|
+
# => 3
|
38
|
+
|
39
|
+
Pack one or more Objects with a custom write callback:
|
40
|
+
|
41
|
+
require 'socket'
|
42
|
+
|
43
|
+
socket = TCPSocket.new('example.com',9786)
|
44
|
+
packer = FFI::MsgPack::Packer.create do |packed,length|
|
45
|
+
socket.write(packed)
|
46
|
+
end
|
47
|
+
|
48
|
+
packer << 1
|
49
|
+
packer << 'x'
|
50
|
+
packer << true
|
51
|
+
socket.close
|
52
|
+
|
53
|
+
packer.total
|
54
|
+
# => 3
|
55
|
+
|
56
|
+
Unpack a String:
|
57
|
+
|
58
|
+
FFI::MsgPack.unpack("\x93\x01\xA1x\xC3")
|
59
|
+
# => [1, "x", true]
|
60
|
+
|
61
|
+
Enumerate over each unpacked Object:
|
62
|
+
|
63
|
+
unpacker = FFI::MsgPack::Unpacker.create
|
64
|
+
unpacker << "\x01\xA1x\xC3"
|
65
|
+
|
66
|
+
unpacker.each do |obj|
|
67
|
+
puts obj.inspect
|
68
|
+
end
|
69
|
+
|
70
|
+
Enumerates over each unpacked Object from a stream:
|
71
|
+
|
72
|
+
unpacker = FFI::MsgPack::Unpacker.create
|
73
|
+
unpacker.stream = socket
|
74
|
+
|
75
|
+
unpacker.each do |obj|
|
76
|
+
puts obj.inspect
|
77
|
+
end
|
78
|
+
|
79
|
+
## Requirements
|
80
|
+
|
81
|
+
* [libmsgpack](http://msgpack.sourceforge.net/) >= 0.4.2
|
82
|
+
* [ffi](http://github.com/ffi/ffi) >= 0.6.0
|
83
|
+
|
84
|
+
## Install
|
85
|
+
|
86
|
+
$ sudo gem install ffi-msgpack
|
87
|
+
|
88
|
+
## License
|
89
|
+
|
90
|
+
See {file:LICENSE.txt} for license information.
|
91
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
|
4
|
+
begin
|
5
|
+
Bundler.setup(:development, :doc)
|
6
|
+
rescue Bundler::BundlerError => e
|
7
|
+
STDERR.puts e.message
|
8
|
+
STDERR.puts "Run `bundle install` to install missing gems"
|
9
|
+
exit e.status_code
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'rake'
|
13
|
+
require 'rake/clean'
|
14
|
+
require 'jeweler'
|
15
|
+
|
16
|
+
Jeweler::Tasks.new do |gem|
|
17
|
+
gem.name = 'ffi-msgpack'
|
18
|
+
gem.licenses = ['MIT']
|
19
|
+
gem.summary = %Q{FFI bindings for msgpack}
|
20
|
+
gem.email = 'postmodern.mod3@gmail.com'
|
21
|
+
gem.homepage = %Q{http://github.com/postmodern/ffi-msgpack}
|
22
|
+
gem.description = %Q{Ruby FFI bindings for the msgpack library.}
|
23
|
+
gem.authors = ['Postmodern']
|
24
|
+
gem.requirements = ['libmsgpack, 0.4.2 or greater']
|
25
|
+
gem.has_rdoc = 'yard'
|
26
|
+
end
|
27
|
+
|
28
|
+
require 'spec/rake/spectask'
|
29
|
+
|
30
|
+
desc "Run all specifications"
|
31
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
32
|
+
spec.libs += ['lib', 'spec']
|
33
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
34
|
+
spec.spec_opts = ['--options', '.specopts']
|
35
|
+
end
|
36
|
+
task :default => :spec
|
37
|
+
|
38
|
+
require 'yard'
|
39
|
+
YARD::Rake::YardocTask.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/ffi-msgpack.gemspec
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{ffi-msgpack}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Postmodern"]
|
12
|
+
s.date = %q{2010-05-21}
|
13
|
+
s.description = %q{Ruby FFI bindings for the msgpack library.}
|
14
|
+
s.email = %q{postmodern.mod3@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"ChangeLog.md",
|
17
|
+
"LICENSE.txt",
|
18
|
+
"README.md"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".gitignore",
|
22
|
+
".specopts",
|
23
|
+
".yardopts",
|
24
|
+
"ChangeLog.md",
|
25
|
+
"Gemfile",
|
26
|
+
"LICENSE.txt",
|
27
|
+
"README.md",
|
28
|
+
"Rakefile",
|
29
|
+
"VERSION",
|
30
|
+
"ffi-msgpack.gemspec",
|
31
|
+
"lib/ffi/msgpack.rb",
|
32
|
+
"lib/ffi/msgpack/exceptions/parse_error.rb",
|
33
|
+
"lib/ffi/msgpack/extensions.rb",
|
34
|
+
"lib/ffi/msgpack/extensions/array.rb",
|
35
|
+
"lib/ffi/msgpack/extensions/false_class.rb",
|
36
|
+
"lib/ffi/msgpack/extensions/float.rb",
|
37
|
+
"lib/ffi/msgpack/extensions/hash.rb",
|
38
|
+
"lib/ffi/msgpack/extensions/integer.rb",
|
39
|
+
"lib/ffi/msgpack/extensions/nil_class.rb",
|
40
|
+
"lib/ffi/msgpack/extensions/string.rb",
|
41
|
+
"lib/ffi/msgpack/extensions/true_class.rb",
|
42
|
+
"lib/ffi/msgpack/msg_array.rb",
|
43
|
+
"lib/ffi/msgpack/msg_key_value.rb",
|
44
|
+
"lib/ffi/msgpack/msg_map.rb",
|
45
|
+
"lib/ffi/msgpack/msg_object.rb",
|
46
|
+
"lib/ffi/msgpack/msg_object_union.rb",
|
47
|
+
"lib/ffi/msgpack/msg_raw.rb",
|
48
|
+
"lib/ffi/msgpack/msgpack.rb",
|
49
|
+
"lib/ffi/msgpack/packable.rb",
|
50
|
+
"lib/ffi/msgpack/packer.rb",
|
51
|
+
"lib/ffi/msgpack/types.rb",
|
52
|
+
"lib/ffi/msgpack/unpacker.rb",
|
53
|
+
"lib/ffi/msgpack/zone.rb",
|
54
|
+
"lib/ffi/msgpack/zone_chunk_list.rb",
|
55
|
+
"lib/ffi/msgpack/zone_finalizer.rb",
|
56
|
+
"lib/ffi/msgpack/zone_finalizer_array.rb",
|
57
|
+
"spec/msg_object_spec.rb",
|
58
|
+
"spec/packer_spec.rb",
|
59
|
+
"spec/spec_helper.rb",
|
60
|
+
"spec/unpacker_spec.rb"
|
61
|
+
]
|
62
|
+
s.has_rdoc = %q{yard}
|
63
|
+
s.homepage = %q{http://github.com/postmodern/ffi-msgpack}
|
64
|
+
s.licenses = ["MIT"]
|
65
|
+
s.require_paths = ["lib"]
|
66
|
+
s.requirements = ["libmsgpack, 0.4.2 or greater"]
|
67
|
+
s.rubygems_version = %q{1.3.7}
|
68
|
+
s.summary = %q{FFI bindings for msgpack}
|
69
|
+
s.test_files = [
|
70
|
+
"spec/msg_object_spec.rb",
|
71
|
+
"spec/packer_spec.rb",
|
72
|
+
"spec/spec_helper.rb",
|
73
|
+
"spec/unpacker_spec.rb"
|
74
|
+
]
|
75
|
+
|
76
|
+
if s.respond_to? :specification_version then
|
77
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
78
|
+
s.specification_version = 3
|
79
|
+
|
80
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
81
|
+
s.add_runtime_dependency(%q<ffi>, ["~> 0.6.0"])
|
82
|
+
s.add_development_dependency(%q<bundler>, ["~> 0.9.25"])
|
83
|
+
s.add_development_dependency(%q<rake>, ["~> 0.8.7"])
|
84
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.4.0"])
|
85
|
+
s.add_development_dependency(%q<rspec>, ["~> 1.3.0"])
|
86
|
+
else
|
87
|
+
s.add_dependency(%q<ffi>, ["~> 0.6.0"])
|
88
|
+
s.add_dependency(%q<bundler>, ["~> 0.9.25"])
|
89
|
+
s.add_dependency(%q<rake>, ["~> 0.8.7"])
|
90
|
+
s.add_dependency(%q<jeweler>, ["~> 1.4.0"])
|
91
|
+
s.add_dependency(%q<rspec>, ["~> 1.3.0"])
|
92
|
+
end
|
93
|
+
else
|
94
|
+
s.add_dependency(%q<ffi>, ["~> 0.6.0"])
|
95
|
+
s.add_dependency(%q<bundler>, ["~> 0.9.25"])
|
96
|
+
s.add_dependency(%q<rake>, ["~> 0.8.7"])
|
97
|
+
s.add_dependency(%q<jeweler>, ["~> 1.4.0"])
|
98
|
+
s.add_dependency(%q<rspec>, ["~> 1.3.0"])
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
data/lib/ffi/msgpack.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'ffi/msgpack/extensions/nil_class'
|
2
|
+
require 'ffi/msgpack/extensions/true_class'
|
3
|
+
require 'ffi/msgpack/extensions/false_class'
|
4
|
+
require 'ffi/msgpack/extensions/integer'
|
5
|
+
require 'ffi/msgpack/extensions/float'
|
6
|
+
require 'ffi/msgpack/extensions/string'
|
7
|
+
require 'ffi/msgpack/extensions/array'
|
8
|
+
require 'ffi/msgpack/extensions/hash'
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'ffi/msgpack/types'
|
2
|
+
require 'ffi/msgpack/msg_object'
|
3
|
+
|
4
|
+
module FFI
|
5
|
+
module MsgPack
|
6
|
+
class MsgArray < FFI::Struct
|
7
|
+
|
8
|
+
layout :size, :uint32,
|
9
|
+
:ptr, :pointer
|
10
|
+
|
11
|
+
#
|
12
|
+
# The length of the MsgPack Array.
|
13
|
+
#
|
14
|
+
# @return [Integer]
|
15
|
+
# The length of the Array.
|
16
|
+
#
|
17
|
+
def length
|
18
|
+
self[:size]
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
# The Array of values.
|
23
|
+
#
|
24
|
+
# @return [Array<Object>]
|
25
|
+
# The values contained within the Array.
|
26
|
+
#
|
27
|
+
def to_a
|
28
|
+
(0...self.length).map do |index|
|
29
|
+
MsgObject.new(self[:ptr][index * MsgObject.size]).to_ruby
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|