Class Amfphp_Core_Amf_Serializer

Description

AmfSerializer manages the job of translating PHP objects into the actionscript equivalent via Amf. The main method of the serializer is the serialize method which takes and AmfObject as it's argument and builds the resulting Amf Message.

TODO spit into 2 classes, one for Amf0 , one for Amf3 or maybe more.

Located in /Amfphp/Core/Amf/Serializer.php (line 22)


	
			
Direct descendents
Class Description
AmfSerializerWrapper This class exports some internal (public) methods. This way, those methods can be tested separately.
Class Constant Summary
Method Summary
Amfphp_Core_Amf_Serializer __construct (Amfphp_Core_Amf_Packet $packet)
string getAmf3Int (int $d)
void getOutput ()
void serialize ()
void writeAmf3Array ( $d, [ $arrayCollectionable = false])
nothing writeAmf3Bool (bool $d)
void writeAmf3ByteArray ( $d)
void writeAmf3Data ( &$d)
nothing writeAmf3Int (int $d)
nothing writeAmf3Null ()
void writeAmf3Number ( $d)
void writeAmf3Object ( $d)
nothing writeAmf3ObjectFromArray (array $d)
The writeAmf3String (string $d)
nothing writeAmf3Undefined ()
void writeAmf3Xml ( $d)
void writeAnonymousObject (array $d)
void writeArrayOrObject (array $d)
void writeBoolean (bool $d)
void writeByte (int $b)
void writeData (mixed $d)
void writeDate (date $d)
void writeDouble (double $d)
void writeInt (int $n)
void writeLong (long $l)
void writeLongUtf (string $s)
void writeNull ()
void writeNumber (int $d)
void writeObjectEnd ()
void writeObjectFromArray (array $d)
void writePlainArray ( $d)
void writeReference ( $num)
void writeString (string $d)
void writeTypedObject (object $d)
void writeUndefined ()
void writeUtf (string $s)
void writeXML (string $d)
Methods
Constructor __construct (line 74)
  • access: public
Amfphp_Core_Amf_Serializer __construct (Amfphp_Core_Amf_Packet $packet)
  • $packet
getAmf3Int (line 934)

Return the serialisation of the given integer (Amf3).

note: There does not seem to be a way to distinguish between signed and unsigned integers. This method just sends the lowest 29 bit as-is, and the receiver is responsible to interpret the result as signed or unsigned based on some context.

note: The limit imposed by Amf3 is 29 bit. So in case the given integer is longer than 29 bit, only the lowest 29 bits will be serialised. No error will be logged!

  • TODO: refactor into writeAmf3Int
  • access: protected
string getAmf3Int (int $d)
  • int $d: the integer to serialise
getOutput (line 134)
  • access: public
void getOutput ()
serialize (line 86)

serializes the Packet passed in the constructor TODO clean up the mess with the temp buffers. A.S.

  • access: public
void serialize ()
writeAmf3Array (line 793)
  • access: protected
void writeAmf3Array ( $d, [ $arrayCollectionable = false])
  • $d
  • $arrayCollectionable

Redefined in descendants as:
writeAmf3ArrayCollectionPreamble (line 652)

Write an ArrayCollection

  • access: protected
void writeAmf3ArrayCollectionPreamble ()
writeAmf3Bool (line 693)

Write a boolean (Amf3).

  • access: protected
nothing writeAmf3Bool (bool $d)
  • bool $d: the boolean to serialise

Redefined in descendants as:
writeAmf3ByteArray (line 998)
  • access: protected
void writeAmf3ByteArray ( $d)
  • $d

Redefined in descendants as:
writeAmf3ByteArrayMessage (line 1007)
  • access: protected
void writeAmf3ByteArrayMessage ( $d)
  • $d
writeAmf3Data (line 575)
  • todo: no type markers ("\6", for example) in this method!
  • todo: Is the reference still needed? PHP4 needed it for objects, but PHP5 always passes objects by reference. And PHP5 uses a copy-on-write approach, so that all values are passed as "reference", in case no changes take place.
  • access: protected
void writeAmf3Data ( &$d)
  • &$d

Redefined in descendants as:
writeAmf3Int (line 709)

Write an (un-)signed integer (Amf3).

nothing writeAmf3Int (int $d)
  • int $d: the integer to serialise
writeAmf3Null (line 679)

Write NULL (Amf3).

  • access: protected
nothing writeAmf3Null ()

Redefined in descendants as:
writeAmf3Number (line 972)
  • access: protected
void writeAmf3Number ( $d)
  • $d

Redefined in descendants as:
writeAmf3Object (line 1029)
  • TODO: better support for traits. Right now the object is considered dynamic, and that's all
  • access: protected
void writeAmf3Object ( $d)
  • $d

Redefined in descendants as:
writeAmf3ObjectFromArray (line 869)

Serialise the array as if it is an object.

  • access: protected
nothing writeAmf3ObjectFromArray (array $d)
  • array $d: the array to serialise
writeAmf3String (line 730)

Write a string (Amf3). Strings are stored in a cache and in case the same string is written again, a reference to the string is sent instead of the string itself.

note: Sending strings larger than 268435455 (2^28-1 byte) will (silently) fail!

note: The string marker is NOT sent here and has to be sent before, if needed.

  • return: reference index inside the lookup table is returned. In case of an empty string which is sent in a special way, NULL is returned.
  • access: protected
The writeAmf3String (string $d)
  • string $d: the string to send

Redefined in descendants as:
writeAmf3Undefined (line 668)

Write undefined (Amf3).

  • access: protected
