wrap() public static method

Wrap the input resource in a stream object.
public static wrap ( Stream | resource | string $resource = '', integer $size = null ) : Stream
$resource Stream | resource | string
$size integer
return Stream
 /**
  * Set 'encrypted_signature' value
  *
  * @param \Protobuf\Stream $value
  */
 public function setEncryptedSignature($value = null)
 {
     if ($value !== null && !$value instanceof \Protobuf\Stream) {
         $value = \Protobuf\Stream::wrap($value);
     }
     $this->encrypted_signature = $value;
 }
 public function testSimpleMessageMergeNullComparison()
 {
     $simple1 = new Simple();
     $simple2 = new Simple();
     $bytes = Stream::wrap("bar");
     $simple1->setBool(false);
     $simple1->setFloat(0.0);
     $simple1->setUint32(0);
     $simple2->merge($simple1);
     $this->assertSame(false, $simple2->getBool());
     $this->assertSame(0.0, $simple2->getFloat());
     $this->assertSame(0, $simple2->getUint32());
 }
 public function testSimpleMessageClear()
 {
     $simple = new Simple();
     $simple->setBool(true);
     $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->setBytes(Stream::wrap("bar"));
     $simple->setSfixed64(-123456789123456789);
     $this->assertSame(true, $simple->getBool());
     $this->assertSame("foo", $simple->getString());
     $this->assertSame(12345.123, $simple->getFloat());
     $this->assertSame(123456789, $simple->getUint32());
     $this->assertSame(-123456789, $simple->getInt32());
     $this->assertSame(123456789, $simple->getFixed32());
     $this->assertSame(-123456789, $simple->getSint32());
     $this->assertSame(-123456789, $simple->getSfixed32());
     $this->assertSame(123456789.12345, $simple->getDouble());
     $this->assertSame(-123456789123456789, $simple->getInt64());
     $this->assertSame(123456789123456789, $simple->getUint64());
     $this->assertSame(123456789123456789, $simple->getFixed64());
     $this->assertSame(-123456789123456789, $simple->getSint64());
     $this->assertSame(-123456789123456789, $simple->getSfixed64());
     $this->assertInstanceOf('Protobuf\\Stream', $simple->getBytes());
     $simple->clear();
     $this->assertNull($simple->getBool());
     $this->assertNull($simple->getString());
     $this->assertNull($simple->getFloat());
     $this->assertNull($simple->getUint32());
     $this->assertNull($simple->getInt32());
     $this->assertNull($simple->getFixed32());
     $this->assertNull($simple->getSint32());
     $this->assertNull($simple->getSfixed32());
     $this->assertNull($simple->getDouble());
     $this->assertNull($simple->getInt64());
     $this->assertNull($simple->getUint64());
     $this->assertNull($simple->getFixed64());
     $this->assertNull($simple->getSint64());
     $this->assertNull($simple->getSfixed64());
     $this->assertNull($simple->getBytes());
 }
 public function testGenerateSimpleMessage()
 {
     $binaryRequest = $this->getFixtureFileContent('compiler/generator-request-simple.bin');
     $expectedContent = $this->getFixtureFileContent('Simple.tpl');
     $compiler = new Compiler($this->logger);
     $binaryResponse = $compiler->compile(Stream::wrap($binaryRequest));
     $response = CodeGeneratorResponse::fromStream($binaryResponse);
     $this->assertInstanceOf('google\\protobuf\\compiler\\CodeGeneratorResponse', $response);
     $this->assertInstanceOf('Protobuf\\Collection', $response->getFileList());
     $this->assertCount(1, $response->getFileList());
     $file = $response->getFileList()[0];
     $this->assertInstanceOf('google\\protobuf\\compiler\\CodeGeneratorResponse\\File', $file);
     $this->assertEquals('ProtobufCompilerTest/Protos/Simple.php', $file->getName());
     $this->assertEquals($expectedContent, $file->getContent());
 }
 public function testWriteSimpleMessage()
 {
     $stream = Stream::create();
     $writer = new StreamWriter($this->config);
     $binary = $this->getProtoContent('simple.bin');
     $writer->writeVarint($stream, WireFormat::getFieldKey(1, WireFormat::WIRE_FIXED64));
     $writer->writeDouble($stream, 123456789.12345);
     $writer->writeVarint($stream, WireFormat::getFieldKey(2, WireFormat::WIRE_FIXED32));
     $writer->writeFloat($stream, 12345.123046875);
     $writer->writeVarint($stream, WireFormat::getFieldKey(3, WireFormat::WIRE_VARINT));
     $writer->writeVarint($stream, -123456789123456789);
     $writer->writeVarint($stream, WireFormat::getFieldKey(4, WireFormat::WIRE_VARINT));
     $writer->writeVarint($stream, 123456789123456789);
     $writer->writeVarint($stream, WireFormat::getFieldKey(5, WireFormat::WIRE_VARINT));
     $writer->writeVarint($stream, -123456789);
     $writer->writeVarint($stream, WireFormat::getFieldKey(6, WireFormat::WIRE_FIXED64));
     $writer->writeFixed64($stream, 123456789123456789);
     $writer->writeVarint($stream, WireFormat::getFieldKey(7, WireFormat::WIRE_FIXED32));
     $writer->writeFixed32($stream, 123456789);
     $writer->writeVarint($stream, WireFormat::getFieldKey(8, WireFormat::WIRE_VARINT));
     $writer->writeVarint($stream, 1);
     $writer->writeVarint($stream, WireFormat::getFieldKey(9, WireFormat::WIRE_LENGTH));
     $writer->writeString($stream, 'foo');
     $writer->writeVarint($stream, WireFormat::getFieldKey(12, WireFormat::WIRE_LENGTH));
     $writer->writeByteStream($stream, Stream::wrap('bar'));
     $writer->writeVarint($stream, WireFormat::getFieldKey(13, WireFormat::WIRE_VARINT));
     $writer->writeVarint($stream, 123456789);
     $writer->writeVarint($stream, WireFormat::getFieldKey(15, WireFormat::WIRE_FIXED32));
     $writer->writeSFixed32($stream, -123456789);
     $writer->writeVarint($stream, WireFormat::getFieldKey(16, WireFormat::WIRE_FIXED64));
     $writer->writeSFixed64($stream, -123456789123456789);
     $writer->writeVarint($stream, WireFormat::getFieldKey(17, WireFormat::WIRE_VARINT));
     $writer->writeZigzag($stream, -123456789, 32);
     $writer->writeVarint($stream, WireFormat::getFieldKey(18, WireFormat::WIRE_VARINT));
     $writer->writeZigzag($stream, -123456789123456789, 64);
     $this->assertEquals($binary, (string) $stream);
 }
 public function testReadSimpleMessage()
 {
     $stream = Stream::wrap($this->getProtoContent('simple.bin'));
     $reader = new StreamReader($this->config);
     $this->assertNextTagWire($reader, $stream, 1, WireFormat::WIRE_FIXED64);
     $this->assertEquals(123456789.12345, $reader->readDouble($stream));
     $this->assertNextTagWire($reader, $stream, 2, WireFormat::WIRE_FIXED32);
     $this->assertEquals(12345.123046875, $reader->readFloat($stream));
     $this->assertNextTagWire($reader, $stream, 3, WireFormat::WIRE_VARINT);
     $this->assertEquals(-123456789123456789, $reader->readVarint($stream));
     $this->assertNextTagWire($reader, $stream, 4, WireFormat::WIRE_VARINT);
     $this->assertEquals(123456789123456789, $reader->readVarint($stream));
     $this->assertNextTagWire($reader, $stream, 5, WireFormat::WIRE_VARINT);
     $this->assertEquals(-123456789, $reader->readVarint($stream));
     $this->assertNextTagWire($reader, $stream, 6, WireFormat::WIRE_FIXED64);
     $this->assertEquals(123456789123456789, $reader->readFixed64($stream));
     $this->assertNextTagWire($reader, $stream, 7, WireFormat::WIRE_FIXED32);
     $this->assertEquals(123456789, $reader->readFixed32($stream));
     $this->assertNextTagWire($reader, $stream, 8, WireFormat::WIRE_VARINT);
     $this->assertEquals(true, $reader->readBool($stream));
     $this->assertNextTagWire($reader, $stream, 9, WireFormat::WIRE_LENGTH);
     $this->assertEquals('foo', $reader->readString($stream));
     $this->assertNextTagWire($reader, $stream, 12, WireFormat::WIRE_LENGTH);
     $this->assertInstanceOf('Protobuf\\Stream', $byteStream = $reader->readByteStream($stream));
     $this->assertEquals('bar', (string) $byteStream);
     $this->assertNextTagWire($reader, $stream, 13, WireFormat::WIRE_VARINT);
     $this->assertEquals(123456789, $reader->readVarint($stream));
     $this->assertNextTagWire($reader, $stream, 15, WireFormat::WIRE_FIXED32);
     $this->assertEquals(-123456789, $reader->readSFixed32($stream));
     $this->assertNextTagWire($reader, $stream, 16, WireFormat::WIRE_FIXED64);
     $this->assertEquals(-123456789123456789, $reader->readSFixed64($stream));
     $this->assertNextTagWire($reader, $stream, 17, WireFormat::WIRE_VARINT);
     $this->assertEquals(-123456789, $reader->readZigzag($stream));
     $this->assertNextTagWire($reader, $stream, 18, WireFormat::WIRE_VARINT);
     $this->assertEquals(-123456789123456789, $reader->readZigzag($stream));
 }
 public function testUnknownFieldSet()
 {
     $binary = $this->getProtoContent('unknown.bin');
     $unrecognized = Unrecognized::fromStream(Stream::wrap($binary));
     $this->assertInstanceOf(Unrecognized::CLASS, $unrecognized);
     $this->assertInstanceOf('Protobuf\\UnknownFieldSet', $unrecognized->unknownFieldSet());
     $this->assertCount(15, $unrecognized->unknownFieldSet());
     $values = $unrecognized->unknownFieldSet();
     $this->assertInstanceOf('Protobuf\\Unknown', $values[1]);
     $this->assertInstanceOf('Protobuf\\Unknown', $values[2]);
     $this->assertInstanceOf('Protobuf\\Unknown', $values[3]);
     $this->assertInstanceOf('Protobuf\\Unknown', $values[4]);
     $this->assertInstanceOf('Protobuf\\Unknown', $values[5]);
     $this->assertInstanceOf('Protobuf\\Unknown', $values[6]);
     $this->assertInstanceOf('Protobuf\\Unknown', $values[7]);
     $this->assertInstanceOf('Protobuf\\Unknown', $values[8]);
     $this->assertInstanceOf('Protobuf\\Unknown', $values[9]);
     $this->assertInstanceOf('Protobuf\\Unknown', $values[12]);
     $this->assertInstanceOf('Protobuf\\Unknown', $values[13]);
     $this->assertInstanceOf('Protobuf\\Unknown', $values[15]);
     $this->assertInstanceOf('Protobuf\\Unknown', $values[16]);
     $this->assertInstanceOf('Protobuf\\Unknown', $values[17]);
     $this->assertInstanceOf('Protobuf\\Unknown', $values[18]);
     $this->assertEquals(4728057454355442093, $values[1]->value);
     $this->assertEquals(1178657918, $values[2]->value);
     $this->assertEquals(-123456789123456789, $values[3]->value);
     $this->assertEquals(123456789123456789, $values[4]->value);
     $this->assertEquals(-123456789, $values[5]->value);
     $this->assertEquals(123456789123456789, $values[6]->value);
     $this->assertEquals(123456789, $values[7]->value);
     $this->assertEquals(1, $values[8]->value);
     $this->assertEquals("foo", $values[9]->value);
     $this->assertEquals("bar", $values[12]->value);
     $this->assertEquals(123456789, $values[13]->value);
     $this->assertEquals(4171510507, $values[15]->value);
     $this->assertEquals(-123456789123456789, $values[16]->value);
     $this->assertEquals(246913577, $values[17]->value);
     $this->assertEquals(246913578246913577, $values[18]->value);
 }
 /**
  * Set 'status' value
  *
  * @param \Protobuf\Stream $value
  */
 public function setStatus($value = null)
 {
     if ($value !== null && !$value instanceof \Protobuf\Stream) {
         $value = \Protobuf\Stream::wrap($value);
     }
     $this->status = $value;
 }
