$:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__))) $:.unshift "#{File.expand_path(File.dirname(__FILE__))}/amf/" require 'amf/version' require 'amf/class_mapping' require 'amf/messages' module AMF begin raise LoadError, 'C extentions not implemented' rescue LoadError require 'amf/pure' end ClassMapper = AMF::ClassMapping.new class << self # Deserialize the AMF string _source_ into a Ruby data structure and return it. def deserialize(source, options = {}) options[:amf_version] ||= 0 if options[:amf_version] == 0 AMF::AMF0Deserializer.new.deserialize(source) elsif options[:amf_version] == 3 AMF::AMF3Deserializer.new.deserialize(source) else raise AMFError, "unsupported version #{amf_version}" end end # Serialize the given Ruby data structure _obj_ into an AMF stream def serialize(obj, options = {}, &block) options[:amf_version] ||= 3 if options[:amf_version] == 0 AMF::AMF0Serializer.new(options).serialize(obj, &block) elsif options[:amf_version] == 3 AMF::AMF3Serializer.new(options).serialize(obj, &block) else raise AMFError, "unsupported version #{amf_version}" end end end # The base exception for AMF errors. class AMFError < StandardError; end end if defined?(ActiveRecord::Base) require 'amf/active_record' Mime::Type.register 'application/x-amf', :amf ActiveRecord::Base.send :include, AMF::ActiveRecord end class Array def to_amf(options = {}) raise "Not all elements respond to to_amf" unless all? { |e| e.respond_to? :to_amf } options[:amf_version] ||= 3 if options[:amf_version] == 3 serializer_class = AMF::AMF3Serializer elsif options[:amf_version] == 0 serializer_class = AMF::AMF0Serializer else raise AMF::AMFError, "unsupported serializer version #{options[:amf_version]}" end serializer = serializer_class.new({:options => options}) serializer.serialize(self) end end