#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include "macros.h"
Go to the source code of this file.
|
| bool | buffer_can_read (const buffer_t *buffer, size_t n) |
| |
| bool | buffer_seek_set (buffer_t *buffer, size_t offset) |
| |
| bool | buffer_seek_cur (buffer_t *buffer, size_t offset) |
| |
| bool | buffer_seek_end (buffer_t *buffer, size_t offset) |
| |
| bool | buffer_read_u8 (buffer_t *buffer, uint8_t *value) |
| |
| bool | buffer_read_u16 (buffer_t *buffer, uint16_t *value, endianness_t endianness) |
| |
| bool | buffer_read_u32 (buffer_t *buffer, uint32_t *value, endianness_t endianness) |
| |
| bool | buffer_read_u64 (buffer_t *buffer, uint64_t *value, endianness_t endianness) |
| |
| bool | buffer_read_varint (buffer_t *buffer, uint64_t *value) |
| |
| bool | buffer_read_bip32_path (buffer_t *buffer, uint32_t *out, size_t out_len) |
| |
| bool | buffer_copy (const buffer_t *buffer, uint8_t *out, size_t out_len) |
| |
| bool | buffer_move (buffer_t *buffer, uint8_t *out, size_t out_len) |
| |
| bool | buffer_peek (const buffer_t *buffer, uint8_t *value) |
| |
| bool | buffer_peek_n (const buffer_t *buffer, size_t n, uint8_t *value) |
| |
| WEAK bool | buffer_read_bytes (buffer_t *buffer, uint8_t *out, size_t n) |
| |
| bool | buffer_write_u8 (buffer_t *buffer, uint8_t value) |
| |
| bool | buffer_write_u16 (buffer_t *buffer, uint16_t value, endianness_t endianness) |
| |
| bool | buffer_write_u32 (buffer_t *buffer, uint32_t value, endianness_t endianness) |
| |
| bool | buffer_write_u64 (buffer_t *buffer, uint64_t value, endianness_t endianness) |
| |
| bool | buffer_write_bytes (buffer_t *buffer, const uint8_t *data, size_t n) |
| |
◆ endianness_t
Enumeration for endianness.
| Enumerator |
|---|
| BE | |
| LE | Big Endian.
Little Endian
|
Definition at line 12 of file buffer.h.
◆ buffer_can_read()
| bool buffer_can_read |
( |
const buffer_t * |
buffer, |
|
|
size_t |
n |
|
) |
| |
Tell whether buffer can read bytes or not.
- Parameters
-
| [in] | buffer | Pointer to input buffer struct. |
| [in] | n | Number of bytes to read in buffer. |
- Returns
- true if success, false otherwise.
Definition at line 28 of file buffer.c.
◆ buffer_copy()
| bool buffer_copy |
( |
const buffer_t * |
buffer, |
|
|
uint8_t * |
out, |
|
|
size_t |
out_len |
|
) |
| |
Copy bytes from buffer without moving offset.
- Parameters
-
| [in] | buffer | Pointer to input buffer struct. |
| [out] | out | Pointer to output byte buffer. |
| [in] | out_len | Length of output byte buffer. |
- Returns
- true if success, false otherwise.
Definition at line 156 of file buffer.c.
◆ buffer_move()
| bool buffer_move |
( |
buffer_t * |
buffer, |
|
|
uint8_t * |
out, |
|
|
size_t |
out_len |
|
) |
| |
Move bytes from buffer.
- Parameters
-
| [in,out] | buffer | Pointer to input buffer struct. |
| [out] | out | Pointer to output byte buffer. |
| [in] | out_len | Length of output byte buffer. |
- Returns
- true if success, false otherwise.
Definition at line 167 of file buffer.c.
◆ buffer_peek()
| bool buffer_peek |
( |
const buffer_t * |
buffer, |
|
|
uint8_t * |
value |
|
) |
| |
Read 1 byte from buffer into uint8_t without advancing the current position in the buffer. Returns true on success, false if the buffer was empty; value is not changed in case of failure.
- Parameters
-
| [in] | buffer | Pointer to input buffer struct. |
| [out] | value | Pointer to 8-bit unsigned integer read from buffer. |
- Returns
- true if success, false otherwise.
Definition at line 178 of file buffer.c.
◆ buffer_peek_n()
| bool buffer_peek_n |
( |
const buffer_t * |
buffer, |
|
|
size_t |
n, |
|
|
uint8_t * |
value |
|
) |
| |
Read 1 byte at position n from buffer into uint8_t without advancing the current position in the buffer. Returns true on success, false if the buffer is not large enough; value is not changed in case of failure.
- Parameters
-
| [in] | buffer | Pointer to input buffer struct. |
| [in] | n | Index of the byte to read, where the immediate next byte has index 0. |
| [out] | value | Pointer to 8-bit unsigned integer read from buffer. |
- Returns
- true if success, false otherwise.
Definition at line 183 of file buffer.c.
◆ buffer_read_bip32_path()
| bool buffer_read_bip32_path |
( |
buffer_t * |
buffer, |
|
|
uint32_t * |
out, |
|
|
size_t |
out_len |
|
) |
| |
Read BIP32 path from buffer.
- Parameters
-
| [in,out] | buffer | Pointer to input buffer struct. |
| [out] | out | Pointer to output 32-bit integer buffer. |
| [in] | out_len | Number of BIP32 paths read in the output buffer. |
- Returns
- true if success, false otherwise.
Definition at line 144 of file buffer.c.
◆ buffer_read_bytes()
| WEAK bool buffer_read_bytes |
( |
buffer_t * |
buffer, |
|
|
uint8_t * |
out, |
|
|
size_t |
n |
|
) |
| |
Read n bytes from buffer, and stores them in out.
- Parameters
-
| [in,out] | buffer | Pointer to input buffer struct. |
| [out] | out | Pointer to output buffer. It is the responsibility of the caller to make sure that the output buffer is at least n bytes long. |
| [in] | n | Number of bytes to read from buffer. |
- Returns
- true if success, false otherwise.
Definition at line 194 of file buffer.c.
◆ buffer_read_u16()
Read 2 bytes from buffer into uint16_t.
- Parameters
-
| [in,out] | buffer | Pointer to input buffer struct. |
| [out] | value | Pointer to 16-bit unsigned integer read from buffer. |
| [in] | endianness | Either BE (Big Endian) or LE (Little Endian). |
- Returns
- true if success, false otherwise.
Definition at line 83 of file buffer.c.
◆ buffer_read_u32()
Read 4 bytes from buffer into uint32_t.
- Parameters
-
| [in,out] | buffer | Pointer to input buffer struct. |
| [out] | value | Pointer to 32-bit unsigned integer read from buffer. |
| [in] | endianness | Either BE (Big Endian) or LE (Little Endian). |
- Returns
- true if success, false otherwise.
Definition at line 99 of file buffer.c.
◆ buffer_read_u64()
Read 8 bytes from buffer into uint64_t.
- Parameters
-
| [in,out] | buffer | Pointer to input buffer struct. |
| [out] | value | Pointer to 64-bit unsigned integer read from buffer. |
| [in] | endianness | Either BE (Big Endian) or LE (Little Endian). |
- Returns
- true if success, false otherwise.
Definition at line 115 of file buffer.c.
◆ buffer_read_u8()
| bool buffer_read_u8 |
( |
buffer_t * |
buffer, |
|
|
uint8_t * |
value |
|
) |
| |
Read 1 byte from buffer into uint8_t.
- Parameters
-
| [in,out] | buffer | Pointer to input buffer struct. |
| [out] | value | Pointer to 8-bit unsigned integer read from buffer. |
- Returns
- true if success, false otherwise.
Definition at line 69 of file buffer.c.
◆ buffer_read_varint()
| bool buffer_read_varint |
( |
buffer_t * |
buffer, |
|
|
uint64_t * |
value |
|
) |
| |
◆ buffer_seek_cur()
| bool buffer_seek_cur |
( |
buffer_t * |
buffer, |
|
|
size_t |
offset |
|
) |
| |
Seek buffer relatively to current offset.
- Parameters
-
| [in,out] | buffer | Pointer to input buffer struct. |
| [in] | offset | Offset to seek relatively to buffer->offset. |
- Returns
- true if success, false otherwise.
Definition at line 46 of file buffer.c.
◆ buffer_seek_end()
| bool buffer_seek_end |
( |
buffer_t * |
buffer, |
|
|
size_t |
offset |
|
) |
| |
Seek the buffer relatively to the end.
- Parameters
-
| [in,out] | buffer | Pointer to input buffer struct. |
| [in] | offset | Offset to seek relatively to buffer->size. |
- Returns
- true if success, false otherwise.
Definition at line 58 of file buffer.c.
◆ buffer_seek_set()
| bool buffer_seek_set |
( |
buffer_t * |
buffer, |
|
|
size_t |
offset |
|
) |
| |
Seek the buffer to specific offset.
- Parameters
-
| [in,out] | buffer | Pointer to input buffer struct. |
| [in] | offset | Specific offset to seek. |
- Returns
- true if success, false otherwise.
Definition at line 35 of file buffer.c.
◆ buffer_write_bytes()
| bool buffer_write_bytes |
( |
buffer_t * |
buffer, |
|
|
const uint8_t * |
data, |
|
|
size_t |
n |
|
) |
| |
Write a number of bytes to a buffer.
- Parameters
-
| [in,out] | buffer | Pointer to output buffer struct. |
| [in] | data | Pointer to bytes to be written. |
| [in] | n | Size of bytes to be written. |
- Returns
- true if success, false if not enough space left in the buffer.
Definition at line 270 of file buffer.c.
◆ buffer_write_u16()
Write a uint16_t into the buffer as 2 bytes, with the given endianness.
- Parameters
-
| [in,out] | buffer | Pointer to output buffer struct. |
| [in] | value | Value to be written. |
| [in] | endianness | Either BE (Big Endian) or LE (Little Endian). |
- Returns
- true if success, false if not enough space left in the buffer.
Definition at line 218 of file buffer.c.
◆ buffer_write_u32()
Write a uint32_t into the buffer as 4 bytes, with the given endianness.
- Parameters
-
| [in,out] | buffer | Pointer to output buffer struct. |
| [in] | value | Value to be written. |
| [in] | endianness | Either BE (Big Endian) or LE (Little Endian). |
- Returns
- true if success, false if not enough space left in the buffer.
Definition at line 235 of file buffer.c.
◆ buffer_write_u64()
Write a uint64_t into the buffer as 8 bytes, with the given endianness.
- Parameters
-
| [in,out] | buffer | Pointer to output buffer struct. |
| [in] | value | Value to be written. |
| [in] | endianness | Either BE (Big Endian) or LE (Little Endian). |
- Returns
- true if success, false if not enough space left in the buffer.
Definition at line 252 of file buffer.c.
◆ buffer_write_u8()
| bool buffer_write_u8 |
( |
buffer_t * |
buffer, |
|
|
uint8_t |
value |
|
) |
| |
Write a uint8_t into a buffer.
- Parameters
-
| [in,out] | buffer | Pointer to output buffer struct. |
| [in] | value | Value to be written. |
- Returns
- true if success, false if not enough space left in the buffer.
Definition at line 206 of file buffer.c.