22declare(strict_types=1);
39 public function __construct(
string $buffer =
"",
int $offset = 0){
40 $this->buffer = $buffer;
41 $this->offset = $offset;
51 public function setOffset(
int $offset) : void{
52 $this->offset = $offset;
55 public function getOffset() : int{
59 public function getBuffer() : string{
67 public function get(
int $len) :
string{
72 throw new \InvalidArgumentException(
"Length must be positive");
75 $remaining = strlen($this->buffer) - $this->offset;
76 if($remaining < $len){
77 throw new BinaryDataException(
"Not enough bytes left in buffer: need $len, have $remaining");
80 return $len === 1 ? $this->buffer[$this->offset++] : substr($this->buffer, ($this->offset += $len) - $len, $len);
88 $buflen = strlen($this->buffer);
89 if($this->offset >= $buflen){
92 $str = substr($this->buffer, $this->offset);
93 $this->offset = $buflen;
97 public function put(
string $str) : void{
98 $this->buffer .= $str;
106 return $this->get(1) !==
"\x00";
109 public function putBool(
bool $v) : void{
110 $this->buffer .= ($v ?
"\x01" :
"\x00");
118 return ord($this->get(1));
121 public function putByte(
int $v) : void{
122 $this->buffer .= chr($v);
130 return
Binary::readShort($this->get(2));
138 return
Binary::readSignedShort($this->get(2));
141 public function putShort(
int $v) : void{
142 $this->buffer .=
Binary::writeShort($v);
150 return
Binary::readLShort($this->get(2));
158 return
Binary::readSignedLShort($this->get(2));
161 public function putLShort(
int $v) : void{
162 $this->buffer .=
Binary::writeLShort($v);
170 return
Binary::readTriad($this->get(3));
173 public function putTriad(
int $v) : void{
174 $this->buffer .=
Binary::writeTriad($v);
182 return
Binary::readLTriad($this->get(3));
185 public function putLTriad(
int $v) : void{
186 $this->buffer .=
Binary::writeLTriad($v);
194 return
Binary::readInt($this->get(4));
197 public function putInt(
int $v) : void{
198 $this->buffer .=
Binary::writeInt($v);
206 return
Binary::readLInt($this->get(4));
209 public function putLInt(
int $v) : void{
210 $this->buffer .=
Binary::writeLInt($v);
218 return
Binary::readFloat($this->get(4));
226 return
Binary::readRoundedFloat($this->get(4), $accuracy);
229 public function putFloat(
float $v) : void{
230 $this->buffer .=
Binary::writeFloat($v);
238 return
Binary::readLFloat($this->get(4));
246 return
Binary::readRoundedLFloat($this->get(4), $accuracy);
249 public function putLFloat(
float $v) : void{
250 $this->buffer .=
Binary::writeLFloat($v);
258 return
Binary::readDouble($this->get(8));
261 public function putDouble(
float $v) : void{
262 $this->buffer .=
Binary::writeDouble($v);
270 return
Binary::readLDouble($this->get(8));
273 public function putLDouble(
float $v) : void{
274 $this->buffer .=
Binary::writeLDouble($v);
282 return
Binary::readLong($this->get(8));
285 public function putLong(
int $v) : void{
286 $this->buffer .=
Binary::writeLong($v);
294 return
Binary::readLLong($this->get(8));
297 public function putLLong(
int $v) : void{
298 $this->buffer .=
Binary::writeLLong($v);
308 return
Binary::readUnsignedVarInt($this->buffer, $this->offset);
315 $this->put(
Binary::writeUnsignedVarInt($v));
325 return
Binary::readVarInt($this->buffer, $this->offset);
332 $this->put(
Binary::writeVarInt($v));
342 return
Binary::readUnsignedVarLong($this->buffer, $this->offset);
349 $this->buffer .=
Binary::writeUnsignedVarLong($v);
359 return
Binary::readVarLong($this->buffer, $this->offset);
366 $this->buffer .=
Binary::writeVarLong($v);
373 return !isset($this->buffer[$this->offset]);
getRoundedLFloat(int $accuracy)
putUnsignedVarLong(int $v)
putUnsignedVarInt(int $v)
getRoundedFloat(int $accuracy)