Class: RocketAMF::Pure::Deserializer

Inherits:
Object
  • Object
show all
Includes:
ReadIOHelpers
Defined in:
lib/rocketamf/pure/deserializer.rb

Overview

Pure ruby deserializer for AMF0 and AMF3

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ReadIOHelpers

#byte_order, #byte_order_little?, #read_double, #read_int16_network, #read_int8, #read_word16_network, #read_word32_network, #read_word8

Constructor Details

#initialize(class_mapper) ⇒ Deserializer

Pass in the class mapper instance to use when deserializing. This enables better caching behavior in the class mapper and allows one to change mappings between deserialization attempts.



12
13
14
# File 'lib/rocketamf/pure/deserializer.rb', line 12

def initialize class_mapper
  @class_mapper = class_mapper
end

Instance Attribute Details

#sourceObject

Returns the value of attribute source.



7
8
9
# File 'lib/rocketamf/pure/deserializer.rb', line 7

def source
  @source
end

Instance Method Details

#deserialize(version, source) ⇒ Object

Deserialize the source using AMF0 or AMF3. Source should either be a string or StringIO object. If you pass a StringIO object, it will have its position updated to the end of the deserialized data.

Raises:

  • (ArgumentError)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rocketamf/pure/deserializer.rb', line 20

def deserialize version, source
  raise ArgumentError, "unsupported version #{version}" unless [0,3].include?(version)
  @version = version

  if StringIO === source
    @source = source
  elsif source
    @source = StringIO.new(source)
  elsif @source.nil?
    raise AMFError, "no source to deserialize"
  end

  if @version == 0
    @ref_cache = []
    return amf0_deserialize
  else
    @string_cache = []
    @object_cache = []
    @trait_cache = []
    return amf3_deserialize
  end
end

#read_objectObject

Reads an object from the deserializer’s stream and returns it.



44
45
46
47
48
49
50
# File 'lib/rocketamf/pure/deserializer.rb', line 44

def read_object
  if @version == 0
    return amf0_deserialize
  else
    return amf3_deserialize
  end
end