MessagePack

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.

You can install MessagePack with rubygems.

  gem install msgpack

Simple usage is as follows:

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

Use Unpacker class for streaming deserialization.

Constants

VERSION

Public Class Methods

pack(object, out = '') → String click to toggle source

Serializes the object into raw bytes. The encoding of the string is ASCII-8BIT on Ruby 1.9. This method is same as object.to_msgpack(out = ’’).

out is an object that implements *<<* method like String or IO.

static VALUE MessagePack_pack(int argc, VALUE* argv, VALUE self)
{
        VALUE out;
        if(argc == 1) {
                out = rb_str_buf_new(0);
        } else if(argc == 2) {
                out = argv[1];
        } else {
                rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)", argc);
        }
        return rb_funcall(argv[0], s_to_msgpack, 1, out);
}
unpack(data) → object click to toggle source

Deserializes one object over the specified buffer.

UnpackError is throw when parse error is occured, the buffer is insufficient to deserialize one object or there are extra bytes.

static VALUE MessagePack_unpack(VALUE self, VALUE data)
{
        CHECK_STRING_TYPE(data);
        return MessagePack_unpack_impl(self, data, RSTRING_LEN(data));
}
unpack_limit(data, limit) → object click to toggle source

Deserializes one object over the specified buffer upto limit bytes.

UnpackError is throw when parse error is occured, the buffer is insufficient to deserialize one object or there are extra bytes.

static VALUE MessagePack_unpack_limit(VALUE self, VALUE data, VALUE limit)
{
        CHECK_STRING_TYPE(data);
        return MessagePack_unpack_impl(self, data, NUM2ULONG(limit));
}

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.