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 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.
void swapBytes (void *word, size_t size)
 Swap bytes in raw data.
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.

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.

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.

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.

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.

Referenced by 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.

Referenced by handleInvoke().

DSOEXPORT void gnash::amf::swapBytes ( void *  word,
size_t  size 
)

Swap bytes in raw data.

This only swaps bytes if the host byte order is little endian.

Parameters:
word The address of the data to byte swap.
size The number of bytes in the data.
Returns:
A pointer to the raw data.
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!

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!

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 
)

Write a string to an AMF buffer.

This function writes the type byte and the string value. It also handles both long and short strings automatically. 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!

Referenced by gnash::MouseDevice::command(), dump_shm(), replyBWCheck(), sendCheckBW(), sendConnectPacket(), sendCreateStream(), sendDeleteStream(), sendFCSubscribe(), sendPausePacket(), sendPlayPacket(), gnash::nsPluginInstance::Write(), write(), gnash::amf::Writer::writeBoolean(), gnash::ExternalInterface::writeBrowser(), gnash::Network::writeNet(), gnash::amf::Writer::writeNumber(), gnash::GnashPluginScriptObject::writePlayer(), writeProperty(), gnash::DiskStream::writeToDisk(), and gnash::amf::Writer::writeUndefined().

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.

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

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().