MessagePack\BufferUnpacker::tryUnpack PHP Метод

tryUnpack() публичный Метод

public tryUnpack ( ) : array
Результат array
    public function tryUnpack()
    {
        $data = [];
        $offset = $this->offset;
        try {
            do {
                $data[] = $this->unpack();
                $offset = $this->offset;
            } while (isset($this->buffer[$this->offset]));
        } catch (InsufficientDataException $e) {
            $this->offset = $offset;
        }
        if ($this->offset) {
            $this->buffer = isset($this->buffer[$this->offset]) ? \substr($this->buffer, $this->offset) : '';
            $this->offset = 0;
        }
        return $data;
    }

Usage Example

Пример #1
0
 public function testTryUnpackTruncatesBuffer()
 {
     $this->unpacker->append("�");
     $this->assertSame([true], $this->unpacker->tryUnpack());
     try {
         $this->unpacker->unpack();
     } catch (InsufficientDataException $e) {
         $this->assertSame('Not enough data to unpack: expected 1, got 0.', $e->getMessage());
         return;
     }
     $this->fail('Buffer was not truncated.');
 }