Sha256: 94e2ce1f0aa7aae6bd5be294c1ea08e1e155d681b1044dc4e3b75463235d37dc

Contents?: true

Size: 987 Bytes

Versions: 3

Compression:

Stored size: 987 Bytes

Contents

class CassandraClient
  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

3 entries across 3 versions & 1 rubygems

Version Path
cassandra_client-0.2.1 lib/cassandra_client/serialization.rb
cassandra_client-0.2.2 lib/cassandra_client/serialization.rb
cassandra_client-0.3 lib/cassandra_client/serialization.rb