Embedded SDK
Embedded SDK
Functions
buffer.c File Reference
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include <string.h>
#include "buffer.h"
#include "read.h"
#include "varint.h"
#include "bip32.h"
Include dependency graph for buffer.c:

Go to the source code of this file.

Functions

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)
 

Function Documentation

◆ buffer_can_read()

bool buffer_can_read ( const buffer_t buffer,
size_t  n 
)

Tell whether buffer can read bytes or not.

Parameters
[in]bufferPointer to input buffer struct.
[in]nNumber of bytes to read in buffer.
Returns
true if success, false otherwise.

Definition at line 27 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]bufferPointer to input buffer struct.
[out]outPointer to output byte buffer.
[in]out_lenLength of output byte buffer.
Returns
true if success, false otherwise.

Definition at line 153 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]bufferPointer to input buffer struct.
[out]outPointer to output byte buffer.
[in]out_lenLength of output byte buffer.
Returns
true if success, false otherwise.

Definition at line 164 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]bufferPointer to input buffer struct.
[out]outPointer to output 32-bit integer buffer.
[in]out_lenNumber of BIP32 paths read in the output buffer.
Returns
true if success, false otherwise.

Definition at line 141 of file buffer.c.

◆ buffer_read_u16()

bool buffer_read_u16 ( buffer_t buffer,
uint16_t value,
endianness_t  endianness 
)

Read 2 bytes from buffer into uint16_t.

Parameters
[in,out]bufferPointer to input buffer struct.
[out]valuePointer to 16-bit unsigned integer read from buffer.
[in]endiannessEither BE (Big Endian) or LE (Little Endian).
Returns
true if success, false otherwise.

Definition at line 80 of file buffer.c.

◆ buffer_read_u32()

bool buffer_read_u32 ( buffer_t buffer,
uint32_t *  value,
endianness_t  endianness 
)

Read 4 bytes from buffer into uint32_t.

Parameters
[in,out]bufferPointer to input buffer struct.
[out]valuePointer to 32-bit unsigned integer read from buffer.
[in]endiannessEither BE (Big Endian) or LE (Little Endian).
Returns
true if success, false otherwise.

Definition at line 96 of file buffer.c.

◆ buffer_read_u64()

bool buffer_read_u64 ( buffer_t buffer,
uint64_t *  value,
endianness_t  endianness 
)

Read 8 bytes from buffer into uint64_t.

Parameters
[in,out]bufferPointer to input buffer struct.
[out]valuePointer to 64-bit unsigned integer read from buffer.
[in]endiannessEither BE (Big Endian) or LE (Little Endian).
Returns
true if success, false otherwise.

Definition at line 112 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]bufferPointer to input buffer struct.
[out]valuePointer to 8-bit unsigned integer read from buffer.
Returns
true if success, false otherwise.

Definition at line 66 of file buffer.c.

◆ buffer_read_varint()

bool buffer_read_varint ( buffer_t buffer,
uint64_t *  value 
)

Read Bitcoin-like varint from buffer into uint64_t.

See also
https://en.bitcoin.it/wiki/Protocol_documentation#Variable_length_integer
Parameters
[in,out]bufferPointer to input buffer struct.
[out]valuePointer to 64-bit unsigned integer read from buffer.
Returns
true if success, false otherwise.

Definition at line 128 of file buffer.c.

◆ buffer_seek_cur()

bool buffer_seek_cur ( buffer_t buffer,
size_t  offset 
)

Seek buffer relatively to current offset.

Parameters
[in,out]bufferPointer to input buffer struct.
[in]offsetOffset to seek relatively to buffer->offset.
Returns
true if success, false otherwise.

Definition at line 43 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]bufferPointer to input buffer struct.
[in]offsetOffset to seek relatively to buffer->size.
Returns
true if success, false otherwise.

Definition at line 55 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]bufferPointer to input buffer struct.
[in]offsetSpecific offset to seek.
Returns
true if success, false otherwise.

Definition at line 32 of file buffer.c.