class RubySerial::Deserializer

Deserialize data previously serialized using Serializer

Public Class Methods

new(data) click to toggle source

Constructor

Parameters
  • data (String): Serialized data (should be BINARY encoding only)

# File lib/ruby-serial/deserializer.rb, line 10
def initialize(data)
  @data = data
end

Public Instance Methods

load() click to toggle source

Load the serialized object

Result
  • Object: The deserialized object

# File lib/ruby-serial/deserializer.rb, line 18
def load
  # Find the version
  idx_data_separator = @data.index("\x00")
  raise 'Unknown format of data. It appears this data has not been serialized using RubySerial.' if (idx_data_separator == nil)
  version = @data[0..idx_data_separator-1]
  data = @data[idx_data_separator+1..-1]

  deserializer = nil
  begin
    require "ruby-serial/versions/#{version}/deserializer"
    deserializer = eval("RubySerial::Deserializer::Versions::Version_#{version}")::Deserializer.new
  rescue
    raise "Unknown deserializer version #{version}. Please use a most recent version of RubySerial to decode your data. #{$!}"
  end

  return deserializer.unpack_data(data)
end