DiscordPHP-Voice Documentation

Buffer extends AbstractBuffer
in package
implements ArrayAccess uses BufferArrayAccessTrait

Helper class for handling binary data.

Tags
author

alexandre433

throws
InvalidArgumentException

If invalid arguments are provided or buffer overflows.

Table of Contents

Interfaces

ArrayAccess

Properties

$buffer  : SplFixedArray

Methods

__construct()  : mixed
__toString()  : string
getLastEmptyPosition()  : int
length()  : int
make()  : static
Convenience factory equivalent to `new static($argument)`.
offsetExists()  : bool
Checks if an attribute exists via key. Used for \ArrayAccess.
offsetGet()  : mixed
Gets an attribute via key. Used for \ArrayAccess.
offsetSet()  : void
Sets an attribute via key. Used for \ArrayAccess.
offsetUnset()  : void
Unsets an attribute via key. Used for \ArrayAccess.
read()  : string
Reads a string from the buffer at the specified offset.
readChar()  : string
Reads a signed char.
readInt()  : int
Reads a signed integer.
readInt16BE()  : int
Reads an unsigned 16-bit big-endian integer at `$offset`.
readInt16LE()  : int
Reads an unsigned 16-bit little-endian integer at `$offset`.
readInt32BE()  : int
Reads an unsigned 32-bit big-endian integer at `$offset`.
readInt32LE()  : int
Reads an unsigned 32-bit little-endian integer at `$offset`.
readInt8()  : int
Reads an unsigned 8-bit integer at `$offset`.
readShort()  : int
Reads an unsigned big endian short.
readUChar()  : string
Reads an unsigned char.
readUInt()  : int
Reads a signed integer.
readUIntLE()  : int
Reads a unsigned integer with little endian.
write()  : static
Writes a string to the buffer at the specified offset.
writeChar()  : self
Writes a char.
writeInt()  : self
Writes a signed integer.
writeInt16BE()  : static
Writes a 16-bit signed integer to the buffer at the specified offset.
writeInt16LE()  : static
Writes a 16-bit signed integer to the buffer at the specified offset.
writeInt32BE()  : static
Writes a 32-bit signed integer to the buffer at the specified offset.
writeInt32LE()  : static
Writes a 32-bit signed integer to the buffer at the specified offset.
writeInt8()  : static
Writes an 8-bit signed integer to the buffer at the specified offset.
writeRaw()  : void
Writes raw binary to the buffer.
writeRawString()  : void
Writes a binary string to the buffer.
writeShort()  : self
Writes an unsigned big endian short.
writeUInt()  : self
Writes an unsigned 32-bit integer in big-endian byte order so that {@see self::readUInt()} round-trips the same value.
writeUInt32BE()  : self
Writes a 32-bit unsigned integer with big endian.
writeUInt64LE()  : self
Writes a 64-bit unsigned integer with little endian.
checkForOverSize()  : static
Checks if the actual value exceeds the expected maximum size.
extract()  : mixed
Extracts a value from the buffer at the specified offset.
initializeStructs()  : void
Allocates the backing {@see \SplFixedArray} of `$length` bytes and copies `$content` into it.
insert()  : Buffer
Inserts a value into the buffer at the specified offset.

Properties

$buffer

protected SplFixedArray $buffer

Methods

__construct()

public __construct(string|int $argument) : mixed
Parameters
$argument : string|int

A binary string to wrap, or a non-negative integer size to zero-fill.

Tags
throws
OutOfRangeException

When an integer size is negative.

InvalidArgumentException

When the argument is neither a string nor an integer.

__toString()

public __toString() : string
Return values
string —

The buffer's bytes as a raw binary string.

getLastEmptyPosition()

public getLastEmptyPosition() : int
Tags
inheritDoc
Return values
int —

The offset of the first empty (unwritten) byte.

length()

public length() : int
Tags
inheritDoc
Return values
int —

The buffer's length in bytes.

make()

Convenience factory equivalent to `new static($argument)`.

public static make(string|int $argument) : static
Parameters
$argument : string|int
Return values
static

offsetExists()

Checks if an attribute exists via key. Used for \ArrayAccess.

public offsetExists(mixed $key) : bool
Parameters
$key : mixed

The attribute key.

Return values
bool —

Whether the offset exists.

offsetGet()

Gets an attribute via key. Used for \ArrayAccess.

public offsetGet(mixed $key) : mixed
Parameters
$key : mixed

