thrift-base64

This gem contains helper classes for working with Base64 encoded Thrift objects. Eventually code will need to persist a serialized Thrift object. The binary protocols are the fastest ones. Unfortunately binary doesn't work well with plaintext protocols. Base64 solves this problem. It's also much faster than working with the provided Thrift::JSON protocol for interlop with plaintext protocols. Just check out the benchmarks below.

Benchmarks

ruby benchmark/serialization.rb
Calculating -------------------------------------
                JSON   739.000  i/100ms
              Binary     4.532k i/100ms
             Compact     7.174k i/100ms
       Binary Base64     3.951k i/100ms
      Compact Base64     6.660k i/100ms
-------------------------------------------------
                JSON      7.369k (

These benchmarks are included in benchmark/.

Installation

Add this line to your application's Gemfile:

gem 'thrift-base64'

And then execute:

$ bundle

Or install it yourself as:

$ gem install thrift-base64

Usage

thrift-base64 adds two classes to the Thrift module: Thrift::Base64Derserializer & Thrift::Base64Serializer. They mimic the interface of Thirft::Deserializer & Thrift::Serializer.

require 'thrift-base64'

struct = SomeThriftStruct.new

json = Thrift::Base64Serializer.new.serialize(struct)
deserialized = Thrift::Base64Deserializer.new.deserialize(SomeThriftStruct.new, json)

Here's another example if you don't like the verbosity. Defaults to using Thrift::BinaryProtocol.

require 'thrift-base64'

struct = SomeThriftStruct.new
SomeThriftStruct.from_base64(struct.to_base64)

Compact methods are available as well. They use Thrift::CompactProtocol.

require 'thrift-base64'

struct = SomeThriftStruct.new
SomeThriftStruct.from_compact_base64(struct.to_compact_base64)

Testing

$ make test
$ make benchmark

Contributing

  1. Fork it ( https://github.com/saltside/thrift-base64-ruby/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request