Public Types | Public Member Functions

cygnal::AMF Class Reference

Binary representation of an ActionScript object. More...

#include <amf.h>

List of all members.

Public Types

enum  shared_obj_types_e {
  CONNECT = 0x01, DISCONNECT = 0x02, SET_ATTRIBUTE = 0x03, UPDATE_DATA = 0x04,
  UPDATE_ATTRIBUTE = 0x05, SEND_MESSAGE = 0x06, STATUS = 0x07, CLEAR_DATA = 0x08,
  DELETE_DATA = 0x09, DELETE_ATTRIBYTE = 0x0a, INITIAL_DATA = 0x0b
}
 

Types of SharedObjects that can be serialized or deserialized.

More...
enum  filetype_e {
  FILETYPE_ERROR = -1, FILETYPE_NONE = 0, FILETYPE_HTML, FILETYPE_SWF,
  FILETYPE_VIDEO, FILETYPE_AUDIO, FILETYPE_MP3, FILETYPE_FCS,
  FILETYPE_OSCP
}
 

Type of file being streamed.

More...

Public Member Functions

 AMF ()
 Create a new AMF object.
 ~AMF ()
 Delete the allocated AMF object.
size_t totalsize ()
 Get the total number of allocated bytes used when serializing.

Encoding methods

Methods for encoding data into big endian formatted raw AMF data. Note that while we could have had a single overloaded encode method, this is more explicit, which when it comes to manipulating binary protocols make the code much more readable.



boost::shared_ptr< BufferencodeProperty (boost::shared_ptr< cygnal::Element > el)
 Encode a variable to its serialized representation.
static boost::shared_ptr< BufferencodeString (const std::string &str)
 Encode a string object to its serialized representation.
static boost::shared_ptr< BufferencodeString (boost::uint8_t *data, size_t size)
 Encode an array of ASCII bytes to its serialized representation.
static boost::shared_ptr< BufferencodeNullString ()
 Encode a String object to its serialized representation.
static boost::shared_ptr< BufferencodeBoolean (bool flag)
 Encode a Boolean object to its serialized representation.
static boost::shared_ptr< BufferencodeUndefined ()
 Encode an "Undefined" object to its serialized representation.
static boost::shared_ptr< BufferencodeNull ()
 Encode a NULL object to its serialized representation.
static boost::shared_ptr< BufferencodeUnsupported ()
 Encode a "Unsupported" object to its serialized representation.
static boost::shared_ptr< BufferencodeXMLObject (const boost::uint8_t *data, size_t nbytes)
 Encode an XML object to its serialized representation.
static boost::shared_ptr< BufferencodeTypedObject (const cygnal::Element &data)
 Encode a Typed Object to its serialized representation.
static boost::shared_ptr< BufferencodeReference (boost::uint16_t index)
 Encode a Reference to an object to its serialized representation.
static boost::shared_ptr< BufferencodeMovieClip (const boost::uint8_t *data, size_t size)
 Encode a Movie Clip (swf data) to its serialized representation.
static boost::shared_ptr< BufferencodeECMAArray (const cygnal::Element &data)
 Encode an ECMA Array to its serialized representation.
static boost::shared_ptr< BufferencodeLongString (const boost::uint8_t *data, size_t size)
 Encode a Long String to its serialized representation.
static boost::shared_ptr< BufferencodeRecordSet (const boost::uint8_t *data, size_t size)
 Encode a Record Set to its serialized representation.
static boost::shared_ptr< BufferencodeDate (const boost::uint8_t *data)
 Encode a Date to its serialized representation.
static boost::shared_ptr< BufferencodeStrictArray (const cygnal::Element &data)
 Encode a Strict Array to its serialized representation.
static boost::shared_ptr< BufferencodeObject (const cygnal::Element &data)
 Encode an object to its serialized representation.
static boost::shared_ptr< BufferencodeObjectEnd ()
 Encode the end of an object to its serialized representation.
static boost::shared_ptr< BufferencodeNumber (double num)
 Encode a 64 bit number to its serialized representation.
static boost::shared_ptr< BufferencodeElement (boost::shared_ptr< cygnal::Element > el)
 Encode an Element to its serialized representation.
static boost::shared_ptr< BufferencodeElement (const cygnal::Element &el)
 Encode an Element to its serialized representation.

Decoding methods

Methods for extracting data from big endian formatted raw AMF data.



boost::shared_ptr
< cygnal::Element
extractAMF (boost::uint8_t *in, boost::uint8_t *tooFar)
 Extract an AMF object from an array of raw bytes.
boost::shared_ptr
< cygnal::Element
extractAMF (boost::shared_ptr< Buffer > buf)
 Extract an AMF object from an array of raw bytes.