The attribute key.

Attributes
#[ReturnTypeWillChange]

offsetSet()

Sets an attribute via key. Used for \ArrayAccess.

public offsetSet(mixed $key, mixed $value) : void
Parameters
$key : mixed

The attribute key.

$value : mixed

The attribute value.

offsetUnset()

Unsets an attribute via key. Used for \ArrayAccess.

public offsetUnset(string $key) : void
Parameters
$key : string

The attribute key.

read()

Reads a string from the buffer at the specified offset.

public read(int $offset, int $length) : string
Parameters
$offset : int

The offset to read from.

$length : int

The length of the string to read.

Tags
todo

Next major release: declare the native return type string. Not before, because Buffer is not final and a subclass overriding this without a return type would fail to load.

Return values
string —

The data read.

readChar()

Reads a signed char.

public readChar(int $offset) : string
Parameters
$offset : int

The offset to read from.

Return values
string —

The byte read.

readInt()

Reads a signed integer.

public readInt(int $offset) : int
Parameters
$offset : int

The offset to read from.

Return values
int —

The data read.

readInt16BE()

Reads an unsigned 16-bit big-endian integer at `$offset`.

public readInt16BE(int $offset) : int
Parameters
$offset : int
Tags
inheritDoc
todo

Next major release: declare the native return type int. Not before, because Buffer is not final and a subclass overriding this without a return type would fail to load.

Return values
int

readInt16LE()

Reads an unsigned 16-bit little-endian integer at `$offset`.

public readInt16LE(int $offset) : int
Parameters
$offset : int
Tags
inheritDoc
todo

Next major release: declare the native return type int. Not before, because Buffer is not final and a subclass overriding this without a return type would fail to load.

Return values
int

readInt32BE()

Reads an unsigned 32-bit big-endian integer at `$offset`.

public readInt32BE(int $offset) : int
Parameters
$offset : int
Tags
inheritDoc
todo

Next major release: declare the native return type int|float. On 32-bit PHP, a value above PHP_INT_MAX comes back as a float, so int alone would not hold on every path. Not before, because Buffer is not final and a subclass overriding this without a return type would fail to load.

Return values
int

readInt32LE()

Reads an unsigned 32-bit little-endian integer at `$offset`.

public readInt32LE(int $offset) : int
Parameters
$offset : int
Tags
inheritDoc
todo

Next major release: declare the native return type int|float. On 32-bit PHP, a value above PHP_INT_MAX comes back as a float, so int alone would not hold on every path. Not before, because Buffer is not final and a subclass overriding this without a return type would fail to load.

Return values
int

readInt8()

Reads an unsigned 8-bit integer at `$offset`.

public readInt8(int $offset) : int
Parameters
$offset : int
Tags
inheritDoc
todo

Next major release: declare the native return type int. Not before, because Buffer is not final and a subclass overriding this without a return type would fail to load.

Return values
int

readShort()

Reads an unsigned big endian short.

public readShort(int $offset) : int
Parameters
$offset : int

The offset to read from.

Return values
int —

The data read.

readUChar()

Reads an unsigned char.

public readUChar(int $offset) : string
Parameters
$offset : int

The offset to read from.

Return values
string —

The byte read.

readUInt()

Reads a signed integer.

public readUInt(int $offset) : int
Parameters
$offset : int

The offset to read from.

Return values
int —

The data read.

readUIntLE()

Reads a unsigned integer with little endian.

public readUIntLE(int $offset) : int
Parameters
$offset : int

The offset that will be read.

Return values
int —

The value that is at the specified offset.

write()

Writes a string to the buffer at the specified offset.

public write(string $value[, int|null $offset = null ]) : static
Parameters
$value : string

The value that will be written.

$offset : int|null = null

The offset that the value will be written at.

Tags
todo

Next major release: narrow the native return type from self to static; it already returns $this. Not before, because Buffer is not final and a subclass overriding this with : self would fail to load.

Return values
static

writeChar()

Writes a char.

public writeChar(string $value, int $offset) : self
Parameters
$value : string

The value that will be written.

$offset : int

The offset that the value will be written.

Return values
self

writeInt()

Writes a signed integer.

public writeInt(int $value, int $offset) : self
Parameters
$value : int

The value that will be written.

$offset : int

The offset that the value will be written.

Return values
self

writeInt16BE()

Writes a 16-bit signed integer to the buffer at the specified offset.

