Class: RubySerial::Deserializer
- Defined in:
- lib/ruby-serial/deserializer.rb,
lib/ruby-serial/versions/1/deserializer.rb
Overview
Deserialize data previously serialized using Serializer
Defined Under Namespace
Modules: Versions
Instance Method Summary collapse
-
#initialize(data) ⇒ Deserializer
constructor
Constructor.
-
#load ⇒ Object
Load the serialized object.
Constructor Details
#initialize(data) ⇒ Deserializer
Constructor
- Parameters
-
data (String): Serialized data (should be BINARY encoding only)
10 11 12 |
# File 'lib/ruby-serial/deserializer.rb', line 10 def initialize(data) @data = data end |
Instance Method Details
#load ⇒ Object
Load the serialized object
- Result
-
Object: The deserialized object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# 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 |