boost::shared_ptr
< cygnal::Element
extractProperty (boost::uint8_t *in, boost::uint8_t *tooFar)
 Extract a Property.
boost::shared_ptr
< cygnal::Element
extractProperty (boost::shared_ptr< Buffer > buf)
 Extract a Property.
static Element::amf0_type_e extractElementHeader (boost::uint8_t *in)
 Extract the AMF0 object type from the header.

Detailed Description

Binary representation of an ActionScript object.

AMF is used to send objects, whether to a SharedObject .sol file, a memory based LocalConnection segment, or over an RTMP connection for streaming.


Member Enumeration Documentation

Type of file being streamed.

Enumerator:
FILETYPE_ERROR 
FILETYPE_NONE 
FILETYPE_HTML 
FILETYPE_SWF 
FILETYPE_VIDEO 
FILETYPE_AUDIO 
FILETYPE_MP3 
FILETYPE_FCS 
FILETYPE_OSCP 

Types of SharedObjects that can be serialized or deserialized.

Enumerator:
CONNECT 
DISCONNECT 
SET_ATTRIBUTE 
UPDATE_DATA 
UPDATE_ATTRIBUTE 
SEND_MESSAGE 
STATUS 
CLEAR_DATA 
DELETE_DATA 
DELETE_ATTRIBYTE 
INITIAL_DATA 

Constructor & Destructor Documentation

cygnal::AMF::AMF (  ) 

Create a new AMF object.

Create a new AMF class. As most of the methods in the AMF class a static, this is primarily only used when encoding complex objects where the byte count is accumulated.

As most of the methods in the AMF class a static, this is primarily only used when encoding complex objects where the byte count is accumulated.

cygnal::AMF::~AMF (  ) 

Delete the allocated AMF object.

Delete the alloczted AMF class.


Member Function Documentation

boost::shared_ptr< Buffer > cygnal::AMF::encodeBoolean ( bool  flag  )  [static]

Encode a Boolean object to its serialized representation.

Encode a Boolean object to it's serialized representation.

Parameters:
flag The boolean value to serialize.
Returns:
a binary AMF packet in big endian format
boost::shared_ptr< Buffer > cygnal::AMF::encodeDate ( const boost::uint8_t *  date  )  [static]

Encode a Date to its serialized representation.

Encode a Date to it's serialized representation.

Parameters:
data A pointer to the raw bytes that becomes the data.
Returns:
a binary AMF packet in big endian format
boost::shared_ptr< Buffer > cygnal::AMF::encodeECMAArray ( const cygnal::Element data  )  [static]

Encode an ECMA Array to its serialized representation.

Encode an ECMA Array to it's serialized representation. An ECMA Array, also called a Mixed Array, contains any AMF data type as an item in the array.

An ECMA Array, also called a Mixed Array, contains any AMF data type as an item in the array.

Parameters:
data A pointer to the raw bytes that becomes the data.
size The number of bytes to serialize.
Returns:
a binary AMF packet in big endian format
Parameters:
data A pointer to the raw bytes that becomes the data.
size The number of bytes to serialize.
Returns:
a binary AMF packet in big endian format
boost::shared_ptr< Buffer > cygnal::AMF::encodeElement ( boost::shared_ptr< cygnal::Element el  )  [static]

Encode an Element to its serialized representation.

Write an AMF element.

Parameters:
el A smart pointer to the Element to encode.
Returns:
a binary AMF packet in big endian format

This encodes the data supplied to an AMF formatted one. As the memory is allocatd within this function, you *must* free the memory used for each element or you'll leak memory.

A "packet" (or element) in AMF is a byte code, followed by the data. Sometimes the data is prefixed by a count, and sometimes it's terminated with a 0x09. Ya gotta love these flaky ad-hoc formats.

All Numbers are 64 bit, big-endian (network byte order) entities.

All strings are in multibyte format, which is to say, probably normal ASCII. It may be that these need to be converted to wide characters, but for now we just leave them as standard multibyte characters. Encode an Element to it's serialized representation.

Parameters:
el A smart pointer to the Element to encode.
Returns:
a binary AMF packet in big endian format

Referenced by cygnal::Element::encode(), cygnal::EchoTest::formatEchoResponse(), and cygnal::OflaDemoTest::formatOflaDemoResponse().

boost::shared_ptr< Buffer > cygnal::AMF::encodeElement ( const cygnal::Element el  )  [static]

Encode an Element to its serialized representation.

Parameters:
el the Element to encode.
Returns:
a binary AMF packet in big endian format
boost::shared_ptr< Buffer > cygnal::AMF::encodeLongString ( const boost::uint8_t *  data,
size_t  size 
) [static]

Encode a Long String to its serialized representation.

Encode a Long String to it's serialized representation.

