This class exports some internal (public) methods.

This way, those methods can be tested separately.

package | Tests_Amfphp_Core_Amf
author | Ariel Sommeria-klein

### Methods

## constructor

    __construct(\Amfphp_Core_Amf_Packet $packet)

### Parameters

#### $packet

`\Amfphp_Core_Amf_Packet`

## get serialized data output

    getOutput() : string

Inherited

inherited_from | \Amfphp_Core_Amf_Serializer::getOutput()

### Returns

`string`

## converts from php object to binary

    serialize(\Amfphp_Core_Amf_Packet $data) : String

Inherited

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

### Parameters

#### $data

`\Amfphp_Core_Amf_Packet`

### Returns

`String`

## write amf3 array

    writeAmf3Array(array $d)

### Parameters

#### $d

`array`

## write amf3 boolean

    writeAmf3Bool(boolean $d) : \nothing

### Parameters

#### $d

`boolean`

### Returns

`\nothing`

## write Amfphp_Core_Amf_Types_ByteArray in amf3

    writeAmf3ByteArray(\Amfphp_Core_Amf_Types_ByteArray $d)

### Parameters

#### $d

`\Amfphp_Core_Amf_Types_ByteArray`

## write amf3 datas

    writeAmf3Data(mixed $d)

### Parameters

#### $d

`mixed`

## write amf3 date

    writeAmf3Date(\Amfphp_Core_Amf_Types_Date $d)

### Parameters

#### $d

`\Amfphp_Core_Amf_Types_Date`

## write amf3 null

    writeAmf3Null() : \nothing

### Returns

`\nothing`

## write amf3 number

    writeAmf3Number(float $d)

### Parameters

#### $d

`float`

## write amf3 string

    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.

### Parameters

#### $d

`string`

### Returns

`\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.

## write amf3 typed object

    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.

### Parameters

#### $d

`\stdClass`

## write amf3 undefined

    writeAmf3Undefined() : \nothing

### Returns

`\nothing`

## write amf3 xml

    writeAmf3Xml(\Amfphp_Core_Amf_Types_Xml $d)

### Parameters

#### $d

`\Amfphp_Core_Amf_Types_Xml`

## write amf3 xml doc

    writeAmf3XmlDocument(\Amfphp_Core_Amf_Types_XmlDocument $d)

### Parameters

#### $d

`\Amfphp_Core_Amf_Types_XmlDocument`

## write array or object

    writeArrayOrObject(array $d)

Then it either writes the array code (0x0A) or the object code (0x03) and then the associated data.

### Parameters

#### $d

`array`

## write boolean

    writeBoolean(boolean $b)

### Parameters

#### $b

`boolean`

## write byte

    writeByte(int $b)

### Parameters

#### $b

`int`

## write date

    writeDate(\Amfphp_Core_Amf_Types_Date $d)

### Parameters

#### $d

`\Amfphp_Core_Amf_Types_Date`

## write double

    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.

### Parameters

#### $s

`float`

## write int

    writeInt(int $n)

### Parameters

#### $n

`int`

## write long

    writeLong(int $l)

### Parameters

#### $l

`int`

## write long utf string

    writeLongUtf(string $s)

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

### Parameters

#### $s

`string`

## write null

    writeNull()

## write number

    writeNumber(float $d)

### Parameters

#### $d

`float`

## write object end

    writeObjectEnd()

## write reference

    writeReference(int $d)

### Parameters

#### $d

`int`

## write string

    writeString(string $d)

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

### Parameters

#### $d

`string`

## write typed object

    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

### Parameters

#### $d

`\stdClass`

## write undefined

    writeUndefined()

## write utf string

    writeUtf(string $s)

### Parameters

#### $s

`string`

## write xml

    writeXML(\Amfphp_Core_Amf_Types_Xml $d)

### Parameters

#### $d

`\Amfphp_Core_Amf_Types_Xml`

## Return the serialisation of the given integer (Amf3).

    getAmf3Int(int $d) : string

Inherited

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

### Parameters

#### $d

`int`

the integer to serialise

### Returns

`string`

## looks if $obj already has a reference.

    handleReference(mixed $obj, array $references)

Inherited

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

### Parameters

#### $obj

`mixed`

#### $references

`array`

## initialize reference arrays and counters.

    resetReferences()

Inherited

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

## handles writing an anoynous object (stdClass) can also be a reference Also creates a bogus traits entry, as even an anonymous object has traits.

    writeAmf3AnonymousObject(\stdClass $d, \doReference $doReference)

Inherited

In this way a reference to a class trait will have the right id.

inherited_from | \Amfphp_Core_Amf_Serializer::writeAmf3AnonymousObject()

### Parameters

#### $d

`\stdClass`

The php object to write

#### $doReference

`\doReference`

Boolean This is used by writeAmf3Array, where the reference has already been taken care of, so there this method is called with false

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

    writeAmf3Int(int $d) : \nothing

Inherited

see | \getAmf3Int()
inherited_from | \Amfphp_Core_Amf_Serializer::writeAmf3Int()

### Parameters

#### $d

`int`

the integer to serialise

### Returns

`\nothing`

## handles writing an anoynous object (stdClass) can also be a reference

    writeAnonymousObject(\stdClass $d)

Inherited

inherited_from | \Amfphp_Core_Amf_Serializer::writeAnonymousObject()

### Parameters

#### $d

`\stdClass`

The php object to write

## 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

    writeData(mixed $d)

Inherited

inherited_from | \Amfphp_Core_Amf_Serializer::writeData()

### Parameters

#### $d

`mixed`

The data

## writeObjectFromArray handles writing a php array with string or mixed keys.

    writeObjectFromArray(array $d)

Inherited

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

### Parameters

#### $d

`array`

The php array with string keys

### Properties

##

    $Amf0StoredObjects : array

Inherited

inherited_from | \Amfphp_Core_Amf_Serializer::$$Amf0StoredObjects

##

    $className2TraitsInfo : array

Inherited

key: class name. value: array(reference id, array(property names))

inherited_from | \Amfphp_Core_Amf_Serializer::$$className2TraitsInfo

## the output stream

    $outBuffer : String

Inherited

inherited_from | \Amfphp_Core_Amf_Serializer::$$outBuffer

##

    $packet : \Amfphp_Core_Amf_Packet

Inherited

inherited_from | \Amfphp_Core_Amf_Serializer::$$packet

##

    $storedObjects : array

Inherited

inherited_from | \Amfphp_Core_Amf_Serializer::$$storedObjects

##

    $storedStrings : array

Inherited

inherited_from | \Amfphp_Core_Amf_Serializer::$$storedStrings

### Constants

## the maximum amount of objects stored for reference

    MAX_STORED_OBJECTS

Inherited

inherited_from | \Amfphp_Core_Amf_Serializer::MAX_STORED_OBJECTS