Module: MessagePack
- Defined in:
- ext/rbinit.c,
ext/rbinit.c,
ext/version.rb
Overview
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.
Defined Under Namespace
Modules: Unpacker Classes: UnpackError
Constant Summary collapse
- VERSION =
"0.4.6"
Class Method Summary collapse
-
.pack(*args) ⇒ Object
call-seq: MessagePack.pack(object, out = ”) -> String.
-
.unpack(data) ⇒ Object
call-seq: MessagePack::Unpacker.unpack(data) -> object.
-
.unpack_limit(data, limit) ⇒ Object
call-seq: MessagePack::Unpacker.unpack_limit(data, limit) -> object.
Class Method Details
.pack(*args) ⇒ Object
call-seq:
MessagePack.pack(object, out = '') -> String
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.
274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'ext/pack.c', line 274
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
call-seq:
MessagePack::Unpacker.unpack(data) -> object
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.
770 771 772 773 774 |
# File 'ext/unpack.c', line 770
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
call-seq:
MessagePack::Unpacker.unpack_limit(data, limit) -> object
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.
753 754 755 756 757 |
# File 'ext/unpack.c', line 753
static VALUE MessagePack_unpack_limit(VALUE self, VALUE data, VALUE limit)
{
CHECK_STRING_TYPE(data);
return MessagePack_unpack_impl(self, data, NUM2ULONG(limit));
}
|