/** * Constructor * * @param Kafka_FetchRequest $req Request object */ public function __construct(Kafka_FetchRequest $req) { $this->size = $req->sizeInBytes() + 2; $this->buffer = fopen('php://temp', 'w+b'); fwrite($this->buffer, pack('n', $req->id)); $req->writeTo($this->buffer); rewind($this->buffer); //fseek($this->buffer, $req->getOffset(), SEEK_SET); }
public function testWriteCompletelyWithBigRequest() { $topicSize = 9000; $this->topic = str_repeat('a', $topicSize); //bigger than the fread buffer, 8192 $this->req = new Kafka_FetchRequest($this->topic, $this->partition, $this->offset); $this->obj = new Kafka_BoundedByteBuffer_Send($this->req); // 4 bytes = size // 2 bytes = request ID $this->assertEquals(4 + $this->req->sizeInBytes() + 2, $this->obj->writeCompletely($this->stream)); }
public function testWriteToOffset() { $this->offset = 14; $this->req = new Kafka_FetchRequest($this->topic, $this->partition, $this->offset, $this->maxSize); $stream = fopen('php://temp', 'w+b'); $this->req->writeTo($stream); rewind($stream); //read it back $topicLen = array_shift(unpack('n', fread($stream, 2))); $this->assertEquals(strlen($this->topic), $topicLen); $this->assertEquals($this->topic, fread($stream, $topicLen)); $this->assertEquals($this->partition, array_shift(unpack('N', fread($stream, 4)))); $int64bit = unpack('N2', fread($stream, 8)); $this->assertEquals($this->offset, $int64bit[2]); $this->assertEquals($this->maxSize, array_shift(unpack('N', fread($stream, 4)))); }