Embedded SDK
Embedded SDK
buffer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <stdint.h> // uint*_t
4 #include <stddef.h> // size_t
5 #include <stdbool.h> // bool
6 
10 typedef enum {
11  BE,
12  LE
14 
18 typedef struct {
19  const uint8_t *ptr;
20  size_t size;
21  size_t offset;
22 } buffer_t;
23 
35 bool buffer_can_read(const buffer_t *buffer, size_t n);
36 
48 bool buffer_seek_set(buffer_t *buffer, size_t offset);
49 
61 bool buffer_seek_cur(buffer_t *buffer, size_t offset);
62 
74 bool buffer_seek_end(buffer_t *buffer, size_t offset);
75 
87 bool buffer_read_u8(buffer_t *buffer, uint8_t *value);
88 
102 bool buffer_read_u16(buffer_t *buffer, uint16_t *value, endianness_t endianness);
103 
117 bool buffer_read_u32(buffer_t *buffer, uint32_t *value, endianness_t endianness);
118 
132 bool buffer_read_u64(buffer_t *buffer, uint64_t *value, endianness_t endianness);
133 
147 bool buffer_read_varint(buffer_t *buffer, uint64_t *value);
148 
162 bool buffer_read_bip32_path(buffer_t *buffer, uint32_t *out, size_t out_len);
163 
177 bool buffer_copy(const buffer_t *buffer, uint8_t *out, size_t out_len);
178 
192 bool buffer_move(buffer_t *buffer, uint8_t *out, size_t out_len);
bool buffer_read_varint(buffer_t *buffer, uint64_t *value)
Definition: buffer.c:128
bool buffer_seek_end(buffer_t *buffer, size_t offset)
Definition: buffer.c:55
bool buffer_read_u16(buffer_t *buffer, uint16_t *value, endianness_t endianness)
Definition: buffer.c:80
bool buffer_copy(const buffer_t *buffer, uint8_t *out, size_t out_len)
Definition: buffer.c:153
bool buffer_seek_cur(buffer_t *buffer, size_t offset)
Definition: buffer.c:43
bool buffer_read_bip32_path(buffer_t *buffer, uint32_t *out, size_t out_len)
Definition: buffer.c:141
bool buffer_seek_set(buffer_t *buffer, size_t offset)
Definition: buffer.c:32
bool buffer_can_read(const buffer_t *buffer, size_t n)
Definition: buffer.c:27
endianness_t
Definition: buffer.h:10
@ LE
Big Endian.
Definition: buffer.h:12
@ BE
Definition: buffer.h:11
bool buffer_read_u64(buffer_t *buffer, uint64_t *value, endianness_t endianness)
Definition: buffer.c:112
bool buffer_move(buffer_t *buffer, uint8_t *out, size_t out_len)
Definition: buffer.c:164
bool buffer_read_u32(buffer_t *buffer, uint32_t *value, endianness_t endianness)
Definition: buffer.c:96
bool buffer_read_u8(buffer_t *buffer, uint8_t *value)
Definition: buffer.c:66
const uint8_t * ptr
Definition: buffer.h:19
size_t size
Pointer to byte buffer.
Definition: buffer.h:20
size_t offset
Size of byte buffer.
Definition: buffer.h:21
unsigned short uint16_t
Definition: usbd_conf.h:54
unsigned char uint8_t
Definition: usbd_conf.h:53