public writeInt16BE(int $value[, int|null $offset = null ]) : static
Parameters
$value : int

The value that will be written.

$offset : int|null = null

The offset that the value will be written at.

Tags
todo

Next major release: narrow the native return type from self to static; it already returns $this. Not before, because Buffer is not final and a subclass overriding this with : self would fail to load.

Return values
static

writeInt16LE()

Writes a 16-bit signed integer to the buffer at the specified offset.

public writeInt16LE(int $value[, int|null $offset = null ]) : static
Parameters
$value : int

The value that will be written.

$offset : int|null = null

The offset that the value will be written at.

Tags
todo

Next major release: narrow the native return type from self to static; it already returns $this. Not before, because Buffer is not final and a subclass overriding this with : self would fail to load.

Return values
static

writeInt32BE()

Writes a 32-bit signed integer to the buffer at the specified offset.

public writeInt32BE(int $value[, int|null $offset = null ]) : static
Parameters
$value : int

The value that will be written.

$offset : int|null = null

The offset that the value will be written at.

Tags
todo

Next major release: narrow the native return type from self to static; it already returns $this. Not before, because Buffer is not final and a subclass overriding this with : self would fail to load.

Return values
static

writeInt32LE()

Writes a 32-bit signed integer to the buffer at the specified offset.

public writeInt32LE(int $value[, int|null $offset = null ]) : static
Parameters
$value : int

The value that will be written.

$offset : int|null = null

The offset that the value will be written at.

Tags
todo

Next major release: narrow the native return type from self to static; it already returns $this. Not before, because Buffer is not final and a subclass overriding this with : self would fail to load.

Attributes
#[Override]
Return values
static

writeInt8()

Writes an 8-bit signed integer to the buffer at the specified offset.

public writeInt8(int $value[, int|null $offset = null ]) : static
Parameters
$value : int

The value that will be written.

$offset : int|null = null

The offset that the value will be written at.

Tags
todo

Next major release: narrow the native return type from self to static; it already returns $this. Not before, because Buffer is not final and a subclass overriding this with : self would fail to load.

Return values
static

writeRaw()

Writes raw binary to the buffer.

public writeRaw(int $value, int $offset) : void
Parameters
$value : int

The value that will be written.

$offset : int

The offset that the value will be written at.

writeRawString()

Writes a binary string to the buffer.

public writeRawString(string $value, int $offset) : void
Parameters
$value : string

The value that will be written.

$offset : int

The offset that the value will be written at.

writeShort()

Writes an unsigned big endian short.

public writeShort(int $value, int $offset) : self
Parameters
$value : int

The value that will be written.

$offset : int

The offset that the value will be written.

Return values
self

writeUInt()

Writes an unsigned 32-bit integer in big-endian byte order so that {@see self::readUInt()} round-trips the same value.

public writeUInt(int $value, int $offset) : self
Parameters
$value : int

The value that will be written.

$offset : int

The offset that the value will be written.

Return values
self

writeUInt32BE()

Writes a 32-bit unsigned integer with big endian.

public writeUInt32BE(int $value, int $offset) : self
Parameters
$value : int

The value that will be written.

$offset : int

The offset that the value will be written.

Return values
self

writeUInt64LE()

Writes a 64-bit unsigned integer with little endian.

public writeUInt64LE(int $value, int $offset) : self
Parameters
$value : int

The value that will be written.

$offset : int

The offset that the value will be written.

Return values
self

checkForOverSize()

Checks if the actual value exceeds the expected maximum size.

protected checkForOverSize(mixed $expectedMax, mixed $actual) : static
Parameters
$expectedMax : mixed
$actual : mixed
Tags
throws
InvalidArgumentException
Return values
static

extract()

Extracts a value from the buffer at the specified offset.

protected extract(FormatPackEnum|string $format, int $offset, int $length) : mixed
Parameters
$format : FormatPackEnum|string
$offset : int
$length : int

initializeStructs()

Allocates the backing {@see \SplFixedArray} of `$length` bytes and copies `$content` into it.

protected initializeStructs(int $length, string $content) : void
Parameters
$length : int
$content : string

insert()

Inserts a value into the buffer at the specified offset.

protected insert(FormatPackEnum|string $format, mixed $value, int $offset[, int|null $length = null ]) : Buffer
Parameters
$format : FormatPackEnum|string
$value : mixed
$offset : int
$length : int|null = null
Return values
Buffer
On this page

Search results