Sha256: dd38d4bf8eff3346778fad3072887b8f26683c98bf182c67f075f946177da65d

Contents?: true

Size: 981 Bytes

Versions: 1

Compression:

Stored size: 981 Bytes

Contents

class Cassandra
  module Serialization
    module String
      def self.dump(object);
        object.to_s
      end

      def self.load(object)
        object
      end
    end

    module Marshal
      def self.dump(object)
        ::Marshal.dump(object)
      end

      def self.load(object)
        ::Marshal.load(object)
      end
    end

    module JSON
      def self.dump(object)
        ::JSON.dump(object)
      end

      begin
        require 'yajl/json_gem'
        def self.load(object)
          ::JSON.load(object)
        end
      rescue LoadError
        require 'json/ext'
        def self.load(object)
          ::JSON.load("[#{object}]").first # :-(
        end
      end
    end
    
    module CompressedJSON
      def self.dump(object)
        Zlib::Deflate.deflate(JSON.dump(object))
      end

      def self.load(object)
        JSON.load(Zlib::Inflate.inflate(object))
      end    
    end

    # module Avro
    #  # Someday!
    # end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cassandra-0.4 lib/cassandra/serialization.rb