A summary of data about the Ruby ecosystem.

https://github.com/msgpack/msgpack-ruby

MessagePack implementation for Ruby / msgpack.org[Ruby]
https://github.com/msgpack/msgpack-ruby

Keywords

msgpack

Keywords from Contributors

rubygems mvc activerecord activejob fluentd ruby-gem cncf data-collector nokogiri libxml2

Last synced: about 22 hours ago
JSON representation

Repository metadata

MessagePack implementation for Ruby / msgpack.org[Ruby]

README.md

MessagePack

MessagePack is an efficient binary serialization format.
It lets you exchange data among multiple languages like JSON but it's faster and smaller.
For example, small integers (like flags or error code) are encoded into a single byte,
and typical short strings only require an extra byte in addition to the strings themselves.

If you ever wished to use JSON for convenience (storing an image with metadata) but could
not for technical reasons (binary data, size, speed...), MessagePack is a perfect replacement.

require 'msgpack'
msg = [1,2,3].to_msgpack  #=> "\x93\x01\x02\x03"
MessagePack.unpack(msg)   #=> [1,2,3]

Add msgpack to your Gemfile to install with Bundler:

# Gemfile
gem 'msgpack'

Or, use RubyGems to install:

gem install msgpack

Or, build msgpack-ruby and install from a checked-out msgpack-ruby repository:

bundle
rake
gem install --local pkg/msgpack

