class RubySerial::Serializer::Versions::Version_1::Serializer

Public Instance Methods

pack_data(obj) click to toggle source

Get data

Parameters
Result
  • String: The serialized data

# File lib/ruby-serial/versions/1/serializer.rb, line 17
def pack_data(obj)
  # First look for shared objects
  # Set of objects parsed, per object_id
  @objs = {}
  # Set of shared object_id, with a boolean indicating whether they have been serialized already or not
  @shared_objs = {}
  gather_ids_rec(obj)
  @shared_objs_to_store = {}
  @shared_objs.each do |object_id, false_value|
    @shared_objs_to_store[object_id] = [
      @objs[object_id].class.name,
      get_msgpack_compatible_rec(@objs[object_id], false)
    ]
  end
  #puts "Found #{@shared_objs_to_store.size} shared objects to be stored"
  return {
    'obj' => get_msgpack_compatible_rec(obj),
    'shared_objs' => @shared_objs_to_store
  }.to_msgpack.force_encoding(Encoding::BINARY)
end