Parameters:
data A pointer to the raw bytes that becomes the data.
size The number of bytes to serialize.
Returns:
a binary AMF packet in big endian format
boost::shared_ptr< Buffer > cygnal::AMF::encodeMovieClip ( const boost::uint8_t *  data,
size_t  size 
) [static]

Encode a Movie Clip (swf data) to its serialized representation.

Encode a Movie Clip (swf data) to it's serialized representation.

Parameters:
data A pointer to the raw bytes that becomes the data.
size The number of bytes to serialize.
Returns:
a binary AMF packet in big endian format (header,data)
boost::shared_ptr< Buffer > cygnal::AMF::encodeNull (  )  [static]

Encode a NULL object to its serialized representation.

Encode a NULL object to it's serialized representation. A NULL object is often used as a placeholder in RTMP.

A NULL object is often used as a placeholder in RTMP.

Returns:
a binary AMF packet in big endian format
a binary AMF packet in big endian format
boost::shared_ptr< Buffer > cygnal::AMF::encodeNullString (  )  [static]

Encode a String object to its serialized representation.

Encode a String object to it's serialized representation. A NULL String is a string with no associated data.

A NULL String is a string with no associated data.

Returns:
a binary AMF packet in big endian format
a binary AMF packet in big endian format
boost::shared_ptr< Buffer > cygnal::AMF::encodeNumber ( double  indata  )  [static]

Encode a 64 bit number to its serialized representation.

Encode a 64 bit number to it's serialized representation.

Parameters:
num A double value to serialize.
Returns:
a binary AMF packet in big endian format

References cygnal::AMF0_NUMBER_SIZE, and cygnal::swapBytes().

boost::shared_ptr< Buffer > cygnal::AMF::encodeObject ( const cygnal::Element data  )  [static]

Encode an object to its serialized representation.

Encode the end of an object to it's serialized representation.

Parameters:
el A smart pointer to an Element class.
Returns:
a binary AMF packet in big endian format
a binary AMF packet in big endian format
boost::shared_ptr< Buffer > cygnal::AMF::encodeObjectEnd (  )  [static]

Encode the end of an object to its serialized representation.

Encode the end of an object to it's serialized representation.

Returns:
a binary AMF packet in big endian format
boost::shared_ptr< Buffer > cygnal::AMF::encodeProperty ( boost::shared_ptr< cygnal::Element el  ) 

Encode a variable to its serialized representation.

Parameters:
el A smart pointer to the Element to encode.
Returns:
a binary AMF packet in big endian format

Encode a variable to it's serialized representation.

Parameters:
el A smart pointer to the Element to encode.
Returns:
a binary AMF packet in big endian format

Referenced by cygnal::SOL::writeFile().

boost::shared_ptr< Buffer > cygnal::AMF::encodeRecordSet ( const boost::uint8_t *  data,
size_t  size 
) [static]

Encode a Record Set to its serialized representation.

Encode a Record Set to it's serialized representation.

Parameters:
data A pointer to the raw bytes that becomes the data.
size The number of bytes to serialize.
Returns:
a binary AMF packet in big endian format
boost::shared_ptr< Buffer > cygnal::AMF::encodeReference ( boost::uint16_t  index  )  [static]

Encode a Reference to an object to its serialized representation.

Encode a Reference to an object to it's serialized representation.

Parameters:
data A pointer to the raw bytes that becomes the data.
size The number of bytes to serialize.
Returns:
a binary AMF packet in big endian format (header,data)
boost::shared_ptr< Buffer > cygnal::AMF::encodeStrictArray ( const cygnal::Element data  )  [static]

Encode a Strict Array to its serialized representation.

Encode a Strict Array to it's serialized represenicttation. A Strict Array is one where all the items are the same data type, commonly either a number or a string.

A Strict Array is one where all the items are the same data type, commonly either a number or a string.

Parameters:
data A pointer to the raw bytes that becomes the data.
size The number of bytes to serialize.
Returns:
a binary AMF packet in big endian format (header,data)
Parameters:
data A pointer to the raw bytes that becomes the data.
size The number of bytes to serialize.
Returns:
a binary AMF packet in big endian format (header,data)
boost::shared_ptr< Buffer > cygnal::AMF::encodeString ( boost::uint8_t *  data,
size_t  size 
) [static]

Encode an array of ASCII bytes to its serialized representation.

Encode a string to it's serialized representation.

Parameters:
data The data to serialize into big endian format
size The size of the data in bytes
Returns:
a binary AMF packet in big endian format
boost::shared_ptr< Buffer > cygnal::AMF::encodeString ( const std::string &  str  )  [static]

Encode a string object to its serialized representation.

Encode a string to it's serialized representation.

Parameters:
str a string value
Returns:
a binary AMF packet in big endian format

Referenced by gnash::HTTP::formatEchoResponse(), and cygnal::LcShm::formatHeader().

