Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/postmodern/ffi-msgpack
Ruby FFI bindings to msgpack
https://github.com/postmodern/ffi-msgpack
Last synced: 6 days ago
JSON representation
Ruby FFI bindings to msgpack
- Host: GitHub
- URL: https://github.com/postmodern/ffi-msgpack
- Owner: postmodern
- License: mit
- Created: 2010-05-19T01:44:07.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2021-02-28T04:05:31.000Z (over 3 years ago)
- Last Synced: 2024-10-12T19:45:17.737Z (22 days ago)
- Language: Ruby
- Homepage:
- Size: 134 KB
- Stars: 16
- Watchers: 4
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# ffi-msgpack
[![CI](https://github.com/postmodern/ffi-msgpack/actions/workflows/ruby.yml/badge.svg)](https://github.com/postmodern/ffi-msgpack/actions/workflows/ruby.yml)
[![Code Climate](https://codeclimate.com/github/postmodern/ffi-msgpack.svg)](https://codeclimate.com/github/postmodern/ffi-msgpack)* [Source](https://github.com/postmodern/ffi-msgpack/)
* [Issues](https://github.com/postmodern/ffi-msgpack/issues)
* [Documentation](http://rubydoc.info/ffi-msgpack)
* [Email](mailto:postmodern.mod3 at gmail.com)## Description
Ruby FFI bindings for the [msgpack](http://msgpack.sourceforge.net/)
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 << truepacker.buffer
# => "\x01\xA1x\xC3"
packer.total
# => 3Pack 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)
endpacker << 1
packer << 'x'
packer << true
socket.closepacker.total
# => 3Unpack 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
endEnumerates over each unpacked Object from a stream:
unpacker = FFI::MsgPack::Unpacker.create
unpacker.stream = socketunpacker.each do |obj|
puts obj.inspect
end## Requirements
* [libmsgpack](http://msgpack.sourceforge.net/) >= 0.5.0
* [ffi](http://github.com/ffi/ffi) ~> 1.0## Install
$ gem install ffi-msgpack
## License
Copyright (c) 2010-2020 Hal Brodigan
See {file:LICENSE.txt} for license information.