|
Bluenet
5.7.0
Bluenet, firmware for nRF52 smart home devices
|
A wrapper around a raw uint8_t array (buffer) to easily read, write from it. More...
#include <cs_StreamBufferAccessor.h>
Public Member Functions | |
| StreamBufferAccessor (buffer_ptr_t buffer, cs_buffer_size_t size) | |
| StreamBufferAccessor (cs_data_t data) | |
| void | reset () |
| Resets the stream buffer accessor to construction state, such that the next operation will read/write will happen from the first byte of the buffer. More... | |
| cs_ret_code_t | assign (buffer_ptr_t buffer, cs_buffer_size_t size) |
| Binds this stream buffer accessor to the given buffer pointer and tell it that there are size bytes available. More... | |
| cs_buffer_size_t | getSerializedSize () const |
| cs_buffer_size_t | getBufferSize () const |
| cs_buffer_size_t | getRemainingCapacity () const |
| cs_data_t | getSerializedBuffer () |
| template<class T > | |
| StreamBufferAccessor & | get (T *&packet_ptr) |
| If the stream buffer is in state OK, and remaining packet size is available, assign the packet_ptr to the current read address and increment it. More... | |
| template<class T > | |
| T | get () |
| Same as the pointer version of get, but this will copy its value into the lvalue its return value is to bind to and will try to construct a default value if the stream is in error state or doesn't have enough bytes left. More... | |
| template<class T > | |
| void | put (T packet) |
| Put packet into the stream, if possible. More... | |
Protected Member Functions | |
| template<class T > | |
| bool | size_check () |
| template<class T > | |
| void | increment_buff () |
| bool | status_check () |
Private Attributes | |
| buffer_ptr_t | buff_begin |
| buffer_ptr_t | buff_curr |
| buffer_ptr_t | buff_end |
| cs_ret_code_t | internal_status |
A wrapper around a raw uint8_t array (buffer) to easily read, write from it.
Example usage:
struct some_packet_t{ float val; uint32_t prescale; uint16_t id; uint16_t unused; };
some_packet_t pack; pack.val = 1234.0f; pack.prescale = 100; pack.id = 0x4321; pack.unused = 0xabcd;
uint8_t buff[16] = {0}; StreamBufferAccessor stream; stream.assign(buff,16);
stream.put(pack); // (or put individual values) stream.reset(); // (or use a stream obtained from a bluetooth buffer)
some_packet_t* received = nullptr;
stream.get(received);
if(received != nullptr){ // yay, use your data }
Note: Classes/Structs that need to be serialized, either need to be memcopy safe, or they need to specialize the get/put methods in order to handle serialization logic. These classes also need to specialize the size_check<T>
|
inline |
|
inline |
|
inline |
Binds this stream buffer accessor to the given buffer pointer and tell it that there are size bytes available.
|
inline |
Same as the pointer version of get, but this will copy its value into the lvalue its return value is to bind to and will try to construct a default value if the stream is in error state or doesn't have enough bytes left.
|
inline |
If the stream buffer is in state OK, and remaining packet size is available, assign the packet_ptr to the current read address and increment it.
This will not make any copies.
|
inline |
|
inline |
|
inline |
|
inline |
|
inlineprotected |
|
inline |
Put packet into the stream, if possible.
Then increment the current buffer pointer.
|
inline |
Resets the stream buffer accessor to construction state, such that the next operation will read/write will happen from the first byte of the buffer.
|
inlineprotected |
|
inlineprotected |
|
private |
|
private |
|
private |
|
private |