Class: AMF::Pure::Deserializer

Inherits:
Object
  • Object
show all
Includes:
AMFConstants, IOHelperRead
Defined in:
lib/amf/pure/deserializer.rb

Overview

Pure ruby deserializer for AMF3 requests

Constant Summary

Constants included from AMFConstants

AMFConstants::AMF3_CLOSE_DYNAMIC_ARRAY, AMFConstants::AMF3_CLOSE_DYNAMIC_OBJECT, AMFConstants::AMF3_EMPTY_STRING, AMFConstants::AMF3_MARKER_ARRAY, AMFConstants::AMF3_MARKER_BYTE_ARRAY, AMFConstants::AMF3_MARKER_DATE, AMFConstants::AMF3_MARKER_DICTIONARY, AMFConstants::AMF3_MARKER_DOUBLE, AMFConstants::AMF3_MARKER_FALSE, AMFConstants::AMF3_MARKER_INTEGER, AMFConstants::AMF3_MARKER_NULL, AMFConstants::AMF3_MARKER_OBJECT, AMFConstants::AMF3_MARKER_STRING, AMFConstants::AMF3_MARKER_TRUE, AMFConstants::AMF3_MARKER_UNDEFINED, AMFConstants::AMF3_MARKER_VECTOR_DOUBLE, AMFConstants::AMF3_MARKER_VECTOR_INT, AMFConstants::AMF3_MARKER_VECTOR_OBJECT, AMFConstants::AMF3_MARKER_VECTOR_UINT, AMFConstants::AMF3_MARKER_XML, AMFConstants::AMF3_MARKER_XML_DOC, AMFConstants::INTEGER_MAX, AMFConstants::INTEGER_MIN, AMFConstants::MIN_INT_2_BYTE, AMFConstants::MIN_INT_3_BYTE, AMFConstants::MIN_INT_4_BYTE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from IOHelperRead

#read_double, #read_int16_network, #read_int8, #read_word16_network, #read_word32_network, #read_word8

Methods included from IOHelperBase

#byte_order, #byte_order_little?

Constructor Details

#initialize(class_mapper) ⇒ Deserializer

Returns a new instance of Deserializer.



25
26
27
# File 'lib/amf/pure/deserializer.rb', line 25

def initialize(class_mapper)
  @class_mapper = class_mapper
end

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



19
20
21
# File 'lib/amf/pure/deserializer.rb', line 19

def source
  @source
end

Instance Method Details

#deserialize(source) ⇒ Object

Raises:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/amf/pure/deserializer.rb', line 37

def deserialize(source)
  raise AMFError, 'no source to deserialize' if source.nil?

  @source = source.is_a?(StringIO) ? source : StringIO.new(source)

  objects = []

  incomplete_objects = nil

  until @source.eof?

    @cache_strings = []
    @cache_objects = []
    @cache_traits  = []

    source_position = @source.pos

    begin
      objects << amf3_deserialize
    rescue AMFErrorIncomplete, AMFError => e

      @source.pos = source_position

      incomplete_objects = @source.read

      break
    end
  end

  {
      objects:            objects,
      incomplete_objects: incomplete_objects
  }
end

#read_objectObject



74
75
76
# File 'lib/amf/pure/deserializer.rb', line 74

def read_object
  amf3_deserialize
end