public function testGetSize() { $handle = fopen('php://temp', 'w+'); $stream = new Stream($handle); $this->assertEquals(3, fwrite($handle, 'foo')); $this->assertEquals(3, $stream->getSize()); $this->assertEquals(4, $stream->write('test', strlen('test'))); $this->assertEquals(7, $stream->getSize()); $this->assertEquals(7, $stream->getSize()); }
/** * Compute the number of bytes that would be needed to encode a stream of bytes. * * @param \Protobuf\Stream $value * * @return integer */ public function computeByteStreamSize(Stream $value) { $length = $value->getSize(); $size = $length + $this->computeVarintSize($length); return $size; }
/** * Write the given stream. * * @param \Protobuf\Stream $stream * @param \Protobuf\Stream $value * @param int $length */ public function writeStream(Stream $stream, Stream $value, $length = null) { if ($length === null) { $length = $value->getSize(); } $stream->writeStream($value, $length); }