This class exports some internal (public) methods.
This way, those methods can be tested separately.
package | Tests_Amfphp_Core_Amf |
---|---|
author | Ariel Sommeria-klein |
getOutput() : string
inherited_from | \Amfphp_Core_Amf_Serializer::getOutput() |
---|
string
serialize(\Amfphp_Core_Amf_Packet $data) : String
The return type is noted as a String, but is a binary stream. echo it to the output buffer
inherited_from | \Amfphp_Core_Amf_Serializer::serialize() |
---|
\Amfphp_Core_Amf_Packet
String
writeAmf3Array(array $d)
array
writeAmf3Bool(boolean $d) : \nothing
boolean
\nothing
writeAmf3ByteArray(\Amfphp_Core_Amf_Types_ByteArray $d)
writeAmf3Data(mixed $d)
mixed
writeAmf3Null() : \nothing
\nothing
writeAmf3Number(float $d)
float
writeAmf3String(string $d) : \The
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.
string
\The
reference index inside the lookup table is returned. In case of an empty
string which is sent in a special way, NULL is returned.writeAmf3TypedObject(\stdClass $d)
Type is determined by having an "explicit type" field. If this field is not set, call writeAmf3AnonymousObject write all properties as sealed members.
\stdClass
writeAmf3Undefined() : \nothing
\nothing
writeArrayOrObject(array $d)
Then it either writes the array code (0x0A) or the object code (0x03) and then the associated data.
array
writeBoolean(boolean $b)
boolean
writeByte(int $b)
int
writeDouble(float $s)
Then if the system is big-endian, it reverses the bytes order because all doubles passed via remoting are passed little-endian.
float
writeInt(int $n)
int
writeLong(int $l)
int
writeLongUtf(string $s)
It works exactly as writeUTF does except uses a long for the length flag.
string
writeNull()
writeNumber(float $d)
float
writeObjectEnd()
writeReference(int $d)
int
writeString(string $d)
Note: strings are truncated to 64k max length. Use XML as type to send longer strings
string
writeTypedObject(\stdClass $d)
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
\stdClass
writeUndefined()
writeUtf(string $s)
string
getAmf3Int(int $d) : string
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 |
---|---|
inherited_from | \Amfphp_Core_Amf_Serializer::getAmf3Int() |
int
the integer to serialise
string
handleReference(mixed $obj, array $references)
If it does, write it, and return true. If not, add it to the references array. Depending on whether or not the spl_object_hash function can be used ( available (PHP >= 5.2), and can only be used on an object) things are handled a bit differently: - if possible, objects are hashed and the hash is used as a key to the references array. So the array has the structure hash => reference - if not, the object is pushed to the references array, and array_search is used. So the array has the structure reference => object. maxing out the number of stored references improves performance(tested with an array of 9000 identical objects). This may be because isset's performance is linked to the size of the array. weird... note on using $references[$count] = &$obj; rather than $references[] = &$obj; the first one is right, the second is not, as with the second one we could end up with the following: some object hash => 0, 0 => array. (it should be 1 => array)
This also means that 2 completely separate instances of a class but with the same values will be written fully twice if we can't use the hash system
inherited_from | \Amfphp_Core_Amf_Serializer::handleReference() |
---|
mixed
array
resetReferences()
Call before writing a body or a header, as the indices are local to each message body or header
inherited_from | \Amfphp_Core_Amf_Serializer::resetReferences() |
---|
writeAmf3AnonymousObject(\stdClass $d, \doReference $doReference)
In this way a reference to a class trait will have the right id.
inherited_from | \Amfphp_Core_Amf_Serializer::writeAmf3AnonymousObject() |
---|
\doReference
Boolean This is used by writeAmf3Array, where the reference has already been taken care of, so there this method is called with false
writeAmf3Int(int $d) : \nothing
see | \getAmf3Int() |
---|---|
inherited_from | \Amfphp_Core_Amf_Serializer::writeAmf3Int() |
int
the integer to serialise
\nothing
writeAnonymousObject(\stdClass $d)
inherited_from | \Amfphp_Core_Amf_Serializer::writeAnonymousObject() |
---|
writeData(mixed $d)
inherited_from | \Amfphp_Core_Amf_Serializer::writeData() |
---|
mixed
The data
writeObjectFromArray(array $d)
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.
inherited_from | \Amfphp_Core_Amf_Serializer::writeObjectFromArray() |
---|
array
The php array with string keys
$Amf0StoredObjects : array
inherited_from | \Amfphp_Core_Amf_Serializer::$$Amf0StoredObjects |
---|
$className2TraitsInfo : array
key: class name. value: array(reference id, array(property names))
inherited_from | \Amfphp_Core_Amf_Serializer::$$className2TraitsInfo |
---|
$outBuffer : String
inherited_from | \Amfphp_Core_Amf_Serializer::$$outBuffer |
---|
$storedObjects : array
inherited_from | \Amfphp_Core_Amf_Serializer::$$storedObjects |
---|
$storedStrings : array
inherited_from | \Amfphp_Core_Amf_Serializer::$$storedStrings |
---|
MAX_STORED_OBJECTS
inherited_from | \Amfphp_Core_Amf_Serializer::MAX_STORED_OBJECTS |
---|