示例#9
0
 /**
  * Set 'session_hash' value
  *
  * @param \Protobuf\Stream $value
  */
 public function setSessionHash($value = null)
 {
     if ($value !== null && !$value instanceof \Protobuf\Stream) {
         $value = \Protobuf\Stream::wrap($value);
     }
     $this->session_hash = $value;
 }
示例#10
0
 /**
  * Set 'request_message' value
  *
  * @param \Protobuf\Stream $value
  */
 public function setRequestMessage($value = null)
 {
     if ($value !== null && !$value instanceof \Protobuf\Stream) {
         $value = \Protobuf\Stream::wrap($value);
     }
     $this->request_message = $value;
 }
 public function testEncodeAndDecodeNestedMessageComparingWithProtoc()
 {
     $proto = 'complex';
     $complex = new Complex();
     $nested = new Complex\Nested();
     $input = 'nested { foo: "FOO" }';
     $class = 'ProtobufTest.Protos.Complex';
     $nested->setFoo('FOO');
     $complex->setNested($nested);
     $encoded = $complex->toStream();
     $expected = $this->executeProtoc($input, $class, $proto);
     $decoded = Complex::fromStream(Stream::wrap($expected));
     $this->assertInstanceOf(Complex::CLASS, $decoded);
     $this->assertInstanceOf(Complex\Nested::CLASS, $complex->getNested());
     $this->assertEquals(bin2hex($encoded), bin2hex($expected));
     $this->assertEquals($complex->getNested()->getFoo(), 'FOO');
 }
 /**
  * Set 'response' value
  *
  * @param \Protobuf\Stream $value
  */
 public function setResponse($value = null)
 {
     if ($value !== null && !$value instanceof \Protobuf\Stream) {
         $value = \Protobuf\Stream::wrap($value);
     }
     $this->response = $value;
 }
 /**
  * Add a new element to 'returns'
  *
  * @param \Protobuf\Stream $value
  */
 public function addReturns($value)
 {
     if ($this->returns === null) {
         $this->returns = new \Protobuf\StreamCollection();
     }
     $this->returns->add(\Protobuf\Stream::wrap($value));
 }
示例#14
0
 public function testCanSetSize()
 {
     $this->assertEquals(10, Stream::wrap('', 10)->getSize());
 }