nothing writeAmf3Undefined ()

Redefined in descendants as:
writeAmf3Xml (line 991)
  • access: protected
void writeAmf3Xml ( $d)
  • $d

Redefined in descendants as:
writeAnonymousObject (line 429)

writeObject handles writing a php array with string or mixed keys. It does not write the object code as that is handled by the writeArrayOrObject and this method is shared with the CustomClass writer which doesn't use the object code.

  • access: protected
void writeAnonymousObject (array $d)
  • array $d: The php array with string keys
writeArrayOrObject (line 313)

writeArrayOrObject first deterines if the PHP array contains all numeric indexes or a mix of keys. Then it either writes the array code (0x0A) or the object code (0x03) and then the associated data.

  • access: protected
void writeArrayOrObject (array $d)
  • array $d: The php array

Redefined in descendants as:
writeBoolean (line 215)

writeBoolean writes the boolean code (0x01) and the data to the output stream

  • access: protected
void writeBoolean (bool $d)
  • bool $d: The boolean value

Redefined in descendants as:
writeByte (line 143)

writeByte writes a singe byte to the output stream 0-255 range

  • access: protected
void writeByte (int $b)
  • int $b: An int that can be converted to a byte

Redefined in descendants as:
writeData (line 487)

writeData checks to see if the type was declared and then either auto negotiates the type or relies on the user defined type to serialize the data into Amf

  • access: protected
void writeData (mixed $d)
  • mixed $d: The data
writeDate (line 261)

writeData writes the date code (0x0B) and the date value to the output stream

  • access: protected
void writeDate (date $d)
  • date $d: The date value

Redefined in descendants as:
writeDouble (line 175)

writeDouble takes a float as the input and writes it to the output stream.

Then if the system is big-endian, it reverses the bytes order because all doubles passed via remoting are passed little-endian.

  • access: protected
void writeDouble (double $d)
  • double $d: The double to add to the output buffer

Redefined in descendants as:
writeInt (line 153)

writeInt takes an int and writes it as 2 bytes to the output stream 0-65535 range

  • access: protected
void writeInt (int $n)
  • int $n: An integer to convert to a 2 byte binary string

Redefined in descendants as:
writeLong (line 163)

writeLong takes an int, float or double and converts it to a 4 byte binary string and adds it to the output buffer

  • access: protected
void writeLong (long $l)
  • long $l: A long to convert to a 4 byte binary string

Redefined in descendants as:
writeLongUtf (line 204)

writeLongUTF will write a string longer than 65535 characters.

It works exactly as writeUTF does except uses a long for the length flag.

  • access: protected
void writeLongUtf (string $s)
  • string $s: A string to add to the byte stream

Redefined in descendants as:
writeNull (line 286)

writeNull writes the null code (0x05) to the output stream

  • access: protected
void writeNull ()

Redefined in descendants as:
writeNumber (line 278)

writeNumber writes the number code (0x00) and the numeric data to the output stream All numbers passed through remoting are floats.

  • access: protected
void writeNumber (int $d)
  • int $d: The numeric data

Redefined in descendants as:
writeObjectEnd (line 301)

writeObjectEnd writes the object end code (0x009) to the output stream

  • access: protected
void writeObjectEnd ()

Redefined in descendants as:
writeObjectFromArray (line 414)

writeObjectFromArray handles writing a php array with string or mixed keys. It does not write the object code as that is handled by the writeArrayOrObject and this method is shared with the CustomClass writer which doesn't use the object code.

  • access: protected
void writeObjectFromArray (array $d)
  • array $d: The php array with string keys
writePlainArray (line 394)

Write a plain numeric array without anything fancy

  • access: protected
void writePlainArray ( $d)
  • $d
writeReference (line 385)
  • access: protected
void writeReference ( $num)
  • $num

Redefined in descendants as:
writeReferenceIfExists (line 362)
  • access: protected
void writeReferenceIfExists ( $d)
  • $d
writeString (line 229)

writeString writes the string code (0x02) and the UTF8 encoded string to the output stream.

Note: strings are truncated to 64k max length. Use XML as type to send longer strings

  • access: protected
void writeString (string $d)
  • string $d: The string data

Redefined in descendants as:
writeTypedObject (line 453)

writeTypedObject takes an instance of a class and writes the variables defined in it to the output stream.

To accomplish this we just blanket grab all of the object vars with get_object_vars, minus the Amfphp_Core_Amf_Constants::FIELD_EXPLICIT_TYPE field, whiuch is used as class name

  • access: protected
void writeTypedObject (object $d)
  • object $d: The object to serialize the properties. The deserializer looks for Amfphp_Core_Amf_Constants::FIELD_EXPLICIT_TYPE on this object and writes it as the class name.

Redefined in descendants as:
writeUndefined (line 294)

writeUndefined writes the Undefined code (0x06) to the output stream

  • access: protected
void writeUndefined ()

Redefined in descendants as:
writeUtf (line 192)

writeUTF takes and input string, writes the length as an int and then appends the string to the output buffer

  • access: protected
void writeUtf (string $s)
  • string $s: The string less than 65535 characters to add to the stream

Redefined in descendants as:
writeXML (line 248)

writeXML writes the xml code (0x0F) and the XML string to the output stream

Note: strips whitespace

  • access: protected
void writeXML (string $d)
  • string $d: The XML string

Redefined in descendants as:
Class Constants
MAX_STORED_OBJECTS = 1024 (line 39)

the maximum amount of objects stored for reference

Documentation generated on Thu, 24 Mar 2011 16:55:41 +0100 by phpDocumentor 1.4.3