Gnash  0.8.10
Classes | Enumerations | Functions
gnash::amf Namespace Reference

Functions and classes for handling AMF. More...

Classes

class  AMFException
 Exception for handling malformed buffers. More...
class  Writer
 A class to compose AMF buffers. More...
class  Reader
 Deserialize an AMF buffer to as_values. More...

Enumerations

enum  Type {
  NOTYPE = -1, NUMBER_AMF0 = 0x00, BOOLEAN_AMF0 = 0x01, STRING_AMF0 = 0x02,
  OBJECT_AMF0 = 0x03, MOVIECLIP_AMF0 = 0x04, NULL_AMF0 = 0x05, UNDEFINED_AMF0 = 0x06,
  REFERENCE_AMF0 = 0x07, ECMA_ARRAY_AMF0 = 0x08, OBJECT_END_AMF0 = 0x09, STRICT_ARRAY_AMF0 = 0x0a,
  DATE_AMF0 = 0x0b, LONG_STRING_AMF0 = 0x0c, UNSUPPORTED_AMF0 = 0x0d, RECORD_SET_AMF0 = 0x0e,
  XML_OBJECT_AMF0 = 0x0f, TYPED_OBJECT_AMF0 = 0x10
}

Functions

bool readBoolean (const boost::uint8_t *&pos, const boost::uint8_t *end)
 Read a boolean value from the buffer.
double readNumber (const boost::uint8_t *&pos, const boost::uint8_t *end)
 Read a number from an AMF buffer.
std::string readString (const boost::uint8_t *&pos, const boost::uint8_t *end)
 Read a string value from the buffer.
std::string readLongString (const boost::uint8_t *&pos, const boost::uint8_t *end)
 Read a long string value from the buffer.
void writePlainString (SimpleBuffer &buf, const std::string &str, Type t)
 Encode a plain short string to an AMF buffer.
void writePlainNumber (SimpleBuffer &buf, double d)
 Write a number to an AMF buffer.
void write (SimpleBuffer &buf, const std::string &str)
 Write a string to an AMF buffer.
void write (SimpleBuffer &buf, double d)
 Write a number to an AMF buffer.
void write (SimpleBuffer &buf, bool b)
 Write a boolean value to an AMF buffer.
boost::uint16_t readNetworkShort (const boost::uint8_t *buf)
 Read an unsigned 16-bit value in network byte order.
boost::uint32_t readNetworkLong (const boost::uint8_t *buf)
 Read an unsigned 32-bit value in network byte order.
void write (SimpleBuffer &buf, const char *str)
 Write a C string to an AMF buffer.
template<typename T >
void writeProperty (SimpleBuffer &buf, const std::string &name, const T &t)
 Encode a string-value pair.

Detailed Description

Functions and classes for handling AMF.

AMF is a simple serialization format for ActionScript objects and values, allowing them to be stored and transmitted. The AMF namespace provides both low-level and high-level conversion to and from AMF buffers.

AMF is a simple serialization format for ActionScript objects and values, allowing them to be stored and transmitted. These classes convert between AMF buffers and the objects they contain.


Enumeration Type Documentation

Enumerator:
NOTYPE 
NUMBER_AMF0 
BOOLEAN_AMF0 
STRING_AMF0 
OBJECT_AMF0 
MOVIECLIP_AMF0 
NULL_AMF0 
UNDEFINED_AMF0 
REFERENCE_AMF0 
ECMA_ARRAY_AMF0 
OBJECT_END_AMF0 
STRICT_ARRAY_AMF0 
DATE_AMF0 
LONG_STRING_AMF0 
UNSUPPORTED_AMF0 
RECORD_SET_AMF0 
XML_OBJECT_AMF0 
TYPED_OBJECT_AMF0 

Function Documentation

DSOEXPORT bool gnash::amf::readBoolean ( const boost::uint8_t *&  pos,
const boost::uint8_t *  end 
)

Read a boolean value from the buffer.

This does not read a type byte; use AMF::Reader when the type should be determined from the buffer. This function will throw an AMFException if it encounters ill-formed AMF.

Referenced by gnash::amf::Reader::operator()().

DSOEXPORT std::string gnash::amf::readLongString ( const boost::uint8_t *&  pos,
const boost::uint8_t *  end 
)

Read a long string value from the buffer.

This does not read a type byte; use AMF::Reader when the type should be determined from the buffer. This function will throw an AMFException if it encounters ill-formed AMF.

References readNetworkLong().

Referenced by gnash::amf::Reader::operator()().

boost::uint32_t gnash::amf::readNetworkLong ( const boost::uint8_t *  buf) [inline]

Read an unsigned 32-bit value in network byte order.

You must ensure that the buffer contains at least 4 bytes!

References gnash::key::s.

Referenced by readLongString().

boost::uint16_t gnash::amf::readNetworkShort ( const boost::uint8_t *  buf) [inline]

Read an unsigned 16-bit value in network byte order.

You must ensure that the buffer contains at least 2 bytes!

References gnash::key::s.

Referenced by readString().

DSOEXPORT double gnash::amf::readNumber ( const boost::uint8_t *&  pos,
const boost::uint8_t *  end 
)

Read a number from an AMF buffer.

This does not read a type byte; use AMF::Reader when the type should be determined from the buffer. This function will throw an AMFException if it encounters ill-formed AMF.

References gnash::key::d.

Referenced by gnash::amf::Reader::operator()(), and handleInvoke().

DSOEXPORT std::string gnash::amf::readString ( const boost::uint8_t *&  pos,
const boost::uint8_t *  end 
)

Read a string value from the buffer.

This does not read a type byte; use AMF::Reader when the type should be determined from the buffer. This function will throw an AMFException if it encounters ill-formed AMF.

References _, and readNetworkShort().

Referenced by gnash::amf::Reader::operator()(), gnash::rtmp::RTMP::sendPacket(), and handleInvoke().

void gnash::amf::write ( SimpleBuffer &  buf,
const char *  str 
) [inline]

Write a C string to an AMF buffer.

The overload is necessary to prevent const char* being resolved to the boolean overload.

References write().

DSOEXPORT void gnash::amf::write ( SimpleBuffer &  buf,
const std::string &  str 
)
DSOEXPORT void gnash::amf::write ( SimpleBuffer &  buf,
double  d 
)

Write a number to an AMF buffer.

This function writes the type byte and the double value. This is overloaded for automatic type deduction to allow the use of a template for more complex operations. You must be careful when using it!

References gnash::SimpleBuffer::appendByte(), NUMBER_AMF0, and writePlainNumber().

DSOEXPORT void gnash::amf::write ( SimpleBuffer &  buf,
bool  b 
)

Write a boolean value to an AMF buffer.

This function writes the type byte and the boolean value. This is overloaded for automatic type deduction to allow the use of a template for more complex operations. You must be careful when using it!

References gnash::SimpleBuffer::appendByte(), and BOOLEAN_AMF0.

DSOEXPORT void gnash::amf::writePlainNumber ( SimpleBuffer &  buf,
double  d 
)

Write a number to an AMF buffer.

This function writes the double value without a type byte.

References gnash::SimpleBuffer::append().

Referenced by write(), and gnash::amf::Writer::writeObject().

DSOEXPORT void gnash::amf::writePlainString ( SimpleBuffer &  buf,
const std::string &  str,
Type  t 
)

Encode a plain short string to an AMF buffer.

This does not encode a type byte; it is used for cases where a string is required, such as for the name of an object property, and therefore does not use a type byte.

References _, LONG_STRING_AMF0, gnash::SimpleBuffer::appendNetworkLong(), STRING_AMF0, gnash::SimpleBuffer::appendNetworkShort(), and gnash::SimpleBuffer::append().

Referenced by write(), writeProperty(), gnash::amf::Writer::writePropertyName(), and gnash::amf::Writer::writeObject().

template<typename T >
void gnash::amf::writeProperty ( SimpleBuffer &  buf,
const std::string &  name,
const T &  t 
)

Encode a string-value pair.

This is used for object properties; the string is always encoded with a 2-byte length.

References writePlainString(), STRING_AMF0, and write().

Referenced by sendConnectPacket().