Ruby FFI bindings to msgpack
Ruby
Latest commit 2e70a84 Aug 12, 2013 @postmodern Allow testing on 2.0.0.
Permalink
Failed to load latest commit information.
lib/ffi Use read_* and write_* methods when offset is always 0. Sep 22, 2012
spec Added magic encoding hints. Aug 12, 2013
.gemtest Opting into `gem test`. Jan 20, 2011
.gitignore Dropped Bundler / Jeweler for Ore. Oct 28, 2010
.rspec Upgraded to rspec 2.0.0. Oct 11, 2010
.travis.yml
.yardopts Initial commit. May 19, 2010
ChangeLog.md
LICENSE.txt
README.md
Rakefile Require more recent version of yard. May 12, 2012
ffi-msgpack.gemspec
gemspec.yml

README.md

ffi-msgpack

Description

Ruby FFI bindings for the msgpack library.

Features

  • Can pack and unpack nil, true, false, Integers, Floats, Strings, Arrays and Hashes.
  • Provides a buffered / callback driven packer.
  • Provides a buffered / streaming unpacker.

Examples

Pack an Object:

require 'ffi/msgpack'

FFI::MsgPack.pack([1,'x',true])
# => "\x93\x01\xA1x\xC3"

Pack one or more Objects into a Buffer:

packer = FFI::MsgPack::Packer.create
packer << 1
packer << 'x'
packer << true

packer.buffer
# => "\x01\xA1x\xC3"
packer.total
# => 3

Pack one or more Objects with a custom write callback:

require 'socket'

socket = TCPSocket.new('example.com',9786)
packer = FFI::MsgPack::Packer.create do |packed,length|
  socket.write(packed)
end

packer << 1
packer << 'x'
packer << true
socket.close

packer.total
# => 3

Unpack a String:

FFI::MsgPack.unpack("\x93\x01\xA1x\xC3")
# => [1, "x", true]

Enumerate over each unpacked Object:

unpacker = FFI::MsgPack::Unpacker.create
unpacker << "\x01\xA1x\xC3"

unpacker.each do |obj|
  puts obj.inspect
end

Enumerates over each unpacked Object from a stream:

unpacker = FFI::MsgPack::Unpacker.create
unpacker.stream = socket

unpacker.each do |obj|
  puts obj.inspect
end

Requirements

Install

$ gem install ffi-msgpack

License

Copyright (c) 2010-2012 Hal Brodigan

See {file:LICENSE.txt} for license information.