Project

mochilo

0.01
Low commit activity in last 3 years
No release in over a year
A ruby library for BananaPack
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 4.1.0
 Project Readme

Mochilo

Mochilo is a Ruby library implementing the BananaPack protocol. BananaPack is a superset of MessagePack. It takes advantage of the new ext types to extend the protocol, adding 3 new types which are used for serializing strings with an encoding other than UTF-8.

The mapping of the ext types are:

  • ext8 - A String in an encoding other than UTF-8 who's length is between 0 and (2^8)-1 bytes.
  • ext16 - A String in an encoding other than UTF-8 who's length is between 0 and (2^16)-1 bytes.
  • ext32 - A String in an encoding other than UTF-8 who's length is between 0 and (2^32)-1 bytes.

Also check out docs/format-spec.md for more detailed information on these types.

Strings tagged as ASCII-8BIT are encoded as the bin types in the MessagePack spec. The type that's used depends on the length of the string. Check out the spec here for more information on those types.

Usage

require 'mochilo'
obj = {"key" => "value"}
packed = Mochilo.pack(obj)
#=> "\x81\xD8\x00\x03\x01key\xD8\x00\x05\x00value"

hash = Mochilo.unpack(packed)
#=> {"key"=>"value"}

Supported Ruby Types

The following Ruby types are supported. Meaning they will be deserialized into the same Ruby type they were before serialization.

If any other object type is encountered during serialization, an exception is raised. This is to ensure you have explicit control over what is being serialized.

  • Array
  • Bignum
  • Fixnum
  • Float
  • Hash
  • Regexp
  • String (with encoding)
  • Symbol
  • Time
  • nil
  • true
  • false