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)))); }
/** * 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); }