////////////////////////////////////////////////////////////////////////////////
//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////
package mx.messaging.channels.amfx
{
import flash.utils.ByteArray;
import flash.utils.Dictionary;
import flash.utils.IExternalizable;
import flash.utils.describeType;
import flash.xml.XMLDocument;
import mx.logging.Log;
import mx.utils.HexEncoder;
import mx.utils.ObjectProxy;
import mx.utils.ObjectUtil;
[ExcludeClass]
/**
* Serializes an arbitrary ActionScript object graph to an XML
* representation that is based on Action Message Format (AMF)
* version 3.
* @private
*/
public class AMFXEncoder
{
public function AMFXEncoder()
{
super();
settings = {};
settings.prettyPrinting = false;
}
public function encode(obj:Object, headers:Array = null):XML
{
XML.setSettings(settings);
var xml:XML = new XML("");
xml.setNamespace(NAMESPACE);
xml.@["ver"] = CURRENT_VERSION;
var context:AMFXContext = new AMFXContext();
context.log = Log.getLogger("mx.messaging.channels.amfx.AMFXEncoder");
encodePacket(xml, obj, headers, context);
return xml;
}
private static function encodePacket(xml:XML, obj:Object, headers:Array = null, context:AMFXContext = null):void
{
if (headers)
encodeHeaders(xml, headers, context);
encodeBody(xml, obj, context);
}
private static function encodeHeaders(xml:XML, headers:Array, context:AMFXContext):void
{
for (var i:uint = 0; i < headers.length; i++)
{
var header:Object = headers[i];
var element:XML = ;
element.@["name"] = header.name;
element.@["mustUnderstand"] = (header.mustUnderstand == true);
encodeValue(element, header.content, context);
xml.appendChild(element);
}
}
private static function encodeBody(xml:XML, obj:*, context:AMFXContext):void
{
var element:XML =