ESPHome
2024.11.1
|
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... | |
template<typename T > | |
T | get (typename std::enable_if< std::is_integral< T >::value, T >::type *=0, typename std::enable_if<(sizeof(T)<=sizeof(uint32_t)), T >::type *=0) |
template<typename T > | |
T | get (size_t offset, typename std::enable_if< std::is_integral< T >::value, T >::type *=0, typename std::enable_if<(sizeof(T)<=sizeof(uint32_t)), T >::type *=0) |
template<typename T > | |
void | put (const T &value, typename std::enable_if< std::is_integral< T >::value, T >::type *=0, typename std::enable_if<(sizeof(T)<=sizeof(uint32_t)), T >::type *=0) |
template<typename T > | |
void | put (const T &value, size_t offset, typename std::enable_if< std::is_integral< T >::value, T >::type *=0, typename std::enable_if<(sizeof(T)<=sizeof(uint32_t)), T >::type *=0) |
template<typename T > | |
T | get (typename std::enable_if< std::is_integral< T >::value, T >::type *=0, typename std::enable_if<(sizeof(T)==sizeof(uint64_t)), T >::type *=0) |
template<typename T > | |
T | get (size_t offset, typename std::enable_if< std::is_integral< T >::value, T >::type *=0, typename std::enable_if<(sizeof(T)==sizeof(uint64_t)), T >::type *=0) |
template<typename T > | |
void | put (const T &value, typename std::enable_if< std::is_integral< T >::value, T >::type *=0, typename std::enable_if<(sizeof(T)==sizeof(uint64_t)), T >::type *=0) |
template<typename T > | |
void | put (const T &value, size_t offset, typename std::enable_if< std::is_integral< T >::value, T >::type *=0, typename std::enable_if<(sizeof(T)==sizeof(uint64_t)), T >::type *=0) |
template<typename T > | |
T | get (typename std::enable_if< std::is_floating_point< T >::value, T >::type *=0, typename std::enable_if<(sizeof(T)==sizeof(uint32_t)), T >::type *=0) |
template<typename T > | |
T | get (typename std::enable_if< std::is_floating_point< T >::value, T >::type *=0, typename std::enable_if<(sizeof(T)==sizeof(uint64_t)), T >::type *=0) |
template<typename T > | |
T | get (size_t offset, typename std::enable_if< std::is_floating_point< T >::value, T >::type *=0, typename std::enable_if<(sizeof(T)==sizeof(uint32_t)), T >::type *=0) |
template<typename T > | |
T | get (size_t offset, typename std::enable_if< std::is_floating_point< T >::value, T >::type *=0, typename std::enable_if<(sizeof(T)==sizeof(uint64_t)), T >::type *=0) |
template<typename T > | |
void | put (const T &value, typename std::enable_if< std::is_floating_point< T >::value, T >::type *=0, typename std::enable_if<(sizeof(T)<=sizeof(uint32_t)), T >::type *=0) |
template<typename T > | |
void | put (const T &value, typename std::enable_if< std::is_floating_point< T >::value, T >::type *=0, typename std::enable_if<(sizeof(T)==sizeof(uint64_t)), T >::type *=0) |
template<typename T > | |
void | put (const T &value, size_t offset, typename std::enable_if< std::is_floating_point< T >::value, T >::type *=0, typename std::enable_if<(sizeof(T)<=sizeof(uint32_t)), T >::type *=0) |
template<typename T > | |
void | put (const T &value, size_t offset, typename std::enable_if< std::is_floating_point< T >::value, T >::type *=0, typename std::enable_if<(sizeof(T)==sizeof(uint64_t)), T >::type *=0) |
void | put_float (float value) |
void | put_double (double value) |
uint8_t | get_uint8 () |
uint16_t | get_uint16 () |
uint32_t | get_uint24 () |
uint32_t | get_uint32 () |
uint64_t | get_uint64 () |
uint8_t | get_int8 () |
int16_t | get_int16 () |
int32_t | get_int32 () |
int64_t | get_int64 () |
float | get_float () |
double | get_double () |
bool | get_bool () |
uint32_t | get_int24 (size_t offset) |
uint32_t | get_int24 () |
std::vector< uint8_t > | get_vector (size_t length, size_t offset) |
std::vector< uint8_t > | get_vector (size_t length) |
void | put_uint8 (uint8_t value) |
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 (int16_t value) |
void | put_int24 (int32_t value) |
void | put_int32 (int32_t value) |
void | put_int64 (int64_t value) |
void | put_bool (bool value) |
uint64_t | get_uint64 (size_t offset) |
uint32_t | get_uint24 (size_t offset) |
double | get_double (size_t offset) |
uint8_t | get_uint8 (size_t offset) |
uint16_t | get_uint16 (size_t offset) |
uint32_t | get_uint32 (size_t offset) |
uint8_t | get_int8 (size_t offset) |
int16_t | get_int16 (size_t offset) |
int32_t | get_int32 (size_t offset) |
int64_t | get_int64 (size_t offset) |
float | get_float (size_t offset) |
bool | get_bool (size_t offset) |
void | put_uint8 (uint8_t value, size_t offset) |
void | put_uint16 (uint16_t value, size_t offset) |
void | put_uint24 (uint32_t value, size_t offset) |
void | put_uint32 (uint32_t value, size_t offset) |
void | put_uint64 (uint64_t value, size_t offset) |
void | put_int8 (int8_t value, size_t offset) |
void | put_int16 (int16_t value, size_t offset) |
void | put_int24 (int32_t value, size_t offset) |
void | put_int32 (int32_t value, size_t offset) |
void | put_int64 (int64_t value, size_t offset) |
void | put_float (float value, size_t offset) |
void | put_double (double value, size_t offset) |
void | put_bool (bool value, size_t offset) |
void | put (const std::vector< uint8_t > &value, size_t offset) |
void | put_vector (const std::vector< uint8_t > &value, size_t offset) |
void | put (const std::vector< uint8_t > &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 () |
std::vector< uint8_t > | get_data () |
void | get_bytes (void *dest, size_t length) |
void | get_bytes (void *dest, size_t length, size_t offset) |
void | rewind () |
void | reset () |
void | set_limit (size_t limit) |
void | set_position (size_t position) |
void | clear () |
void | flip () |
Static Public Member Functions | |
template<typename T > | |
static ByteBuffer | wrap (T value, Endian endianness=LITTLE) |
static ByteBuffer | wrap (std::vector< uint8_t > const &data, Endian endianness=LITTLE) |
static ByteBuffer | wrap (const uint8_t *ptr, size_t len, Endian endianness=LITTLE) |
Protected Member Functions | |
uint64_t | get_uint64_ (size_t offset, size_t length) const |
uint64_t | get_uint64_ (size_t length) |
uint32_t | get_uint32_ (size_t offset, size_t length) const |
uint32_t | get_uint32_ (size_t length) |
void | put_uint64_ (uint64_t value, size_t length) |
Putters. More... | |
void | put_uint32_ (uint32_t value, size_t length) |
void | put_uint64_ (uint64_t value, size_t offset, size_t length) |
void | put_uint32_ (uint32_t value, size_t offset, size_t length) |
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.
The code is defined here in the header file rather than in a .cpp file, so that it does not get compiled if not used. The templated functions ensure that only those typed functions actually used are compiled. The functions are implicitly inline-able which will aid performance.
Definition at line 38 of file bytebuffer.h.
|
inline |
Definition at line 42 of file bytebuffer.h.
Create a new Bytebuffer with the given capacity.
Definition at line 47 of file bytebuffer.h.
|
inlineprotected |
Definition at line 411 of file bytebuffer.h.
|
inline |
Definition at line 297 of file bytebuffer.h.
|
inline |
Definition at line 316 of file bytebuffer.h.
|
inline |
Definition at line 320 of file bytebuffer.h.
|
inline |
Definition at line 59 of file bytebuffer.h.
|
inline |
Definition at line 66 of file bytebuffer.h.
|
inline |
Definition at line 85 of file bytebuffer.h.
|
inline |
Definition at line 91 of file bytebuffer.h.
|
inline |
Definition at line 110 of file bytebuffer.h.
|
inline |
Definition at line 116 of file bytebuffer.h.
|
inline |
Definition at line 122 of file bytebuffer.h.
|
inline |
Definition at line 128 of file bytebuffer.h.
|
inline |
Definition at line 197 of file bytebuffer.h.
|
inline |
Definition at line 262 of file bytebuffer.h.
|
inline |
Definition at line 302 of file bytebuffer.h.
|
inline |
Definition at line 307 of file bytebuffer.h.
|
inline |
Definition at line 291 of file bytebuffer.h.
|
inline |
Definition at line 300 of file bytebuffer.h.
|
inline |
Definition at line 194 of file bytebuffer.h.
|
inline |
Definition at line 244 of file bytebuffer.h.
|
inline |
Definition at line 295 of file bytebuffer.h.
|
inline |
Definition at line 192 of file bytebuffer.h.
|
inline |
Definition at line 258 of file bytebuffer.h.
|
inline |
Definition at line 188 of file bytebuffer.h.
|
inline |
Definition at line 254 of file bytebuffer.h.
|
inline |
Definition at line 199 of file bytebuffer.h.
|
inline |
Definition at line 207 of file bytebuffer.h.
|
inline |
Definition at line 189 of file bytebuffer.h.
|
inline |
Definition at line 255 of file bytebuffer.h.
|
inline |
Definition at line 190 of file bytebuffer.h.
|
inline |
Definition at line 256 of file bytebuffer.h.
|
inline |
Definition at line 187 of file bytebuffer.h.
|
inline |
Definition at line 253 of file bytebuffer.h.
|
inline |
Definition at line 293 of file bytebuffer.h.
|
inline |
Definition at line 292 of file bytebuffer.h.
|
inline |
Definition at line 294 of file bytebuffer.h.
|
inline |
Definition at line 179 of file bytebuffer.h.
|
inline |
Definition at line 249 of file bytebuffer.h.
|
inline |
Definition at line 181 of file bytebuffer.h.
|
inline |
Definition at line 243 of file bytebuffer.h.
|
inline |
Definition at line 183 of file bytebuffer.h.
|
inline |
Definition at line 251 of file bytebuffer.h.
|
inlineprotected |
Definition at line 348 of file bytebuffer.h.
|
inlineprotected |
Definition at line 365 of file bytebuffer.h.
|
inline |
Definition at line 185 of file bytebuffer.h.
|
inline |
Definition at line 242 of file bytebuffer.h.
|
inlineprotected |
Definition at line 326 of file bytebuffer.h.
|
inlineprotected |
Definition at line 343 of file bytebuffer.h.
|
inline |
Definition at line 177 of file bytebuffer.h.
|
inline |
Definition at line 247 of file bytebuffer.h.
|
inline |
Definition at line 214 of file bytebuffer.h.
|
inline |
Definition at line 219 of file bytebuffer.h.
|
inline |
Definition at line 298 of file bytebuffer.h.
|
inline |
Definition at line 296 of file bytebuffer.h.
|
inline |
Definition at line 72 of file bytebuffer.h.
|
inline |
Definition at line 78 of file bytebuffer.h.
|
inline |
Definition at line 97 of file bytebuffer.h.
|
inline |
Definition at line 103 of file bytebuffer.h.
|
inline |
Definition at line 133 of file bytebuffer.h.
|
inline |
Definition at line 139 of file bytebuffer.h.
|
inline |
Definition at line 145 of file bytebuffer.h.
|
inline |
Definition at line 151 of file bytebuffer.h.
|
inline |
Definition at line 279 of file bytebuffer.h.
|
inline |
Definition at line 283 of file bytebuffer.h.
|
inline |
Definition at line 238 of file bytebuffer.h.
|
inline |
Definition at line 278 of file bytebuffer.h.
|
inline |
Definition at line 175 of file bytebuffer.h.
|
inline |
Definition at line 277 of file bytebuffer.h.
|
inline |
Definition at line 174 of file bytebuffer.h.
|
inline |
Definition at line 276 of file bytebuffer.h.
|
inline |
Definition at line 233 of file bytebuffer.h.
|
inline |
Definition at line 271 of file bytebuffer.h.
|
inline |
Definition at line 234 of file bytebuffer.h.
|
inline |
Definition at line 272 of file bytebuffer.h.
|
inline |
Definition at line 235 of file bytebuffer.h.
|
inline |
Definition at line 273 of file bytebuffer.h.
|
inline |
Definition at line 236 of file bytebuffer.h.
|
inline |
Definition at line 274 of file bytebuffer.h.
|
inline |
Definition at line 232 of file bytebuffer.h.
|
inline |
Definition at line 270 of file bytebuffer.h.
|
inline |
Definition at line 227 of file bytebuffer.h.
|
inline |
Definition at line 265 of file bytebuffer.h.
|
inline |
Definition at line 228 of file bytebuffer.h.
|
inline |
Definition at line 266 of file bytebuffer.h.
|
inline |
Definition at line 229 of file bytebuffer.h.
|
inline |
Definition at line 267 of file bytebuffer.h.
|
inlineprotected |
Definition at line 377 of file bytebuffer.h.
|
inlineprotected |
Definition at line 397 of file bytebuffer.h.
|
inline |
Definition at line 230 of file bytebuffer.h.
|
inline |
Definition at line 268 of file bytebuffer.h.
|
inlineprotected |
Putters.
Definition at line 373 of file bytebuffer.h.
|
inlineprotected |
Definition at line 382 of file bytebuffer.h.
|
inline |
Definition at line 226 of file bytebuffer.h.
|
inline |
Definition at line 264 of file bytebuffer.h.
|
inline |
Definition at line 282 of file bytebuffer.h.
|
inline |
Definition at line 287 of file bytebuffer.h.
|
inline |
Definition at line 312 of file bytebuffer.h.
|
inline |
Definition at line 311 of file bytebuffer.h.
|
inline |
Definition at line 314 of file bytebuffer.h.
|
inline |
Definition at line 315 of file bytebuffer.h.
|
inlinestatic |
Definition at line 156 of file bytebuffer.h.
|
inlinestatic |
Definition at line 163 of file bytebuffer.h.
|
inlinestatic |
Definition at line 169 of file bytebuffer.h.
|
protected |
Definition at line 413 of file bytebuffer.h.
Definition at line 414 of file bytebuffer.h.
|
protected |
Definition at line 417 of file bytebuffer.h.
|
protected |
Definition at line 416 of file bytebuffer.h.
|
protected |
Definition at line 415 of file bytebuffer.h.