Download the PHP package nelexa/buffer without Composer
On this page you can find all versions of the php package nelexa/buffer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nelexa/buffer
More information about nelexa/buffer
Files in nelexa/buffer
Package buffer
Short Description Reading And Writing Binary Data (incl. primitive types, ex. byte, ubyte, short, ushort, int, uint, long, float, double). The classes also help with porting the I/O operations of the JAVA code.
License MIT
Informations about the package buffer
nelexa/buffer
-> Read And Write Binary Data
This is classes defines methods for reading and writing values of all primitive types. Primitive values are translated to (or from) sequences of bytes according to the buffer's current byte order, which may be retrieved and modified via the order methods. The initial order of a byte buffer is always Buffer::BIG_ENDIAN.
Requirements
- PHP >= 5.4 (64 bit)
Installation
Documentation
Class \Nelexa\Buffer
is abstract and base methods for all other buffers.
Initialize buffer as string.
Initialize buffer as file.
Initialize buffer as memory resource (php://memory).
Initialize buffer as stream resource.
Set read only buffer
Checking the possibility of recording in the buffer
Modifies this buffer's byte order, either Buffer::BIG_ENDIAN
or Buffer::LITTLE_ENDIAN
Get buffer's byte order
Get buffer size.
Set buffer position.
Get buffer position.
Skip bytes.
Skip primitive type size.
Rewinds this buffer. The position is set to zero.
Flips this buffer. The limit is set to the current position and then the position is set to zero.
Returns the number of elements between the current position and the limit.
Tells whether there are any elements between the current position and the limit. True if, and only if, there is at least one element remaining in this buffer
Close buffer and release resources
Read buffer
Read the entire contents of the buffer into a string without changing the position of the buffer.
Reads the string at this buffer's current position, and then increments the position.
Read literal types
Method | Type | Values |
---|---|---|
$buffer->getBoolean |
boolean | true or false |
$buffer->getByte() |
byte | -128 ... 127 |
$buffer->getUnsignedByte() |
unsigned byte (ubyte) | 0 ... 255 |
$buffer->getShort() |
short (2 bytes) | -32768 ... 32767 |
$buffer->getUnsignedShort() |
unsigned short (ushort) | 0 ... 65535 |
$buffer->getInt() |
int (4 bytes) | -2147483648 ... 2147483647 |
$buffer->getUnsignedInt() |
unsigned int (uint) | 0 ... 4294967296 |
$buffer->getLong() |
long (8 bytes) | -9223372036854775808 ... 9223372036854775807 |
$buffer->getFloat() |
float (4 bytes) | single-precision 32-bit IEEE 754 floating point number |
$buffer->getDouble() |
double (5 bytes) | double-precision 64-bit IEEE 754 floating point number |
$buffer->getArrayBytes($length) |
byte[] | array |
$buffer->getString($length) |
string (length bytes) | string |
$buffer->getUTF() |
string | string |
$buffer->getUTF16($length) |
string (length * 2) | string |
Write to buffer
Insert bytes to buffer
Insert string (byte[]) or Buffer to buffer.
Insert primitive types
Insert boolean value false
or true
. Change size and position by +1.
Insert byte (-128 >= byte <= 127). Change size and position by +1.
Insert short value (-32768 >= short <= 32767). Change size and position by +2.
Insert integer value (-2147483648 >= int <= 2147483647). Change size and position by +4.
Insert long value (-9223372036854775808 >= long <= 9223372036854775807). Change position +8.
Insert float value (single-precision 32-bit IEEE 754 floating point number). Change position +4.
Insert double value (double-precision 64-bit IEEE 754 floating point number). Change position +8.
Insert array bytes. Change size and position by +(size array).
Insert string value. Change size and position by +(length string).
Insert UTF-8 string with encoding first two bytes as length string. Change size and position by +(2 + length string).
Analog java java.io.DataOutputStream#writeUTF(String str)
Insert string with UTF-16 encoding. Change size and position by +(2 * length string).
Put bytes to buffer
Put string (byte[]) or Buffer to buffer and overwrite old value.
Put primitive types
Put boolean value false
or true
. Change position by +1.
Put byte (-128 >= byte <= 127). Change position by +1.
Put short value (-32768 >= short <= 32767). Change position by +2.
Put integer value (-2147483648 >= int <= 2147483647). Change position by +4.
Put long value (-9223372036854775808 >= long <= 9223372036854775807). Change position by +8.
Put float value (single-precision 32-bit IEEE 754 floating point number). Change position +4.
Put double value (double-precision 64-bit IEEE 754 floating point number). Change position +8.
Put array bytes. Change position by +(size array).
Insert string value. Change position by +(length string).
Put UTF-8 string with encoding first two bytes as length string. Change position by +(2 + length string).
Analog java java.io.DataOutputStream#writeUTF(String str)
Put string with UTF-16 encoding. Change position by +(2 * length string).
Replace bytes by buffer
Replace following a certain number of bytes by string or another Buffer.
Replace by primitive types
Replace by boolean value false
or true
. Change size by (-$length + 1) and position +1.
Replace by byte (-128 >= byte <= 127). Change size by (-$length + 1) and position +1.
Replace by short value (-32768 >= short <= 32767). Change size by (-$length + 2) and position +2.
Replace by integer value (-2147483648 >= int <= 2147483647). Change size by (-$length + 4) and position +4.
Replace by long value (-9223372036854775808 >= long <= 9223372036854775807). Change size by (-$length + 8) and position +8.
Replace by float value (single-precision 32-bit IEEE 754 floating point number). Change size by (-$length + 4) and position +4.
Replace by double value (double-precision 64-bit IEEE 754 floating point number). Change size by (-$length + 8) and position +8.
Replace by array bytes. Change size by (-$length + size array) and position +(size array).
Replace by string value. Change size by (-$length + length string) and position +(length string).
Replace by UTF-8 string with encoding first two bytes as length string. Change size by (-$length + 2 + length string) and position +(2 + length string).
Analog java java.io.DataOutputStream#writeUTF(String str)
Replace by string with UTF-16 encoding. Change size by (-$length + 2 length string) and position +(2 length string).
Remove bytes by buffer
Remove a certain number of bytes. Change size by -$length.
Remove all bytes. Truncate buffer.