Package pyamf :: Module amf3

[hide private]
[frames] | no frames]

# Module amf3

source code

AMF3 implementation.

`AMF3` is the default serialization for ActionScript 3.0 and provides various advantages over AMF0, which is used for ActionScript 1.0 and 2.0. It adds support for sending `int` and `uint` objects as integers and supports data types that are available only in ActionScript 3.0, such as ByteArray and ArrayCollection.

See Also:
  Official AMF3 Specification in English (external), Official AMF3 Specification in Japanese (external), AMF3 documentation on OSFlash (external)

Since: 0.1

Classes | [hide private]

| ObjectEncoding AMF object encodings.
| DataOutput I am a `StringIO` type object containing byte data from the AMF stream.
| DataInput I provide a set of methods for reading binary data with ActionScript 3.0.
| ByteArray I am a `StringIO` type object containing byte data from the AMF stream.
| ClassDefinition
| Context I hold the AMF3 context for en/decoding streams.
| Decoder Decodes an AMF3 data stream.
| Encoder Encodes an AMF3 data stream.

Functions | [hide private]

decode(stream, context=None, strict=False) A helper function to decode an AMF3 datastream. | source code

BufferedByteStream

encode(*args, **kwargs) A helper function to encode an element into AMF3 format. | source code

Variables | [hide private]

