-
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
471 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# Module core:bit_converter | ||
|
||
## Converting values to bytes and back | ||
|
||
```lua | ||
function bit_converter.string_to_bytes(string: str) -> table | ||
``` | ||
Converts a string to bytes | ||
|
||
```lua | ||
function bit_converter.bool_to_byte(boolean: bool) -> integer | ||
``` | ||
Converts a boolean to a byte | ||
|
||
```lua | ||
function bit_converter.single_to_bytes(number: single) -> table | ||
``` | ||
Converts a single precision float value to bytes | ||
|
||
```lua | ||
function bit_converter.double_to_bytes(number: double) -> table | ||
``` | ||
Converts a double precision float value to bytes | ||
|
||
```lua | ||
function bit_converter.uint16_to_bytes(integer: int) -> table | ||
``` | ||
Converts an unsigned 2-bytes integer to bytes | ||
|
||
```lua | ||
function bit_converter.uint32_to_bytes(integer: int) -> table | ||
``` | ||
Converts an unsigned 4-bytes integer to bytes | ||
|
||
```lua | ||
function bit_converter.int16_to_bytes(integer: int) -> table | ||
``` | ||
Converts a signed 2-bytes integer to bytes | ||
|
||
```lua | ||
function bit_converter.int32_to_bytes(integer: int) -> table | ||
``` | ||
Converts a signed 4-bytes integer to bytes | ||
|
||
```lua | ||
function bit_converter.int64_to_bytes(integer: int) -> table | ||
``` | ||
Converts a signed 8-bytes integer to bytes | ||
|
||
```lua | ||
function bit_converter.bytes_to_string(table: bytes) -> string | ||
``` | ||
Converts a byte array to a string | ||
|
||
```lua | ||
function bit_converter.byte_to_bool(integer: byte) -> boolean | ||
``` | ||
Converts a byte to a boolean value | ||
|
||
```lua | ||
function bit_converter.bytes_to_single(table: bytes) -> number№ | ||
``` | ||
Converts a byte array to a single-precision float | ||
|
||
```lua | ||
function bit_converter.bytes_to_double(table: bytes) -> number | ||
``` | ||
Converts a byte array to a double precision float | ||
|
||
```lua | ||
function bit_converter.bytes_to_uint16(table: bytes) -> integer | ||
``` | ||
Converts a byte array to a 2-bytes unsigned number | ||
|
||
```lua | ||
function bit_converter.bytes_to_uint32(table: bytes) -> integer | ||
``` | ||
Converts a byte array to a 4-bytes unsigned number | ||
|
||
```lua | ||
function bit_converter.bytes_to_int16(table: bytes) -> integer | ||
``` | ||
Converts a byte array to a 2-bytes signed number | ||
|
||
```lua | ||
function bit_converter.bytes_to_int32(table: bytes) -> integer | ||
``` | ||
Converts a byte array to a 4-bytes signed number | ||
|
||
```lua | ||
function bit_converter.bytes_to_int64(table: bytes) -> integer | ||
``` | ||
Converts a byte array to an 8-bytes signed number |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
# Module core:data_buffer | ||
|
||
## Data buffer | ||
### Stores an array of bytes and allows you to easily get or add different values | ||
|
||
```lua | ||
function data_buffer(bytes) | ||
``` | ||
Creates a new data_buffer instance (the bytes parameter is optional) | ||
|
||
```lua | ||
function data_buffer:put_byte(integer: byte) | ||
``` | ||
Writes a byte to the buffer | ||
|
||
```lua | ||
function data_buffer:put_bytes(table: bytes) | ||
``` | ||
Writes bytes to the buffer | ||
|
||
```lua | ||
function data_buffer:put_string(string: str) | ||
``` | ||
Converts a string to bytes and writes them to the buffer | ||
|
||
```lua | ||
function data_buffer:put_bool(boolean: bool) | ||
``` | ||
Converts a boolean value to a byte and writes it to the buffer | ||
|
||
```lua | ||
function data_buffer:put_single(number: single) | ||
``` | ||
Converts a single precision float to bytes and writes them to the buffer | ||
|
||
```lua | ||
function data_buffer:put_double(number: double) | ||
``` | ||
Converts a double precision float to bytes and writes them to the buffer | ||
|
||
```lua | ||
function data_buffer:put_uint16(integer: int) | ||
``` | ||
Converts an unsigned 2-bytes number to bytes and writes them to the buffer | ||
|
||
```lua | ||
function data_buffer:put_uint32(integer: int) | ||
``` | ||
Converts an unsigned 4-bytes number to bytes and writes them to the buffer | ||
|
||
```lua | ||
function data_buffer:put_int16(integer: int) | ||
``` | ||
Converts a signed 2-bytes number into bytes and writes them to the buffer | ||
|
||
```lua | ||
function data_buffer:put_int32(integer: int) | ||
``` | ||
Converts a signed 4-bytes number into bytes and writes them to the buffer | ||
|
||
```lua | ||
function data_buffer:put_int64(integer: int) | ||
``` | ||
Converts a signed 8-bytes number to bytes and writes them to the buffer | ||
|
||
```lua | ||
function data_buffer:put_number(number: num) | ||
``` | ||
Converts any number into bytes and writes them to the buffer; | ||
|
||
The first byte is the value type: | ||
```lua | ||
zero = 0 | ||
uint16 = 1 | ||
uint32 = 2 | ||
int16 = 3 | ||
int32 = 4 | ||
int64 = 5 | ||
double = 6 | ||
``` | ||
|
||
```lua | ||
function data_buffer:get_byte() -> integer | ||
``` | ||
Returns the next byte from the buffer | ||
|
||
```lua | ||
function data_buffer:get_bytes(n) -> table | ||
``` | ||
Returns the next n bytes, if n is nil or not specified, then an array of all bytes is returned | ||
|
||
```lua | ||
function data_buffer:get_string() -> string | ||
``` | ||
Reads the next line from the buffer | ||
|
||
```lua | ||
function data_buffer:get_bool() -> boolean | ||
``` | ||
Reads the next Boolean from the buffer | ||
|
||
```lua | ||
function data_buffer:get_single() -> number | ||
``` | ||
Reads the next single precision floating number from the buffer | ||
|
||
```lua | ||
function data_buffer:get_double() -> number | ||
``` | ||
Reads the next double precision floating number from the buffer | ||
|
||
```lua | ||
function data_buffer:get_uint16() -> integer | ||
``` | ||
Reads the next 2-bytes unsigned integer from the buffer | ||
|
||
```lua | ||
function data_buffer:get_uint32() -> integer | ||
``` | ||
Reads the next 4-bytes unsigned integer from the buffer | ||
|
||
```lua | ||
function data_buffer:get_int16() -> integer | ||
``` | ||
Reads the next 2-bytes signed integer from the buffer | ||
|
||
```lua | ||
function data_buffer:get_int32() -> integer | ||
``` | ||
Reads the next 4-bytes signed integer from the buffer | ||
|
||
```lua | ||
function data_buffer:get_int64() -> integer | ||
``` | ||
Reads the next 8-bytes signed integer from the buffer | ||
|
||
```lua | ||
function data_buffer:get_number() -> number | ||
``` | ||
Reads the next number (see data_buffer:put_number) | ||
|
||
```lua | ||
function data_buffer:size() -> integer | ||
``` | ||
Returns the buffer size | ||
|
||
```lua | ||
function data_buffer:set_position(integer: pos) | ||
``` | ||
Sets the current position in the buffer | ||
|
||
```lua | ||
function data_buffer:set_bytes(table: bytes) | ||
``` | ||
Sets bytes into the buffer |
Oops, something went wrong.