Project

rencoder

0.0
No commit activity in last 3 years
No release in over 3 years
Rencoder is implementation of Rencoder encoding/decoding.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 3.1.0
~> 0.90
 Project Readme

Rencoder

Rencoder is a pure Ruby implementation of Rencode serialization format encoding/decoding.

Rencoder is a FULLY compliant with Python implementation, and uses all optimizations (by-type-offset integers, strings, arrays, hashes) both for encoding and decoding.

Rencoder have no runtime dependencies. Everything done in a pure Ruby.

More about Rencode format:

Usage

Serialization

require 'rencoder'

Rencoder.dump("Hello World") # Strings

Rencoder.dump(100) # Integer

Rencoder.dump(1.0001) # Floats

Rencoder.dump({ hello: "world" }) # Hashes

Rencoder.dump(["hello", :world, 123]) # Arrays

Float precion notice Rencoder uses a 64-bit precision by default. It's recommended to stay this way. If there is a strong reason to use 32-bit precision, then please specify float32: true option in a Rencoder.dump call:

Rencoder.dump(1.000001, float32: true)

Using 32-bit precision is NOT recommended

Deserialization

require 'rencoder'

Rencoder.load(hash_data)
# => { 'hello': 'world' }

Rencoder.load(string_data)
# => "Hello World"

Rencoder can read data from any IO object directly, without using any buffers

socket = TCPSocket.new('example.com', 8814)
Rendcoder.load(socket)
# => "Example!"

ActiveRecord

Rencoder is compliant with the ActiveSupport's serialize interface:

class MyModel < ActiveRecord::Base
    serialize :data, Rencoder
end

Installation

Add this line to your application's Gemfile:

gem 'rencoder'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rencoder