Class: RocketAMF::Pure::Serializer
- Inherits:
-
Object
- Object
- RocketAMF::Pure::Serializer
- Includes:
- IOHelperWrite
- Defined in:
- lib/rocketamf/pure/serializer.rb
Overview
Pure ruby serializer for AMF3
Instance Attribute Summary collapse
-
#stream ⇒ Object
readonly
Returns the value of attribute stream.
Instance Method Summary collapse
-
#initialize(class_mapper) ⇒ Serializer
constructor
A new instance of Serializer.
-
#serialize(obj) ⇒ Object
Serialize the given object using AMF3.
-
#write_array(value) ⇒ Object
Helper for writing arrays inside encode_amf.
-
#write_object(obj, props = nil, traits = nil) ⇒ Object
Helper for writing objects inside encode_amf.
Methods included from IOHelperWrite
#pack_double, #pack_int16_network, #pack_int8, #pack_integer, #pack_word32_network
Methods included from IOHelperBase
#byte_order, #byte_order_little?
Constructor Details
#initialize(class_mapper) ⇒ Serializer
Returns a new instance of Serializer.
28 29 30 31 32 |
# File 'lib/rocketamf/pure/serializer.rb', line 28 def initialize(class_mapper) @class_mapper = class_mapper @stream = '' @depth = 0 end |
Instance Attribute Details
#stream ⇒ Object (readonly)
Returns the value of attribute stream.
22 23 24 |
# File 'lib/rocketamf/pure/serializer.rb', line 22 def stream @stream end |
Instance Method Details
#serialize(obj) ⇒ Object
Serialize the given object using AMF3. Can be called from inside encode_amf.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rocketamf/pure/serializer.rb', line 36 def serialize(obj) # Initialize caches if @depth == 0 @string_cache = StringCache.new @object_cache = ObjectCache.new @trait_cache = StringCache.new end @depth += 1 # Perform serialization amf3_serialize(obj) # Cleanup @depth -= 1 if @depth == 0 @ref_cache = nil @string_cache = nil @object_cache = nil @trait_cache = nil end @stream end |
#write_array(value) ⇒ Object
Helper for writing arrays inside encode_amf.
61 62 63 |
# File 'lib/rocketamf/pure/serializer.rb', line 61 def write_array(value) amf3_write_array value end |
#write_object(obj, props = nil, traits = nil) ⇒ Object
Helper for writing objects inside encode_amf. If you pass in a property hash, it will use it rather than having the class mapper determine properties. You can also specify a traits hash, which can be used to reduce serialized data size or serialize things as externalizable.
69 70 71 |
# File 'lib/rocketamf/pure/serializer.rb', line 69 def write_object(obj, props = nil, traits = nil) amf3_write_object(obj, props, traits) end |