module AMF

AMF is a full featured AMF3 serializer/deserializer with support for bi-directional other language to ruby class mapping, custom serialization and mapping, remoting gateway helpers that follow AMF3 messaging specs, and a suite of specs to ensure adherence to the specification documents put out by Adobe. If the C components compile, then RocketAMF automatically takes advantage of them to provide a substantial performance benefit. In addition, RocketAMF is fully compatible with Ruby 2.0, 2.1.

Performance

# 100.000 objects
# Ruby 2.0
Testing pure AMF3:
  minimum serialize time: 49.294496s
  minimum deserialize time: 6.600238s

Example

test_object =

{
   first_name: "Greg",
   last_name:  "House"
}

data = AMF::Root.serialize(test_object)

restored_object = AMF::Root.serialize(data)

Mapping Classes Between Other language and Ruby

RocketAMF provides a simple class mapping tool to facilitate serialization and deserialization of typed objects. Refer to the documentation of RocketAMF::ClassMapping for more details. If the provided class mapping tool is not sufficient for your needs, you also have the option to replace it with a class mapper of your own devising that matches the documented API.

Advanced Serialization (encode_amf and IExternalizable)

RocketAMF provides some additional functionality to support advanced serialization techniques. If you define an encode_amf method on your object, it will get called during serialization. It is passed a single argument, the serializer, and it can use the serializer stream, the serialize method, the write_array method, the write_object method, and the serializer version. Below is a simple example that uses write_object to customize the property hash that is used for serialization.

Example:

class TestObject
  def encode_amf serializer
    serializer.write_object self, @attributes
  end
end

If you plan on using the serialize method, make sure to pass in the current serializer version, or you could create a message that cannot be deserialized.

Example:

class VariableObject
  def encode_amf serializer
      serializer.serialize(false)
  end
end