|
TEC
A lightweight C++ library enabling safe, efficient execution in multithreaded and concurrent systems.
|
Lightweight binary serialization container optimized for network communication. More...
#include <tec_net_data.hpp>
Classes | |
| struct | StreamIn |
| Helper type for ADL customization of input operations. More... | |
| struct | StreamOut |
| Helper type for ADL customization of output operations. More... | |
Public Member Functions | |
| NetData ()=default | |
| Default constructor - creates empty NetData object. | |
| NetData (const NetData &)=delete | |
Copy constructor – use explicit copy_from() | |
| NetData (NetData &&)=delete | |
Disabled – use explicit move_from() | |
| virtual | ~NetData ()=default |
| Virtual destructor. | |
| const Bytes & | bytes () const |
| Returns const reference to internal byte buffer. | |
| const void * | data () const |
| Returns const pointer to the beginning of serialized data. | |
| void | copy_from (const NetData &src) |
| Performs deep copy of content from another NetData instance. | |
| void | move_from (NetData &&src, size_t size_to_shrink=0) |
| Efficiently moves content from another NetData instance. | |
| void | rewind () |
| Resets read position to the beginning of the buffer. | |
| size_t | size () const |
| Returns current logical size of the message (according to header) | |
| size_t | capacity () const |
| Returns current capacity of internal buffer. | |
| Bytes & | bytes () |
| Returns mutable reference to internal byte buffer. | |
| template<typename T > | |
| NetData & | operator<< (const T &val) |
| Serialization operator (stream-like syntax) | |
| template<typename T > | |
| NetData & | operator>> (T &val) |
| Deserialization operator (stream-like syntax) | |
Public Member Functions inherited from tec::NdTypes | |
| constexpr Count | to_count (size_t count) |
| Convert a size_t count to Count, clamping at maximum. | |
| ElemHeader | get_scalar_info (const char &) |
| Get element info for signed char. | |
| ElemHeader | get_scalar_info (const unsigned char &) |
| Get element info for unsigned char. | |
| ElemHeader | get_scalar_info (const short &) |
| Get element info for signed short. | |
| ElemHeader | get_scalar_info (const unsigned short &) |
| Get element info for unsigned short. | |
| ElemHeader | get_scalar_info (const int &) |
| Get element info for signed int. | |
| ElemHeader | get_scalar_info (const unsigned int &) |
| Get element info for unsigned int. | |
| ElemHeader | get_scalar_info (const long &) |
| Get element info for signed long. | |
| ElemHeader | get_scalar_info (const unsigned long &) |
| Get element info for unsigned long. | |
| ElemHeader | get_scalar_info (const long long &) |
| Get element info for signed long long. | |
| ElemHeader | get_scalar_info (const unsigned long long &) |
| Get element info for unsigned long long. | |
| ElemHeader | get_scalar_info (const bool &) |
| Get element info for bool. | |
| ElemHeader | get_scalar_info (const float &) |
| Get element info for float. | |
| ElemHeader | get_scalar_info (const double &) |
| Get element info for double. | |
| ElemHeader | get_scalar_info (const long double &) |
| Get element info for long double (platform-dependent size). | |
| ElemHeader | get_seq_info (const String &str) |
| Get element info for std::string (character sequence). | |
| ElemHeader | get_seq_info (const Blob &bytes) |
| Get element info for Blob (raw byte sequence). | |
| template<typename TContainer > | |
| ElemHeader | get_container_info (const TContainer &c) |
| Get element info for flat containers (vector, array, etc.). | |
| template<typename TMap > | |
| ElemHeader | get_map_info (const TMap &m) |
| Get element info for map-like containers. | |
| template<typename TObject > | |
| ElemHeader | get_object_info (const TObject &) |
| Get element info for user-defined serializable objects. | |
| template<typename T > | |
| ElemHeader | get_info (const T &val) |
| Generic dispatcher to determine ElemHeader for any supported type. | |
Public Attributes | |
| Header | header |
| Global message header. | |
Protected Member Functions | |
| template<typename TMap > | |
| size_t | write_map (ElemHeader *hdr, const TMap &map) |
| Serializes map-like container (std::unordered_map) | |
| template<typename TContainer > | |
| size_t | write_container (ElemHeader *hdr, const TContainer &container) |
| Serializes sequence container (vector, deque, list, ...) | |
| template<typename TObject > | |
| size_t | write_object (ElemHeader *hdr, const TObject &obj) |
| Serializes custom object that implements store() method. | |
| virtual size_t | write_long_double_64 (ElemHeader *hdr, const double *d64) |
| Special handling for long double when sizeof(long double) == 8 (on MS Windows) | |
| virtual size_t | write_scalar (ElemHeader *hdr, const void *p) |
| Writes single scalar value with its header. | |
| virtual size_t | write_sequence (ElemHeader *hdr, const void *p) |
| Writes string or blob sequence (header + raw bytes) | |
| template<typename TMap > | |
| void | read_map (ElemHeader *hdr, TMap &map) |
| Reads map-like container from stream. | |
| template<typename TContainer > | |
| void | read_container (ElemHeader *hdr, TContainer &c) |
| Reads sequence container from stream. | |
| virtual void | read (ElemHeader *hdr, void *dst) |
| Generic dispatcher for reading scalar/sequence values. | |
| virtual void | read_long_double_64 (const ElemHeader *hdr, double *d64) |
Platform-specific reading of MSWindows' long double (64 bit) stored as 128-bit double. | |
| virtual void | read_scalar (const ElemHeader *hdr, void *dst) |
| Reads single scalar value. | |
| virtual void | read_sequence (const ElemHeader *hdr, void *dst) |
| Reads string or blob sequence data. | |
Protected Attributes | |
| Bytes | data_ |
| Internal storage of serialized binary data. | |
Additional Inherited Members | |
Public Types inherited from tec::NdTypes | |
| using | ID = uint16_t |
| Unique identifier type for serialized objects/messages. | |
| using | Tag = uint16_t |
| Tag type used to encode element kind and properties. | |
| using | Size = uint32_t |
| Size type for individual element payload (in bytes). | |
| using | Count = uint16_t |
| Count type for number of elements in sequences/containers. | |
| using | Bool = uint8_t |
| Boolean storage type (always 1 byte). | |
| using | String = std::string |
| String storage type. | |
Lightweight binary serialization container optimized for network communication.
NetData provides efficient serialization and deserialization of various C++ types including scalars, strings, containers, maps and user-defined serializable objects. The format consists of ElemHeader + payload for each element, allowing flexible and relatively compact binary representation suitable for network transmission.
|
inline |
Returns mutable reference to internal byte buffer.
Returns const reference to internal byte buffer.
|
inline |
Returns current capacity of internal buffer.
Returns const pointer to the beginning of serialized data.
Efficiently moves content from another NetData instance.
| src | rvalue reference to source object (will be left in moved-from state) |
| size_to_shrink | optional target capacity after move (0 = don't shrink) |
Serialization operator (stream-like syntax)
| T | type of value to serialize |
| val | value to be serialized |
Supports most fundamental types, strings, containers, maps and custom types that satisfy is_serializable_v<> trait.
Deserialization operator (stream-like syntax)
| T | type of value to deserialize |
| val | [out] destination variable |
|
inlineprotectedvirtual |
Generic dispatcher for reading scalar/sequence values.
| hdr | element header already read |
| dst | [out] destination memory |
|
inlineprotected |
Reads sequence container from stream.
| TContainer | sequence container type |
| hdr | element header already read |
| c | [out] destination container |
|
inlineprotectedvirtual |
Platform-specific reading of MSWindows' long double (64 bit) stored as 128-bit double.
| hdr | element header |
| d64 | [out] destination double |
|
inlineprotected |
Reads map-like container from stream.
| TMap | map-like container type |
| hdr | element header already read |
| map | [out] destination container |
|
inlineprotectedvirtual |
Reads single scalar value.
| hdr | element header |
| dst | [out] destination memory |
|
inlineprotectedvirtual |
Reads string or blob sequence data.
| hdr | element header |
| dst | [out] destination string/blob |
|
inline |
Returns current logical size of the message (according to header)
|
inlineprotected |
Serializes sequence container (vector, deque, list, ...)
| TContainer | sequence container type |
| hdr | prepared element header |
| container | container instance to serialize |
|
inlineprotectedvirtual |
Special handling for long double when sizeof(long double) == 8 (on MS Windows)
| hdr | element header |
| d64 | pointer to double value (used as source) |
|
inlineprotected |
Serializes map-like container (std::unordered_map)
| TMap | map-like container type |
| hdr | prepared element header |
| map | container instance to serialize |
|
inlineprotected |
Serializes custom object that implements store() method.
| TObject | type of serializable object |
| hdr | prepared element header |
| obj | object instance to serialize |
|
inlineprotectedvirtual |
Writes single scalar value with its header.
| hdr | element header |
| p | pointer to source value |
|
inlineprotectedvirtual |
Writes string or blob sequence (header + raw bytes)
| hdr | element header |
| p | pointer to source (std::string or Blob) |