ESPHome
2024.10.2
|
A class modelled on the Java ByteBuffer class. More...
#include <bytebuffer.h>
Public Member Functions | |
ByteBuffer () | |
ByteBuffer (size_t capacity, Endian endianness=LITTLE) | |
Create a new Bytebuffer with the given capacity. More... | |
uint64_t | get_uint (size_t length) |
uint8_t | get_uint8 () |
Getters. More... | |
uint16_t | get_uint16 () |
uint32_t | get_uint24 () |
uint32_t | get_uint32 () |
uint64_t | get_uint64 () |
uint8_t | get_int8 () |
int16_t | get_int16 () |
uint32_t | get_int24 () |
int32_t | get_int32 () |
int64_t | get_int64 () |
float | get_float () |
double | get_double () |
bool | get_bool () |
std::vector< uint8_t > | get_vector (size_t length) |
void | put_uint (uint64_t value, size_t length) |
void | put_uint8 (uint8_t value) |
Putters. More... | |
void | put_uint16 (uint16_t value) |
void | put_uint24 (uint32_t value) |
void | put_uint32 (uint32_t value) |
void | put_uint64 (uint64_t value) |
void | put_int8 (int8_t value) |
void | put_int16 (int32_t value) |
void | put_int24 (int32_t value) |
void | put_int32 (int32_t value) |
void | put_int64 (int64_t value) |
void | put_float (float value) |
void | put_double (double value) |
void | put_bool (bool value) |
void | put_vector (const std::vector< uint8_t > &value) |
size_t | get_capacity () const |
size_t | get_position () const |
size_t | get_limit () const |
size_t | get_remaining () const |
Endian | get_endianness () const |
void | mark () |
void | big_endian () |
void | little_endian () |
void | set_limit (size_t limit) |
void | set_position (size_t position) |
void | clear () |
void | flip () |
std::vector< uint8_t > | get_data () |
void | rewind () |
void | reset () |
Static Public Member Functions | |
static ByteBuffer | wrap (std::vector< uint8_t > const &data, Endian endianness=LITTLE) |
Wrap an existing vector in a ByteBufffer. More... | |
static ByteBuffer | wrap (const uint8_t *ptr, size_t len, Endian endianness=LITTLE) |
Wrap an existing array in a ByteBuffer. More... | |
static ByteBuffer | wrap (uint8_t value) |
static ByteBuffer | wrap (uint16_t value, Endian endianness=LITTLE) |
static ByteBuffer | wrap (uint32_t value, Endian endianness=LITTLE) |
static ByteBuffer | wrap (uint64_t value, Endian endianness=LITTLE) |
static ByteBuffer | wrap (int8_t value) |
static ByteBuffer | wrap (int16_t value, Endian endianness=LITTLE) |
static ByteBuffer | wrap (int32_t value, Endian endianness=LITTLE) |
static ByteBuffer | wrap (int64_t value, Endian endianness=LITTLE) |
static ByteBuffer | wrap (float value, Endian endianness=LITTLE) |
static ByteBuffer | wrap (double value, Endian endianness=LITTLE) |
static ByteBuffer | wrap (bool value) |
Protected Member Functions | |
ByteBuffer (std::vector< uint8_t > const &data) | |
Protected Attributes | |
std::vector< uint8_t > | data_ |
Endian | endianness_ {LITTLE} |
size_t | position_ {0} |
size_t | mark_ {0} |
size_t | limit_ {0} |
A class modelled on the Java ByteBuffer class.
It wraps a vector of bytes and permits putting and getting items of various sizes, with an automatically incremented position.
There are three variables maintained pointing into the buffer:
capacity: the maximum amount of data that can be stored - set on construction and cannot be changed limit: the limit of the data currently available to get or put position: the current insert or extract position
0 <= position <= limit <= capacity
In addition a mark can be set to the current position with mark(). A subsequent call to reset() will restore the position to the mark.
The buffer can be marked to be little-endian (default) or big-endian. All subsequent operations will use that order.
The flip() operation will reset the position to 0 and limit to the current position. This is useful for reading data from a buffer after it has been written.
Definition at line 33 of file bytebuffer.h.
|
inline |
Definition at line 36 of file bytebuffer.h.
Create a new Bytebuffer with the given capacity.
Definition at line 40 of file bytebuffer.h.
|
inlineprotected |
Definition at line 136 of file bytebuffer.h.
|
inline |
Definition at line 122 of file bytebuffer.h.
void esphome::ByteBuffer::clear | ( | ) |
Definition at line 74 of file bytebuffer.cpp.
void esphome::ByteBuffer::flip | ( | ) |
Definition at line 78 of file bytebuffer.cpp.
|
inline |
Definition at line 92 of file bytebuffer.h.
|
inline |
Definition at line 116 of file bytebuffer.h.
|
inline |
Definition at line 131 of file bytebuffer.h.
double esphome::ByteBuffer::get_double | ( | ) |
Definition at line 118 of file bytebuffer.cpp.
|
inline |
Definition at line 120 of file bytebuffer.h.
float esphome::ByteBuffer::get_float | ( | ) |
Definition at line 114 of file bytebuffer.cpp.
|
inline |
Definition at line 83 of file bytebuffer.h.
uint32_t esphome::ByteBuffer::get_int24 | ( | ) |
Definition at line 107 of file bytebuffer.cpp.
|
inline |
Definition at line 85 of file bytebuffer.h.
|
inline |
Definition at line 86 of file bytebuffer.h.
|
inline |
Definition at line 82 of file bytebuffer.h.
|
inline |
Definition at line 118 of file bytebuffer.h.
|
inline |
Definition at line 117 of file bytebuffer.h.
|
inline |
Definition at line 119 of file bytebuffer.h.
uint64_t esphome::ByteBuffer::get_uint | ( | size_t | length | ) |
Definition at line 88 of file bytebuffer.cpp.
|
inline |
Definition at line 74 of file bytebuffer.h.
|
inline |
Definition at line 76 of file bytebuffer.h.
|
inline |
Definition at line 78 of file bytebuffer.h.
|
inline |
Definition at line 80 of file bytebuffer.h.
uint8_t esphome::ByteBuffer::get_uint8 | ( | ) |
Getters.
Definition at line 84 of file bytebuffer.cpp.
std::vector< uint8_t > esphome::ByteBuffer::get_vector | ( | size_t | length | ) |
Definition at line 123 of file bytebuffer.cpp.
|
inline |
Definition at line 123 of file bytebuffer.h.
|
inline |
Definition at line 121 of file bytebuffer.h.
|
inline |
Definition at line 113 of file bytebuffer.h.
void esphome::ByteBuffer::put_double | ( | double | value | ) |
Definition at line 157 of file bytebuffer.cpp.
void esphome::ByteBuffer::put_float | ( | float | value | ) |
Definition at line 152 of file bytebuffer.cpp.
|
inline |
Definition at line 106 of file bytebuffer.h.
|
inline |
Definition at line 107 of file bytebuffer.h.
|
inline |
Definition at line 108 of file bytebuffer.h.
|
inline |
Definition at line 109 of file bytebuffer.h.
|
inline |
Definition at line 105 of file bytebuffer.h.
void esphome::ByteBuffer::put_uint | ( | uint64_t | value, |
size_t | length | ||
) |
Definition at line 136 of file bytebuffer.cpp.
|
inline |
Definition at line 100 of file bytebuffer.h.
|
inline |
Definition at line 101 of file bytebuffer.h.
|
inline |
Definition at line 102 of file bytebuffer.h.
|
inline |
Definition at line 103 of file bytebuffer.h.
void esphome::ByteBuffer::put_uint8 | ( | uint8_t | value | ) |
Putters.
Definition at line 131 of file bytebuffer.cpp.
void esphome::ByteBuffer::put_vector | ( | const std::vector< uint8_t > & | value | ) |
Definition at line 162 of file bytebuffer.cpp.
|
inline |
Definition at line 133 of file bytebuffer.h.
|
inline |
Definition at line 132 of file bytebuffer.h.
void esphome::ByteBuffer::set_limit | ( | size_t | limit | ) |
Definition at line 66 of file bytebuffer.cpp.
void esphome::ByteBuffer::set_position | ( | size_t | position | ) |
Definition at line 70 of file bytebuffer.cpp.
|
static |
Wrap an existing vector in a ByteBufffer.
Definition at line 18 of file bytebuffer.cpp.
|
static |
Wrap an existing array in a ByteBuffer.
Note that this will create a copy of the data.
Definition at line 10 of file bytebuffer.cpp.
|
static |
Definition at line 24 of file bytebuffer.cpp.
|
static |
Definition at line 31 of file bytebuffer.cpp.
|
static |
Definition at line 38 of file bytebuffer.cpp.
|
static |
Definition at line 45 of file bytebuffer.cpp.
|
inlinestatic |
Definition at line 55 of file bytebuffer.h.
|
inlinestatic |
Definition at line 56 of file bytebuffer.h.
|
inlinestatic |
Definition at line 59 of file bytebuffer.h.
|
inlinestatic |
Definition at line 62 of file bytebuffer.h.
|
static |
Definition at line 52 of file bytebuffer.cpp.
|
static |
Definition at line 59 of file bytebuffer.cpp.
|
inlinestatic |
Definition at line 67 of file bytebuffer.h.
|
protected |
Definition at line 137 of file bytebuffer.h.
Definition at line 138 of file bytebuffer.h.
|
protected |
Definition at line 141 of file bytebuffer.h.
|
protected |
Definition at line 140 of file bytebuffer.h.
|
protected |
Definition at line 139 of file bytebuffer.h.