| use_proxies_default = `False` If True encode/decode lists/tuples to ArrayCollections and dicts to ObjectProxy
| TYPE_UNDEFINED = ``'``\x00``'`` The undefined type is represented by the undefined type marker.
| TYPE_NULL = ``'``\x01``'`` The null type is represented by the null type marker.
| TYPE_BOOL_FALSE = ``'``\x02``'`` The false type is represented by the false type marker and is used to encode a Boolean value of `false`.
| TYPE_BOOL_TRUE = ``'``\x03``'`` The true type is represented by the true type marker and is used to encode a Boolean value of `true`.
| TYPE_INTEGER = ``'``\x04``'`` In AMF 3 integers are serialized using a variable length signed 29-bit integer.
| TYPE_NUMBER = ``'``\x05``'`` This type is used to encode an ActionScript Number or an ActionScript `int` of value greater than or equal to 2^28 or an ActionScript uint of value greater than or equal to 2^29.
| TYPE_STRING = ``'``\x06``'`` ActionScript String values are represented using a single string type in AMF 3 - the concept of string and long string types from AMF 0 is not used.
| TYPE_XML = ``'``\x07``'`` ActionScript 3.0 introduced a new XML type however the legacy `XMLDocument` type from ActionScript 1.0 and 2.0.is retained in the language as `flash.xml.XMLDocument`.
| TYPE_DATE = ``'``\x08``'`` In AMF 3 an ActionScript Date is serialized simply as the number of milliseconds elapsed since the epoch of midnight, 1st Jan 1970 in the UTC time zone.
| TYPE_ARRAY = ``'``\t``'`` ActionScript Arrays are described based on the nature of their indices, i.e.
| TYPE_OBJECT = ``'``\n``'`` A single AMF 3 type handles ActionScript Objects and custom user classes.
| TYPE_XMLSTRING = ``'``\x0b``'`` ActionScript 3.0 introduces a new top-level XML class that supports E4X syntax.
| TYPE_BYTEARRAY = ``'``\x0c``'`` ActionScript 3.0 introduces the ByteArray type to hold an Array of bytes.
| REFERENCE_BIT = `1` Reference bit.
| MAX_29B_INT = `268435455` The maximum that can be represented by an signed 29 bit integer.
| MIN_29B_INT = `-268435456` The minimum that can be represented by an signed 29 bit integer.
| ENCODED_INT_CACHE = ``{`0`:` `'``\x00``'``,` 1`:` `'``\x01``'``,` 2`:` `'``\x02``'``,` 3`:` `'``\x03``...``

Imports: types, datetime, zlib, pyamf, util, ObjectProxy, ArrayCollection, set, encode_int, decode_int

Function Details | [hide private]

### decode(stream, context=None, strict=False)

source code

A helper function to decode an AMF3 datastream.

Parameters:
  - `stream` (BufferedByteStream) - AMF3 data.
  - `context` (Context) - Context.

### encode(*args, **kwargs)

source code

A helper function to encode an element into AMF3 format.

Parameters:
  - `context` (Context) - Any initial context to use.
  - `args` (List of args to encode.)
Returns: BufferedByteStream
  `StringIO` type object containing the encoded AMF3 data.

Variables Details | [hide private]

### TYPE_UNDEFINED

The undefined type is represented by the undefined type marker. No further information is encoded for this value.

Value:

      '\x00'

### TYPE_NULL

The null type is represented by the null type marker. No further information is encoded for this value.

Value:

      '\x01'

### TYPE_BOOL_FALSE

The false type is represented by the false type marker and is used to encode a Boolean value of `false`. No further information is encoded for this value.

Value:

      '\x02'

### TYPE_BOOL_TRUE

The true type is represented by the true type marker and is used to encode a Boolean value of `true`. No further information is encoded for this value.

Value:

      '\x03'

### TYPE_INTEGER

In AMF 3 integers are serialized using a variable length signed 29-bit integer.

See Also: Parsing Integers on OSFlash (external)

Value:

      '\x04'

### TYPE_NUMBER

This type is used to encode an ActionScript Number or an ActionScript `int` of value greater than or equal to 2^28 or an ActionScript uint of value greater than or equal to 2^29. The encoded value is is always an 8 byte IEEE-754 double precision floating point value in network byte order (sign bit in low memory). The AMF 3 number type is encoded in the same manner as the AMF 0 Number type.

Value:

      '\x05'

### TYPE_STRING

ActionScript String values are represented using a single string type in AMF 3 - the concept of string and long string types from AMF 0 is not used. Strings can be sent as a reference to a previously occurring String by using an index to the implicit string reference table. Strings are encoding using UTF-8 - however the header may either describe a string literal or a string reference.

Value:

      '\x06'

### TYPE_XML

ActionScript 3.0 introduced a new XML type however the legacy `XMLDocument` type from ActionScript 1.0 and 2.0.is retained in the language as `flash.xml.XMLDocument`. Similar to AMF 0, the structure of an `XMLDocument` needs to be flattened into a string representation for serialization. As with other strings in AMF, the content is encoded in UTF-8. XMLDocuments can be sent as a reference to a previously occurring `XMLDocument` instance by using an index to the implicit object reference table.

See Also: OSFlash documentation (external)

Value:

      '\x07'

### TYPE_DATE

In AMF 3 an ActionScript Date is serialized simply as the number of milliseconds elapsed since the epoch of midnight, 1st Jan 1970 in the UTC time zone. Local time zone information is not sent.

Value:

      '\x08'

### TYPE_ARRAY

ActionScript Arrays are described based on the nature of their indices, i.e. their type and how they are positioned in the Array.

Value:

      '\t'

### TYPE_XMLSTRING

ActionScript 3.0 introduces a new top-level XML class that supports E4X syntax. For serialization purposes the XML type needs to be flattened into a string representation. As with other strings in AMF, the content is encoded using UTF-8.

Value:

      '\x0b'

### TYPE_BYTEARRAY

ActionScript 3.0 introduces the ByteArray type to hold an Array of bytes. AMF 3 serializes this type using a variable length encoding 29-bit integer for the byte-length prefix followed by the raw bytes of the ByteArray.

See Also: Parsing ByteArrays on OSFlash (external)

Value:

      '\x0c'

### ENCODED_INT_CACHE

Value:

      {0: '\x00',
       1: '\x01',
       2: '\x02',
       3: '\x03',
       4: '\x04',
       5: '\x05',
       6: '\x06',
       7: '\x07',
      ...