Default encoding version (should be the last one)
Constructor
obj (Object): Ruby object to serialize
options (map<Symbol,Object>): Options [default = {}]
:version (String): The version to be used to encode
# File lib/ruby-serial/serializer.rb, line 14 def initialize(obj, options = {}) @version = (options[:version] || DEFAULT_VERSION) @obj = obj # Map of objects ID, with their corresponding number of shared objects among their descendants (those having 0 share nothing) # map< ObjectID, NbrSharedObjects > @objs = {} # Map of shared objects' associated to a boolean indicating whether they have already been serialized or not @shared_objs = {} end
Serialize the object
String: The object serialized
# File lib/ruby-serial/serializer.rb, line 28 def dump serializer = nil begin require "ruby-serial/versions/#{@version}/serializer" serializer = eval("RubySerial::Serializer::Versions::Version_#{@version}")::Serializer.new rescue raise "Unknown serializer version #{@version}: #{$!}" end return "#{@version}\x00#{serializer.pack_data(@obj)}".force_encoding(Encoding::BINARY) end