Skip to content

Commit

Permalink
#12 - Rewind stream before writing
Browse files Browse the repository at this point in the history
  • Loading branch information
FabioBatSilva committed Sep 21, 2016
1 parent 29c66d2 commit c0da95f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Binary/StreamWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ public function writeByteStream(Stream $stream, Stream $value)
{
$length = $value->getSize();

$value->seek(0);
$this->writeVarint($stream, $length);
$stream->writeStream($value, $length);
}
Expand Down
28 changes: 28 additions & 0 deletions tests/SerializeMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,34 @@ public function testWriteSimpleMessage()
$this->assertSerializedMessageSize($expected, $simple);
}

public function testWriteSimpleMessageTwice()
{
$simple = new Simple();

$simple->setBool(true);
$simple->setBytes("bar");
$simple->setString("foo");
$simple->setFloat(12345.123);
$simple->setUint32(123456789);
$simple->setInt32(-123456789);
$simple->setFixed32(123456789);
$simple->setSint32(-123456789);
$simple->setSfixed32(-123456789);
$simple->setDouble(123456789.12345);
$simple->setInt64(-123456789123456789);
$simple->setUint64(123456789123456789);
$simple->setFixed64(123456789123456789);
$simple->setSint64(-123456789123456789);
$simple->setSfixed64(-123456789123456789);

$expected = $this->getProtoContent('simple.bin');
$actual1 = $simple->toStream();
$actual2 = $simple->toStream();

$this->assertEquals($expected, (string) $actual1);
$this->assertEquals($expected, (string) $actual2);
}

public function testWriteRepeatedString()
{
$repeated = new Repeated();
Expand Down

0 comments on commit c0da95f

Please sign in to comment.