serialize

This method serializes a request. It requires an SabreAMF_OutputStream as an argument to read
the AMF Data from. After serialization the Outputstream will contain the encoded AMF data.

@param SabreAMF_OutputStream $stream
@return void
779087
public function serialize(SabreAMF_OutputStream $stream) {

            $this->outputStream = $stream;
            $stream->writeByte(0x00);
            $stream->writeByte($this->encoding);
            $stream->writeInt(count($this->headers));
            
            foreach($this->headers as $header) {

                $serializer = new SabreAMF_AMF0_Serializer($stream);
                $serializer->writeString($header['name']);
                $stream->writeByte($header['required']==true);
                $stream->writeLong(-1);
                $serializer->writeAMFData($header['data']);
            }

            $stream->writeInt(count($this->bodies));


            foreach($this->bodies as $body) {
                $serializer = new SabreAMF_AMF0_Serializer($stream);
                $serializer->writeString($body['target']);
                $serializer->writeString($body['response']);
                $stream->writeLong(-1);
                
                switch($this->encoding) {

                    case SabreAMF_Const::AMF0 :
                        $serializer->writeAMFData($body['data']);
                        break;
                    case SabreAMF_Const::AMF3 :
                        $serializer->writeAMFData(new SabreAMF_AMF3_Wrapper($body['data']));
                        break;

                }

            }

        }
452675
private function writeRemainingLength(PacketStream $stream)
    {
        $x = $this->remainingPacketLength;
        do {
            $encodedByte = $x % 128;
            $x = (int) ($x / 128);
            if ($x > 0) {
                $encodedByte |= 128;
            }

            $stream->writeByte($encodedByte);
        } while ($x > 0);
    }
424690
public function xmlSerialize(\Sabre\Xml\Writer $writer) {

        if ($this->attributes['rating'] != 'numeric') {
            $this->value = '';
        }

        parent::xmlSerialize($writer);
    }
1058019
public function writeArray($data) {

            if (!count($data)) {
                $this->stream->writeLong(0);
            } else {
                end($data);
                $last = key($data);
                $this->stream->writeLong($last+1);
                for($i=0;$i<=$last;$i++) {
                    if (isset($data[$i])) {
                        $this->writeAMFData($data[$i]);
                    } else {
                        $this->stream->writeByte(SabreAMF_AMF0_Const::DT_UNDEFINED);
                    }
                }
            }

        }
1246832
private function outputStream(): ResourceOutputStream
    {
        if (null === $this->outputStream)
        {
            $this->outputStream = new ResourceOutputStream(self::createStream($this->host, $this->port), 65000);
        }

        return $this->outputStream;
    }
192956
public function serialize($resource, OutputStream $out): OutputStream
    {
        if (is_object($resource) && method_exists($resource, '__toString')) {
            $out->write((string) $resource);
        } elseif (is_object($resource) || is_array($resource)) {
            $out->write(var_export($resource, true));
        } elseif (is_bool($resource) && $resource) {
            $out->write('true');
        } elseif (is_bool($resource) && !$resource) {
            $out->write('false');
        } else {
            $out->write((string) $resource);
        }

        return $out;
    }
1361296
public function writeMessage(Zend_Amf_Parse_OutputStream $stream)
    {
        $objectEncoding = $this->_objectEncoding;

        //Write encoding to start of stream. Preamble byte is written of two byte Unsigned Short
        $stream->writeByte(0x00);
        $stream->writeByte($objectEncoding);

        // Loop through the AMF Headers that need to be returned.
        $headerCount = count($this->_headers);
        $stream->writeInt($headerCount);
        foreach ($this->getAmfHeaders() as $header) {
            $serializer = new Zend_Amf_Parse_Amf0_Serializer($stream);
            $stream->writeUTF($header->name);
            $stream->writeByte($header->mustRead);
            $stream->writeLong(Zend_Amf_Constants::UNKNOWN_CONTENT_LENGTH);
            if (is_object($header->data)) {
                // Workaround for PHP5 with E_STRICT enabled complaining about
                // "Only variables should be passed by reference"
                $placeholder = null;
                $serializer->writeTypeMarker($placeholder, null, $header->data);
            } else {
                $serializer->writeTypeMarker($header->data);
            }
        }

        // loop through the AMF bodies that need to be returned.
        $bodyCount = count($this->_bodies);
        $stream->writeInt($bodyCount);
        foreach ($this->_bodies as $body) {
            $serializer = new Zend_Amf_Parse_Amf0_Serializer($stream);
            $stream->writeUTF($body->getTargetURI());
            $stream->writeUTF($body->getResponseURI());
            $stream->writeLong(Zend_Amf_Constants::UNKNOWN_CONTENT_LENGTH);
            $bodyData = $body->getData();
            $markerType = ($this->_objectEncoding == Zend_Amf_Constants::AMF0_OBJECT_ENCODING) ? null : Zend_Amf_Constants::AMF0_AMF3;
            if (is_object($bodyData)) {
                // Workaround for PHP5 with E_STRICT enabled complaining about
                // "Only variables should be passed by reference"
                $placeholder = null;
                $serializer->writeTypeMarker($placeholder, $markerType, $bodyData);
            } else {
                $serializer->writeTypeMarker($bodyData, $markerType);
            }
        }

        return $this;
    }
1060903
public void encode(byte aBuffer[], OutputStream aStream)
    throws IOException {
        ByteArrayInputStream inStream = new ByteArrayInputStream(aBuffer);
        encode(inStream, aStream);
    }
929951
public function write($bytes)
    {
        $this->out += strlen($bytes);
        foreach ($this->mirrors as $stream) {
            $stream->write($bytes);
        }
    }