boost::shared_ptr< Buffer > cygnal::AMF::encodeTypedObject ( const cygnal::Element data  )  [static]

Encode a Typed Object to its serialized representation.

Encode a Typed Object to it's serialized representation.

Parameters:
data A pointer to the raw bytes that becomes the data.
size The number of bytes to serialize.
Returns:
a binary AMF packet in big endian format
boost::shared_ptr< Buffer > cygnal::AMF::encodeUndefined (  )  [static]

Encode an "Undefined" object to its serialized representation.

Encode an "Undefined" object to it's serialized representation.

Returns:
a binary AMF packet in big endian format
boost::shared_ptr< Buffer > cygnal::AMF::encodeUnsupported (  )  [static]

Encode a "Unsupported" object to its serialized representation.

Encode a "Unsupported" object to it's serialized representation.

Returns:
a binary AMF packet in big endian format
boost::shared_ptr< Buffer > cygnal::AMF::encodeXMLObject ( const boost::uint8_t *  data,
size_t  nbytes 
) [static]

Encode an XML object to its serialized representation.

Encode an XML object to it's serialized representation.

Parameters:
data A pointer to the raw bytes that becomes the XML data.
nbytes The number of bytes to serialize.
Returns:
a binary AMF packet in big endian format
boost::shared_ptr< cygnal::Element > cygnal::AMF::extractAMF ( boost::shared_ptr< Buffer buf  ) 

Extract an AMF object from an array of raw bytes.

Parameters:
buf A smart pointer to a Buffer to parse the data from.
Returns:
A smart ptr to an Element.
Remarks:
May throw a ParserException
boost::shared_ptr< cygnal::Element > cygnal::AMF::extractAMF ( boost::uint8_t *  in,
boost::uint8_t *  tooFar 
)

Extract an AMF object from an array of raw bytes.

Extract an AMF object from an array of raw bytes. An AMF object is one of the support data types.

An AMF object is one of the support data types.

Parameters:
in A real pointer to the raw data to start parsing from.
tooFar A pointer to one-byte-past the last valid memory address within the buffer.
Returns:
A smart ptr to an Element.
Remarks:
May throw a ParserException
Parameters:
in A real pointer to the raw data to start parsing from.
tooFar A pointer to one-byte-past the last valid memory address within the buffer.
Returns:
A smart ptr to an Element.
Remarks:
May throw a ParserException

Referenced by cygnal::Flv::decodeMetaData(), gnash::RTMP::decodeMsgBody(), cygnal::AMF_msg::parseAMFPacket(), cygnal::EchoTest::parseEchoRequest(), cygnal::FitcDemoTest::parseFitcDemoRequest(), cygnal::LcShm::parseHeader(), and cygnal::OflaDemoTest::parseOflaDemoRequest().

static Element::amf0_type_e cygnal::AMF::extractElementHeader ( boost::uint8_t *  in  )  [inline, static]

Extract the AMF0 object type from the header.

Parameters:
in The raw data to extract values from.
Returns:
The data type from the header
boost::shared_ptr< cygnal::Element > cygnal::AMF::extractProperty ( boost::uint8_t *  in,
boost::uint8_t *  tooFar 
)

Extract a Property.

Extract a Property. A Property is a standard AMF object preceeded by a length and an ASCII name field. These are onicly used with higher level ActionScript objects.

A Property is a standard AMF object preceeded by a length and an ASCII name field. These are only used with higher level ActionScript objects.

Parameters:
in A real pointer to the raw data to start parsing from.
tooFar A pointer to one-byte-past the last valid memory address within the buffer.
Returns:
A smart ptr to an Element.
Remarks:
May throw a ParserException
Parameters:
in A real pointer to the raw data to start parsing from.
tooFar A pointer to one-byte-past the last valid memory address within the buffer.
Returns:
A smart ptr to an Element.
Remarks:
May throw a ParserException

Referenced by cygnal::RTMPServer::packetRead(), and cygnal::SOL::readFile().

boost::shared_ptr< cygnal::Element > cygnal::AMF::extractProperty ( boost::shared_ptr< Buffer buf  ) 

Extract a Property.

Extract a Property. A Property is a standard AMF object preceeded by a length and an ASCII name field. These are only used with higher level ActionScript objects.

A Property is a standard AMF object preceeded by a length and an ASCII name field. These are only used with higher level ActionScript objects.

Parameters:
buf A smart pointer to an Buffer to parse the data from.
Returns:
A smart ptr to an Element.
Remarks:
May throw a ParserException
Parameters:
buf A smart pointer to an Buffer to parse the data from.
Returns:
A smart ptr to an Element.
Remarks:
May throw a ParserException
size_t cygnal::AMF::totalsize (  )  [inline]

The documentation for this class was generated from the following files: