Gnash  0.8.11dev
Classes | Enumerations | Functions
gnash::amf Namespace Reference

Functions and classes for handling AMF. More...

Classes

class  AMFException
 Exception for handling malformed buffers. More...
 
class  Reader
 Deserialize an AMF buffer to as_values. More...
 
class  Writer
 A class to compose AMF buffers. 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. More...
 
double readNumber (const boost::uint8_t *&pos, const boost::uint8_t *end)
 Read a number from an AMF buffer. More...
 
std::string readString (const boost::uint8_t *&pos, const boost::uint8_t *end)
 Read a string value from the buffer. More...
 
std::string readLongString (const boost::uint8_t *&pos, const boost::uint8_t *end)
 Read a long string value from the buffer. More...
 
void writePlainString (SimpleBuffer &buf, const std::string &str, Type t)
 Encode a plain short string to an AMF buffer. More...
 
void writePlainNumber (SimpleBuffer &buf, double d)
 Write a number to an AMF buffer. More...
 
void write (SimpleBuffer &buf, const std::string &str)
 Write a string to an AMF buffer. More...
 
void write (SimpleBuffer &buf, double d)
 Write a number to an AMF buffer. More...
 
void write (SimpleBuffer &buf, bool b)
 Write a boolean value to an AMF buffer. More...
 
boost::uint16_t readNetworkShort (const boost::uint8_t *buf)
 Read an unsigned 16-bit value in network byte order. More...
 
boost::uint32_t readNetworkLong (const boost::uint8_t *buf)
 Read an unsigned 32-bit value in network byte order. More...
 
void write (SimpleBuffer &buf, const char *str)
 Write a C string to an AMF buffer. More...
 
template<typename T >
void writeProperty (SimpleBuffer &buf, const std::string &name, const T &t)
 Encode a string-value pair. More...
 

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 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 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 handleInvoke(), and gnash::amf::Reader::operator()().

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 handleInvoke(), gnash::amf::Reader::operator()(), and gnash::rtmp::RTMP::sendPacket().

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 _, gnash::SimpleBuffer::append(), gnash::SimpleBuffer::appendNetworkLong(), gnash::SimpleBuffer::appendNetworkShort(), LONG_STRING_AMF0, and STRING_AMF0.

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

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 STRING_AMF0, write(), and writePlainString().

Referenced by sendConnectPacket().