Use cases

  • Create REST API returing MessagePack using Rails + RABL
  • Store objects efficiently serialized by msgpack on memcached or Redis
  • Upload data in efficient format from mobile devices such as smartphones
    • MessagePack works on iPhone/iPad and Android. See also Objective-C and Java implementations
  • Design a portable protocol to communicate with embedded devices
    • Check also Fluentd which is a log collector which uses msgpack for the log format (they say it uses JSON but actually it's msgpack, which is compatible with JSON)
  • Exchange objects between software components written in different languages
    • You'll need a flexible but efficient format so that components exchange objects while keeping compatibility

Portability

MessagePack for Ruby should run on x86, ARM, PowerPC, SPARC and other CPU architectures.

And it works with MRI (CRuby) and Rubinius.
Patches to improve portability are highly welcomed.

Serializing objects

Use MessagePack.pack or to_msgpack:

require 'msgpack'
msg = MessagePack.pack(obj)  # or
msg = obj.to_msgpack
File.binwrite('mydata.msgpack', msg)

Streaming serialization

Packer provides advanced API to serialize objects in streaming style:

# serialize a 2-element array [e1, e2]
pk = MessagePack::Packer.new(io)
pk.write_array_header(2).write(e1).write(e2).flush

See API reference for details.

Deserializing objects

Use MessagePack.unpack:

require 'msgpack'
msg = File.binread('mydata.msgpack')
obj = MessagePack.unpack(msg)

Streaming deserialization

Unpacker provides advanced API to deserialize objects in streaming style:

# deserialize objects from an IO
u = MessagePack::Unpacker.new(io)
u.each do |obj|
  # ...
end

or event-driven style which works well with EventMachine:

# event-driven deserialization
def on_read(data)
  @u ||= MessagePack::Unpacker.new
  @u.feed_each(data) {|obj|
     # ...
  }
end

See API reference for details.

Serializing and deserializing symbols

By default, symbols are serialized as strings:

packed = :symbol.to_msgpack     # => "\xA6symbol"
MessagePack.unpack(packed)      # => "symbol"

This can be customized by registering an extension type for them:

MessagePack::DefaultFactory.register_type(0x00, Symbol)

# symbols now survive round trips
packed = :symbol.to_msgpack     # => "\xc7\x06\x00symbol"
MessagePack.unpack(packed)      # => :symbol

The extension type for symbols is configurable like any other extension type.
For example, to customize how symbols are packed you can just redefine
Symbol#to_msgpack_ext. Doing this gives you an option to prevent symbols from
being serialized altogether by throwing an exception:

class Symbol
  def to_msgpack_ext
    raise "Serialization of symbols prohibited"
  end
end

MessagePack::DefaultFactory.register_type(0x00, Symbol)

[1, :symbol, 'string'].to_msgpack  # => RuntimeError: Serialization of symbols prohibited

Serializing and deserializing Time instances

There are the timestamp extension type in MessagePack,
but it is not registered by default.

To map Ruby's Time to MessagePack's timestamp for the default factory:

MessagePack::DefaultFactory.register_type(
  MessagePack::Timestamp::TYPE, # or just -1
  Time,
  packer: MessagePack::Time::Packer,
  unpacker: MessagePack::Time::Unpacker
)

See API reference for details.

Extension Types

Packer and Unpacker support Extension types of MessagePack.

# register how to serialize custom class at first
pk = MessagePack::Packer.new(io)
pk.register_type(0x01, MyClass1, :to_msgpack_ext) # equal to pk.register_type(0x01, MyClass)
pk.register_type(0x02, MyClass2){|obj| obj.how_to_serialize() } # blocks also available

# almost same API for unpacker
uk = MessagePack::Unpacker.new()
uk.register_type(0x01, MyClass1, :from_msgpack_ext)
uk.register_type(0x02){|data| MyClass2.create_from_serialized_data(data) }

MessagePack::Factory is to create packer and unpacker which have same extension types.

factory = MessagePack::Factory.new
factory.register_type(0x01, MyClass1) # same with next line
factory.register_type(0x01, MyClass1, packer: :to_msgpack_ext, unpacker: :from_msgpack_ext)
pk = factory.packer(options_for_packer)
uk = factory.unpacker(options_for_unpacker)

For MessagePack.pack and MessagePack.unpack, default packer/unpacker refer MessagePack::DefaultFactory. Call MessagePack::DefaultFactory.register_type to enable types process globally.

MessagePack::DefaultFactory.register_type(0x03, MyClass3)
MessagePack.unpack(data_with_ext_typeid_03) #=> MyClass3 instance

Alternatively, extension types can call the packer or unpacker recursively to generate the extension data:

Point = Struct.new(:x, :y)
factory = MessagePack::Factory.new
factory.register_type(
  0x01,
  Point,
  packer: ->(point, packer) {
    packer.write(point.x)
    packer.write(point.y)
  },
  unpacker: ->(unpacker) {
    x = unpacker.read
    y = unpacker.read
    Point.new(x, y)
  },
  recursive: true,
)
factory.load(factory.dump(Point.new(12, 34))) # => #<struct Point x=12, y=34>

Pooling

Creating Packer and Unpacker objects is expensive. For best performance it is preferable to re-use these objects.

MessagePack::Factory#pool makes that easier:

factory = MessagePack::Factory.new
factory.register_type(
  0x01,
  Point,
  packer: ->(point, packer) {
    packer.write(point.x)
    packer.write(point.y)
  },
  unpacker: ->(unpacker) {
    x = unpacker.read
    y = unpacker.read
    Point.new(x, y)
  },
  recursive: true,
)
pool = factory.pool(5) # The pool size should match the number of threads expected to use the factory concurrently.

pool.load(pool.dump(Point.new(12, 34))) # => #<struct Point x=12, y=34>

Buffer API

MessagePack for Ruby provides a buffer API so that you can read or write data by hand, not via Packer or Unpacker API.

This MessagePack::Buffer is backed with a fixed-length shared memory pool which is very fast for small data (<= 4KB),
and has zero-copy capability which significantly affects performance to handle large binary data.

How to build and run tests

Before building msgpack, you need to install bundler and dependencies.

gem install bundler
bundle install

Then, you can run the tasks as follows:

Build

bundle exec rake build

Run tests

bundle exec rake spec

Generating docs

bundle exec rake doc

How to build -java rubygems

To build -java gems for JRuby, run:

rake build:java

If this directory has Gemfile.lock (generated with MRI), remove it beforehand.

Updating documents

Online documentation (https://ruby.msgpack.org) is generated from the gh-pages branch.
To update documents in gh-pages branch:

bundle exec rake doc
git checkout gh-pages
cp -a doc/* ./

Copyright

  • Author
  • Copyright
    • Copyright (c) 2008-2015 Sadayuki Furuhashi
  • License
    • Apache License, Version 2.0

Owner metadata


GitHub Events

Total
Last Year

Committers metadata

Last synced: 1 day ago

Total Commits: 1,873
Total Committers: 106
Avg Commits per committer: 17.67
Development Distribution Score (DDS): 0.706

Commits in past year: 5
Committers in past year: 3
Avg Commits per committer in past year: 1.667
Development Distribution Score (DDS) in past year: 0.6

Name Email Commits
frsyuki f****i@u****p 550
TAGOMORI Satoshi t****s@g****m 210
gfx g****i@c****g 146
Jean Boussier j****r@g****m 121
tokuhirom t****m@g****m 94
Muga Nishizawa m****a@g****m 81
frsyuki f****i@5****1 55
Muga Nishizawa m****a@f****) 51
INADA Naoki s****y@g****m 50
Hideyuki Tanaka t****i@g****m 38
UENISHI Kota k****b@g****m 34
Theo t****o@i****t 29
Naoki INADA i****n@e****e 24
Tokuhiro Matsuno t****m@u****p 20
makamaka m****o@g****m 18
Aaron Patterson a****n@g****m 17
Naoki INADA i****n@k****p 16
Gustav Munkby g****v@g****m 14
Vincent de Phily v****y@g****m 14
Naoki INADA i****n@g****r 13
Kazuki Ohta k****a@g****m 13
Olle Jonsson o****n@g****m 13
moriyoshi m****o@m****p 13
Kazuki Oikawa k@o****g 12
frsyuki f****i@v****) 11
frsyuki (none) f****i@v****. 11
Christopher Aue m****l@c****t 11
Kazuki Ohta k****k@i****p 10
Koichiro Ohba k****o@m****g 10
takeshita t****a@g****m 9
and 76 more...

Committer domains:


Issue and Pull Request metadata

Last synced: 2 months ago

Total issues: 44
Total pull requests: 125
Average time to close issues: over 1 year
Average time to close pull requests: about 1 month
Total issue authors: 32
Total pull request authors: 19
Average comments per issue: 4.18
Average comments per pull request: 1.55
Merged pull request: 104
Bot issues: 0
Bot pull requests: 0

Past year issues: 1
Past year pull requests: 9
Past year average time to close issues: 2 days
Past year average time to close pull requests: about 1 hour
Past year issue authors: 1
Past year pull request authors: 4
Past year average comments per issue: 2.0
Past year average comments per pull request: 0.0
Past year merged pull request: 7
Past year bot issues: 0
Past year bot pull requests: 0

More stats: https://issues.ecosyste.ms/repositories/lookup?url=https://github.com/msgpack/msgpack-ruby

Top Issue Authors

  • tagomoris (6)
  • casperisfine (5)
  • marek22k (3)
  • pvalena (2)
  • x-nagasawa (1)
  • TonyWu20 (1)
  • TonyCTHsu (1)
  • frankcrc (1)
  • qcn (1)
  • abbshr (1)
  • kinnalru (1)
  • yoonwaiyan (1)
  • jmartin-r7 (1)
  • pavel-workato (1)
  • kirillrdy (1)

Top Pull Request Authors

  • casperisfine (73)
  • byroot (9)
  • olleolleolle (9)
  • tagomoris (5)
  • Watson1978 (4)
  • peterzhu2118 (3)
  • chrisseaton (3)
  • amatsuda (3)
  • kenhys (2)
  • orien (2)
  • seedot1234 (2)
  • mark-young-atg (2)
  • mohits (2)
  • aardvark179 (1)
  • eregon (1)

Top Issue Labels

Top Pull Request Labels

  • reviewing (3)
  • new feature (3)
  • waiting (3)
  • optimization (2)

Package metadata

gem.coop: msgpack

MessagePack is a binary-based efficient object serialization library. It enables to exchange structured objects between many languages like JSON. But unlike JSON, it is very fast and small.

  • Homepage: http://msgpack.org/
  • Documentation: http://www.rubydoc.info/gems/msgpack/
  • Licenses: Apache 2.0
  • Latest release: 1.8.0 (published about 1 year ago)
  • Last Synced: 2026-03-01T21:01:36.597Z (2 days ago)
  • Versions: 254
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 456,657,761 Total
  • Docker Downloads: 2,134,923,542
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 0.026%
    • Downloads: 0.052%
    • Docker downloads count: 0.052%
  • Maintainers (5)
rubygems.org: msgpack

MessagePack is a binary-based efficient object serialization library. It enables to exchange structured objects between many languages like JSON. But unlike JSON, it is very fast and small.

  • Homepage: http://msgpack.org/
  • Documentation: http://www.rubydoc.info/gems/msgpack/
  • Licenses: Apache 2.0
  • Latest release: 1.8.0 (published about 1 year ago)
  • Last Synced: 2026-03-02T01:01:41.051Z (2 days ago)
  • Versions: 259
  • Dependent Packages: 329
  • Dependent Repositories: 282,509
  • Downloads: 456,685,117 Total
  • Docker Downloads: 2,134,923,542
  • Rankings:
    • Downloads: 0.058%
    • Docker downloads count: 0.061%
    • Dependent repos count: 0.086%
    • Dependent packages count: 0.135%
    • Average: 0.813%
    • Stargazers count: 2.125%
    • Forks count: 2.412%
  • Maintainers (5)
proxy.golang.org: github.com/msgpack/msgpack-ruby

  • Homepage:
  • Documentation: https://pkg.go.dev/github.com/msgpack/msgpack-ruby#section-documentation
  • Licenses: apache-2.0
  • Latest release: v1.8.0 (published about 1 year ago)
  • Last Synced: 2026-02-28T21:01:13.436Z (3 days ago)
  • Versions: 65
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent packages count: 5.48%
    • Average: 5.664%
    • Dependent repos count: 5.848%
gem.coop: ed-precompiled_msgpack

MessagePack is a binary-based efficient object serialization library. It enables to exchange structured objects between many languages like JSON. But unlike JSON, it is very fast and small.

  • Homepage: https://msgpack.org/
  • Documentation: http://www.rubydoc.info/gems/ed-precompiled_msgpack/
  • Licenses: Apache-2.0
  • Latest release: 1.8.0 (published 5 months ago)
  • Last Synced: 2026-02-28T21:01:09.632Z (3 days ago)
  • Versions: 3
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 910 Total
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Stargazers count: 2.214%
    • Forks count: 2.468%
    • Average: 20.833%
    • Downloads: 99.482%
  • Maintainers (1)
conda-forge.org: rb-msgpack

  • Homepage: https://rubygems.org/gems/msgpack
  • Licenses: Apache-2.0
  • Latest release: 1.4.2 (published over 4 years ago)
  • Last Synced: 2026-02-03T12:11:42.955Z (28 days ago)
  • Versions: 3
  • Dependent Packages: 1
  • Dependent Repositories: 0
  • Rankings:
    • Stargazers count: 13.786%
    • Forks count: 15.488%
    • Average: 23.03%
    • Dependent packages count: 28.82%
    • Dependent repos count: 34.025%
rubygems.org: ed-precompiled_msgpack

MessagePack is a binary-based efficient object serialization library. It enables to exchange structured objects between many languages like JSON. But unlike JSON, it is very fast and small.

  • Homepage: https://msgpack.org/
  • Documentation: http://www.rubydoc.info/gems/ed-precompiled_msgpack/
  • Licenses: Apache-2.0
  • Latest release: 1.8.0 (published 5 months ago)
  • Last Synced: 2026-02-28T21:01:09.585Z (3 days ago)
  • Versions: 3
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 910 Total
  • Rankings:
    • Stargazers count: 2.074%
    • Forks count: 2.315%
    • Dependent packages count: 14.231%
    • Average: 30.853%
    • Dependent repos count: 43.59%
    • Downloads: 92.056%
  • Maintainers (1)

Dependencies

Gemfile rubygems
  • rubocop ~> 0.82.0
  • simplecov >= 0
msgpack.gemspec rubygems
  • bundler >= 0 development
  • json >= 0 development
  • rake >= 0 development
  • rake-compiler >= 1.1.9 development
  • rspec ~> 3.3 development
  • yard >= 0 development
.github/workflows/ci.yaml actions
  • actions/checkout v2 composite
  • ruby/setup-ruby v1 composite

Score: 33.687621519161596