Encode a stream of bytes.

@param \Protobuf\Stream $stream
@param \Protobuf\Stream $value
329282
public function writeByteStream(Stream $stream, Stream $value)
    {
        $length = $value->getSize();

        $value->seek(0);
        $this->writeVarint($stream, $length);
        $stream->writeStream($value, $length);
    }
1206284
public function encode($value)
    {
        switch (true) {
            case is_null($value):
                return $this->encodeString('', self::T_NULL);
            case is_bool($value):
                return $this->encodeString($value ? 'true' : 'false', self::T_BOOL);
            case is_int($value):
                return $this->encodeString($value, self::T_INT);
            case is_float($value):
                return $this->encodeString($value, self::T_FLOAT);
            case is_array($value):
                return $this->encodePHPArray($value);

            case is_resource($value):
                throw new InvalidArgumentException("You can't encode a PHP resource as a tagged netstring.");

            default:
                return $this->encodeString($value);
        }
    }
1370046
protected function _encodeHeader($value)
    {
        if (Zend_Mime::isPrintable($value) === false) {
            if ($this->getHeaderEncoding() === Zend_Mime::ENCODING_QUOTEDPRINTABLE) {
                $value = Zend_Mime::encodeQuotedPrintableHeader($value, $this->getCharset(), Zend_Mime::LINELENGTH, Zend_Mime::LINEEND);
            } else {
                $value = Zend_Mime::encodeBase64Header($value, $this->getCharset(), Zend_Mime::LINELENGTH, Zend_Mime::LINEEND);
            }
        }

        return $value;
    }
1292236
public function setSignature($value = null)
    {
        if ($value !== null && ! $value instanceof \Protobuf\Stream) {
            $value = \Protobuf\Stream::wrap($value);
        }

        $this->Signature = $value;
    }
950185
def encode(self, value):
        '''
        
        '''
        encoded = strToBytes(value) + b'\x00'
        return Bits(bytes=encoded)
659000
public function initFromStream($stream)
    {
        if (!$stream instanceof StreamInterface) {
            $stream = new Stream($stream);
        }

        try {
            $offset = $stream->tell();
        } catch (\RuntimeException $e) {
            $offset = 0;
        }

        $shouldAndCanSeek = $offset !== 0 && $stream->isSeekable();

        if ($shouldAndCanSeek) {
            $stream->rewind();
        }

        try {
            $data = $stream->getContents();
        } catch (\RuntimeException $e) {
            $data = null;
        }

        if ($shouldAndCanSeek) {
            $stream->seek($offset);
        }

        if ($data) {
            return $this->initFromBinary($data);
        }

        throw new \Intervention\Image\Exception\NotReadableException(
            "Unable to init from given stream"
        );
    }
1144131
public function addStream($stream)
    {
        while (!feof($stream)) {
            $freeBufferLength = $this->chunkSize - StringHelper::byteLength($this->_buffer);

            $streamChunk = fread($stream, $freeBufferLength);
            if ($streamChunk === false) {
                break;
            }
            $this->_buffer .= $streamChunk;
            $this->flushBuffer();
        }

        return $this;
    }
808830
public function setStreamTimeout($value)
    {
        if ($value < 1) {
            $value = self::DEFAULT_STREAM_TIMEOUT;
        }

        $this->streamTimeout = (int) $value;
        if ($this->handle !== null) {
            stream_set_timeout($this->handle, 0, $this->getStreamTimeout());
        }
    }
925844
public function readByte(Stream $stream)
    {
        $char = $stream->read(1);
        $byte = ord($char);

        return $byte;
    }
548896
protected function readStream(&$stream, &$output) {
    $content = stream_get_contents($stream);
    if (strlen(rtrim($content))) {
      foreach (preg_split('/\r?\n/', $content) as $line) {
        $output[] = $line;
      }
    }
  }
1114652
public function setOutputStream($level, $stream)
    {
        if (static::$streamsMap === null) {
            $this->resetOutputStreams();
        }
        $this->checkLevel($level);
        if (!is_resource($stream)) {
            throw new \UnexpectedValueException("Argument '\$stream' must be a writable stream resource");
        }
        static::$streamsMap[$level] = $stream;
        return $this;
    }
117254
public function compressStream($stream)
    {
        if (!is_resource($stream)) {
            throw new InvalidArgumentException('Argument is not a resource');
        }

        rewind($stream);
        $string = stream_get_contents($stream);
        fclose($stream);
        $compressedString = $this->compressString($string);
        $stream = fopen('php://memory', 'b+');
        fwrite($stream, $compressedString);
        rewind($stream);

        return $stream;
    }
1006274
public function loadBinaryStream($stream)
    {
        if (($contents = stream_get_contents($stream)) === false) {
            throw IOException::notReadable('<stream>');
        }
        $this->parse($contents, CFPropertyList::FORMAT_BINARY);
    }
171778
public void encode(InputStream inStream, OutputStream outStream)
        throws IOException {
        int     j;
        int     numBytes;
        byte    tmpbuffer[] = new byte[bytesPerLine()];

        encodeBufferPrefix(outStream);

        while (true) {
            numBytes = readFully(inStream, tmpbuffer);
            if (numBytes == 0) {
                break;
            }
            encodeLinePrefix(outStream, numBytes);
            for (j = 0; j < numBytes; j += bytesPerAtom()) {

                if ((j + bytesPerAtom()) <= numBytes) {
                    encodeAtom(outStream, tmpbuffer, j, bytesPerAtom());
                } else {
                    encodeAtom(outStream, tmpbuffer, j, (numBytes)- j);
                }
            }
            if (numBytes < bytesPerLine()) {
                break;
            } else {
                encodeLineSuffix(outStream);
            }
        }
        encodeBufferSuffix(outStream);
    }
891468
public function setInputStream($stream)
    {
        $stream = new Stream($stream ?: STDIN);
        $stream = FnStream::decorate($stream, [
            'read' => function ($length) use ($stream) {
                $ret = $stream->read($length);
                $this->onRead($ret);

                return $ret;
            },
        ]);
        $stream = StreamWrapper::getResource($stream);

        parent::setInputStream($stream);
    }
228701
public static function encode($value)
    {
        $value = gmp_init($value, 10);
        $octets = chr(gmp_strval(gmp_and($value, 0x7f), 10));

        $rightShift = function ($number, $positions) {
            return gmp_div($number, gmp_pow(2, $positions));
        };

        $value = $rightShift($value, 7);
        while (gmp_cmp($value, 0) > 0) {
            $octets .= chr(gmp_strval(gmp_or(0x80, gmp_and($value, 0x7f)), 10));
            $value = $rightShift($value, 7);
        }

        return strrev($octets);
    }
229263
public function readByteStream(Stream $stream)
    {
        $length = $this->readVarint($stream);
        $value  = $stream->readStream($length);

        return $value;
    }