![]() |
VSM C++ SDK
Vehicle Specific Modules SDK
|
Generic I/O buffer. More...
#include <io_buffer.h>
Public Types | |
typedef std::shared_ptr < Io_buffer > | Ptr |
Pointer type. | |
typedef std::weak_ptr< Io_buffer > | Weak_ptr |
Pointer type. | |
Public Member Functions | |
Io_buffer (const Io_buffer &buf, size_t offset=0, size_t len=END) | |
Copy constructor. More... | |
Io_buffer (Io_buffer &&buf) | |
Move constructor. More... | |
Io_buffer (std::shared_ptr< const std::vector< uint8_t >> &&data_vec, size_t offset=0, size_t len=END) | |
Construct from data provided in vector. More... | |
Io_buffer (std::vector< uint8_t > &&data_vec, size_t offset=0, size_t len=END) | |
Construct from data provided in vector. More... | |
Io_buffer () | |
Construct empty buffer. More... | |
Io_buffer (const std::string &data_str) | |
Construct buffer from string. More... | |
Io_buffer (const void *data, size_t len) | |
Construct buffer from provided bytes array. More... | |
Ptr | Concatenate (Io_buffer::Ptr buf) |
Concatenate this buffer data with another buffer data and return new buffer object which contains resulted data. More... | |
Ptr | Slice (size_t offset, size_t len=END) const |
Take slice from buffer data. More... | |
size_t | Get_length () const |
Get length of the contained data. More... | |
const void * | Get_data () const |
Get pointer to raw data stored in the buffer. More... | |
std::string | Get_string () const |
Get buffer content as string. More... | |
std::string | Get_ascii () const |
Get buffer data as string of characters. More... | |
std::string | Get_hex () const |
Get buffer data as hex string. | |
Static Public Member Functions | |
template<typename... Args> | |
static Ptr | Create (Args &&...args) |
Create an instance. More... | |
Static Public Attributes | |
static const size_t | END |
Special value which references data end. More... | |
Generic I/O buffer.
Used for all I/O operations with network, filesystem, peripheral devices. Should always be passed by Io_buffer::Ptr smart pointer type. This allows anyone to hold reference to the buffer until he needs to access data and release the buffer when it last reference released.
Important: the buffer object is immutable - once it is created its data cannot be modified. It is required not confuse other reference holders. If modified buffer is required it can be easily created based on existing one via different constructors, operators and methods. Create() method should be used for obtaining Io_buffer instance.
Copy constructor.
buf | Buffer to copy from. |
offset | Offset in bytes to reference data in the source buffer. |
len | Length in bytes of the referenced data. Value END indicates that all remaining data are taken. |
Invalid_param_exception | if the specified offset or length exceeds the source buffer boundary. |
ugcs::vsm::Io_buffer::Io_buffer | ( | Io_buffer && | buf | ) |
Move constructor.
|
explicit |
Construct from data provided in vector.
Typical usage is for data which are firstly received from some I/O call.
data_vec | Vector with data. Should be dynamically allocated by "std::make_shared()". Keep in mind that it can be passed somewhere else only by shared pointer. |
offset | Offset in data vector where this buffer data start from. |
len | Length of the data referenced in the provided vector. Offset and length should not exceed vector boundary. Value END indicates that all remaining data in vector should be used. |
Invalid_param_exception | if the specified offset or length exceeds the source buffer boundary. |
ugcs::vsm::Io_buffer::Io_buffer | ( | std::vector< uint8_t > && | data_vec, |
size_t | offset = 0 , |
||
size_t | len = END |
||
) |
Construct from data provided in vector.
See constructor which accepts "std::shared_ptr<const std::vector<uint8_t>> &&" for more details.
ugcs::vsm::Io_buffer::Io_buffer | ( | ) |
Construct empty buffer.
ugcs::vsm::Io_buffer::Io_buffer | ( | const std::string & | data_str | ) |
Construct buffer from string.
Null terminator is not included in the data. Data are copied.
ugcs::vsm::Io_buffer::Io_buffer | ( | const void * | data, |
size_t | len | ||
) |
Construct buffer from provided bytes array.
Data are copied.
data | Bytes array with data. |
len | Number of bytes to take from data argument. |
Ptr ugcs::vsm::Io_buffer::Concatenate | ( | Io_buffer::Ptr | buf | ) |
Concatenate this buffer data with another buffer data and return new buffer object which contains resulted data.
Note, that method complexity is linear if lengths of both buffers are not zero.
buf | Buffer to concatenate with. |
|
inlinestatic |
Create an instance.
std::string ugcs::vsm::Io_buffer::Get_ascii | ( | ) | const |
Get buffer data as string of characters.
Non-printable chars are substituted with '.'
const void* ugcs::vsm::Io_buffer::Get_data | ( | ) | const |
Get pointer to raw data stored in the buffer.
Invalid_op_exception | if the buffer is empty. |
|
inline |
Get length of the contained data.
std::string ugcs::vsm::Io_buffer::Get_string | ( | ) | const |
Get buffer content as string.
Take slice from buffer data.
offset | Offset to start slice from. |
len | Length of the slice data. Value END indicates that all remaining data should be taken. |
Invalid_param_exception | if the specified offset or length exceeds the source buffer boundary. |
|
static |
Special value which references data end.