1121860
public function setStream($stream)
    {
        parent::setStream($stream);
        foreach ($this->getStreamWriters() as $writer) {
            $writer->setStream($stream);
        }

        return $this;
    }
1325165
function _stream_write($data)
    {
        switch ($this->mode) {
            case 'r':
                return false;
        }

        $result = $this->sftp->put($this->path, $data, SFTP::SOURCE_STRING, $this->pos);
        if (isset($this->notification) && is_callable($this->notification)) {
            if (!$result) {
                call_user_func($this->notification, STREAM_NOTIFY_FAILURE, STREAM_NOTIFY_SEVERITY_ERR, $this->sftp->getLastSFTPError(), NET_SFTP_OPEN, 0, 0);
                return 0;
            }
            // seems that PHP splits up strings into 8k blocks before calling stream_write
            call_user_func($this->notification, STREAM_NOTIFY_PROGRESS, STREAM_NOTIFY_SEVERITY_INFO, '', 0, strlen($data), strlen($data));
        }

        if ($result === false) {
            return false;
        }
        $this->pos+= strlen($data);
        if ($this->pos > $this->size) {
            $this->size = $this->pos;
        }
        $this->eof = false;
        return strlen($data);
    }
1253038
protected function attachResource($stream) : void
    {
        if (is_resource($stream) === false) {
            throw new \InvalidArgumentException("Argument must be a valid resource type.");
        }

        $this->stream = $stream;
        $stats = fstat($this->stream);


        // Identifica se o "Stream" é "pipe"
        $bitMask = 0010000;
        $this->isPipe = (($stats["mode"] & $bitMask) !== 0);

        // Identifica o tamanho do "Stream" (se possível).
        $this->size = ((isset($stats["size"]) && $this->isPipe === false) ? $stats["size"] : null);

        // Resgata os metadados do "Stream"
        $this->metaData = stream_get_meta_data($this->stream);

        // Verifica se o "Stream" é "pesquisável"
        $this->seekable = ($this->isPipe === false && $this->metaData["seekable"]);



        $streamModes = [
            "readable" => ["r", "r+", "w+", "a+", "x+", "c+"],
            "writable" => ["r+", "w", "w+", "a", "a+", "x", "x+", "c", "c+"]
        ];

        // Verifica se é possível alterar o "Stream"
        foreach ($streamModes["writable"] as $mode) {
            if (strpos($this->metaData["mode"], $mode) === 0) {
                $this->writable = true;
                break;
            }
        }

        
        // Verifica se é possível ler o "Stream"
        foreach ($streamModes["readable"] as $mode) {
            if (strpos($this->metaData["mode"], $mode) === 0) {
                $this->readable = true;
                break;
            }
        }
    }
1128661
public function writeObject($data) {
           
            $encodingType = SabreAMF_AMF3_Const::ET_PROPLIST;
            if ($data instanceof SabreAMF_ITypedObject) {

                $classname = $data->getAMFClassName();
                $data = $data->getAMFData();

            } else if (!$classname = $this->getRemoteClassName(get_class($data))) {

                
                $classname = '';

            } else {

                if ($data instanceof SabreAMF_Externalized) {

                    $encodingType = SabreAMF_AMF3_Const::ET_EXTERNALIZED;

                }

            }


            $objectInfo = 0x03;
            $objectInfo |= $encodingType << 2;

            switch($encodingType) {

                case SabreAMF_AMF3_Const::ET_PROPLIST :

                    $propertyCount=0;
                    foreach($data as $k=>$v) {
                        $propertyCount++;
                    }

                    $objectInfo |= ($propertyCount << 4);


                    $this->writeInt($objectInfo);
                    $this->writeString($classname);
                    foreach($data as $k=>$v) {

                        $this->writeString($k);

                    }
                    foreach($data as $k=>$v) {

                        $this->writeAMFData($v);

                    }
                    break;

                case SabreAMF_AMF3_Const::ET_EXTERNALIZED :

                    $this->writeInt($objectInfo);
                    $this->writeString($classname);
                    $this->writeAMFData($data->writeExternal());
                    break;
            }

        }
142136
public final void serialize(OutputStream out) throws IOException {
        out.write(Jackson.toJsonString(this).getBytes(UTF8));
        out.flush();
    }
529308
public function setStream($stream)
    {
        if (! is_resource($stream) || ! 'stream' == get_resource_type($stream)) {
            throw new \InvalidArgumentException(sprintf(
                'Expects argument to be a stream resource, got %s',
                is_resource($stream) ? get_resource_type($stream) : gettype($stream)
            ));
        }

        $this->stream = $stream;

        return $this;
    }
741136
private void writeObject(ObjectOutputStream stream) throws IOException {

        /*
         * Since this is a simple class all we have to do is write each member to the stream.
         * the order has to remain identical to readObject, so I've just gone alphabetically.
         *
         * If we change the serialversionUID, we may need to modify this method as well.
         */

        if (tc.isEntryEnabled()) {
            Tr.entry(this, tc, "writeObject", stream);
        }

        ObjectOutputStream.PutField putField = stream.putFields();

        putField.put("activationConfigProps", activationConfigProps);
        putField.put("destinationRef", destinationRef);
        putField.put("authenticationAlias", authenticationAlias);
        putField.put("applicationName", applicationName);
        putField.put("qmid", qmid);

        stream.writeFields();

        if (tc.isEntryEnabled()) {
            Tr.exit(this, tc, "writeObject activation config - " + this.toString());
        }

    }
1166225
public function removeWriteStream($stream)
    {
        unset(
            $this->writeStreams[(int) $stream],
            $this->writeCallbacks[(int) $stream]
        );
    }