Skip to content

Commit f9cf6d1

Browse files
committed
support read/write float and double
1 parent 78bb680 commit f9cf6d1

File tree

7 files changed

+282
-45
lines changed

7 files changed

+282
-45
lines changed

README.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
# `php-buffer` -> Read And Write Binary Data
1+
# `nelexa/buffer` -> Read And Write Binary Data
2+
3+
[![Packagist Version](https://img.shields.io/packagist/v/nelexa/buffer.svg)](https://packagist.org/packages/nelexa/buffer)
4+
[![Packagist](https://img.shields.io/packagist/dt/nelexa/buffer.svg?color=%23ff007f)](https://packagist.org/packages/nelexa/buffer)
5+
[![Build Status](https://travis-ci.org/Ne-Lexa/php-buffer.svg?branch=master)](https://travis-ci.org/Ne-Lexa/php-buffer)
6+
[![License](https://img.shields.io/packagist/l/nelexa/buffer.svg)](https://packagist.org/packages/nelexa/buffer)
27

38
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.
49

@@ -50,7 +55,7 @@ Checking the possibility of recording in the buffer
5055
$boolValue = $buffer->isReadOnly();
5156
```
5257

53-
Modifies this buffer's byte order, either Buffer::BIG_ENDIAN or Buffer::LITTLE_ENDIAN
58+
Modifies this buffer's byte order, either `Buffer::BIG_ENDIAN` or `Buffer::LITTLE_ENDIAN`
5459
```php
5560
$buffer->setOrder(\Nelexa\Buffer::LITTLE_ENDIAN);
5661
```
@@ -94,6 +99,8 @@ $buffer->skipByte(); // skip 1 byte
9499
$buffer->skipShort(); // skip 2 bytes
95100
$buffer->skipInt(); // skip 4 bytes
96101
$buffer->skipLong(); // skip 8 bytes
102+
$buffer->skipFloat(); // skip 4 bytes
103+
$buffer->skipDouble(); // skip 8 bytes
97104
```
98105

99106
Rewinds this buffer. The position is set to zero.
@@ -187,6 +194,8 @@ Method | Type | Values
187194
`$buffer->getInt()` | int (4 bytes) | -2147483648 ... 2147483647
188195
`$buffer->getUnsignedInt()` | unsigned int (uint) | 0 ... 4294967296
189196
`$buffer->getLong()` | long (8 bytes) | -9223372036854775808 ... 9223372036854775807
197+
`$buffer->getFloat()` | float (4 bytes) | single-precision 32-bit IEEE 754 floating point number
198+
`$buffer->getDouble()` | double (5 bytes) | double-precision 64-bit IEEE 754 floating point number
190199
`$buffer->getArrayBytes($length)` | byte[] | `array`
191200
`$buffer->getString($length)` | string (length bytes) | `string`
192201
`$buffer->getUTF()` | string | `string`
@@ -235,6 +244,14 @@ Insert long value (-9223372036854775808 >= long <= 9223372036854775807). Change
235244
```php
236245
$buffer->insertLong($longValue);
237246
```
247+
Insert float value (single-precision 32-bit IEEE 754 floating point number). Change position +4.
248+
```php
249+
$buffer->insertFloat($floatValue);
250+
```
251+
Insert double value (double-precision 64-bit IEEE 754 floating point number). Change position +8.
252+
```php
253+
$buffer->insertDouble($doubleValue);
254+
```
238255
Insert array bytes. Change size and position by +(size array).
239256
```php
240257
$buffer->insertArrayBytes($bytes);
@@ -293,6 +310,14 @@ Put long value (-9223372036854775808 >= long <= 9223372036854775807). Change pos
293310
```php
294311
$buffer->putLong($longValue);
295312
```
313+
Put float value (single-precision 32-bit IEEE 754 floating point number). Change position +4.
314+
```php
315+
$buffer->putFloat($floatValue);
316+
```
317+
Put double value (double-precision 64-bit IEEE 754 floating point number). Change position +8.
318+
```php
319+
$buffer->putDouble($doubleValue);
320+
```
296321
Put array bytes. Change position by +(size array).
297322
```php
298323
$buffer->putArrayBytes($bytes);
@@ -351,6 +376,14 @@ Replace by long value (-9223372036854775808 >= long <= 9223372036854775807). Cha
351376
```php
352377
$buffer->replaceLong($longValue, $length);
353378
```
379+
Replace by float value (single-precision 32-bit IEEE 754 floating point number). Change size by (-$length + 4) and position +4.
380+
```php
381+
$buffer->replaceFloat($floatValue, $length);
382+
```
383+
Replace by double value (double-precision 64-bit IEEE 754 floating point number). Change size by (-$length + 8) and position +8.
384+
```php
385+
$buffer->replaceDouble($doubleValue, $length);
386+
```
354387
Replace by array bytes. Change size by (-$length + size array) and position +(size array).
355388
```php
356389
$buffer->replaceArrayBytes($bytes, $length);

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nelexa/buffer",
3-
"description": "Reading And Writing Binary Data (incl. primitive types, ex. byte, ubyte, short, ushort, int, uint, long). The classes also help with porting the I/O operations of the JAVA code.",
3+
"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.",
44
"type": "library",
55
"keywords": [
66
"binary",
@@ -12,6 +12,8 @@
1212
"int",
1313
"uint",
1414
"long",
15+
"float",
16+
"double",
1517
"io",
1618
"java",
1719
"pack",
@@ -40,4 +42,4 @@
4042
"Nelexa\\Buffer\\": "tests/Nelexa/Buffer"
4143
}
4244
}
43-
}
45+
}

0 commit comments

Comments
 (0)