165 template <
typename T>
168 if( hdr.
tag & Meta::Sequence ) {
171 else if(hdr.
tag & Meta::Scalar) {
174 else if(hdr.
tag == Tags::Object) {
177 else if(hdr.
tag == Tags::Map) {
180 else if(hdr.
tag == Tags::Container) {
197 template <
typename TMap>
199 if constexpr (is_map_v<TMap>) {
205 for(
const auto& [key, value]: map ) {
206 *
this << key << value;
209 auto bytes_written =
data_.
tell() - cur_pos;
210 hdr_ptr->
size = bytes_written;
211 return bytes_written;
223 template <
typename TContainer>
225 if constexpr (is_container_v<TContainer>) {
231 for(
const auto& e: container ) {
235 auto bytes_written =
data_.
tell() - cur_pos;
236 hdr_ptr->
size = bytes_written;
237 return bytes_written;
249 template <
typename TObject>
251 if constexpr (is_serializable_v<TObject>) {
252 if constexpr (is_root_v<TObject>) {
260 obj.store(std::ref(*
this));
262 auto bytes_written =
data_.
tell() - cur_pos;
263 hdr_ptr->
size = bytes_written;
264 return bytes_written;
276 double dst[2]{*d64, 0.0};
289 if(
sizeof(
long double) == 8 && hdr->
tag == Tags::F128) {
308 if( hdr->
tag == Tags::SChar ) {
309 const std::string* s =
static_cast<const std::string*
>(p);
312 else if( hdr->
tag == Tags::SByte ) {
313 const Blob* bs =
static_cast<const Blob*
>(p);
334 template <
typename T>
339 if (hdr.
tag == Tags::Object) {
340 if constexpr(is_serializable_v<T>) {
341 val.load(std::ref(*
this));
345 else if (hdr.
tag == Tags::Map) {
349 else if (hdr.
tag == Tags::Container) {
367 template <
typename TMap>
369 if constexpr(is_map_v<TMap>) {
370 for(
size_t n = 0 ; n < hdr->
count ; ++n ) {
371 typename TMap::key_type k;
372 typename TMap::mapped_type e;
385 template <
typename TContainer>
388 is_container_v<TContainer> &&
389 !is_map_v<TContainer> &&
390 !std::is_same_v<TContainer, String>
392 for(
size_t n = 0 ; n < hdr->
count ; ++n ) {
393 typename TContainer::value_type e;
406 if( hdr->
tag & Meta::Scalar) {
407 if( hdr->
tag & Meta::Sequence ) {
426 double d[2]{0.0, 0.0};
437 if(
sizeof(
long double) == 8 && hdr->
tag == Tags::F128) {
453 if( hdr->
tag == Tags::SChar ) {
454 std::string* str =
static_cast<String*
>(dst);
455 str->resize(hdr->
size);
459 else if( hdr->
tag == Tags::SByte ) {
A byte buffer class with stream-like read/write semantics.
Definition tec_memfile.hpp:50
size_t write(const void *src, size_t len)
Writes data into the buffer at the current position.
Definition tec_memfile.hpp:382
long seek(long offset, int whence)
Moves the read/write position relative to a reference point.
Definition tec_memfile.hpp:343
const char * ptr(long pos) const
Returns a const pointer to a specific position in the buffer.
Definition tec_memfile.hpp:273
const void * data() const
Returns a const pointer to the buffer's data.
Definition tec_memfile.hpp:247
constexpr void rewind() noexcept
Resets the read/write position to the beginning of the buffer.
Definition tec_memfile.hpp:327
size_t capacity() const noexcept
Returns the current capacity of the underlying storage.
Definition tec_memfile.hpp:312
size_t read(void *dst, size_t len)
Reads data from the buffer starting at the current position.
Definition tec_memfile.hpp:404
constexpr long tell() const noexcept
Returns the current read/write position.
Definition tec_memfile.hpp:320
void move_from(MemFile &&src, size_t size_to_shrink=0)
Moves data from another MemFile instance.
Definition tec_memfile.hpp:221
size_t size() const noexcept
Returns the logical size of the data in the buffer.
Definition tec_memfile.hpp:304
void copy_from(const MemFile &src)
Copies data from another MemFile instance.
Definition tec_memfile.hpp:206
Lightweight binary serialization container optimized for network communication.
Definition tec_net_data.hpp:51
virtual void read_sequence(const ElemHeader *hdr, void *dst)
Reads string or blob sequence data.
Definition tec_net_data.hpp:451
void copy_from(const NetData &src)
Performs deep copy of content from another NetData instance.
Definition tec_net_data.hpp:101
virtual ~NetData()=default
Virtual destructor.
void read_container(ElemHeader *hdr, TContainer &c)
Reads sequence container from stream.
Definition tec_net_data.hpp:386
void read_map(ElemHeader *hdr, TMap &map)
Reads map-like container from stream.
Definition tec_net_data.hpp:368
size_t write_map(ElemHeader *hdr, const TMap &map)
Serializes map-like container (std::unordered_map)
Definition tec_net_data.hpp:198
Bytes data_
Internal storage of serialized binary data.
Definition tec_net_data.hpp:58
Bytes & bytes()
Returns mutable reference to internal byte buffer.
Definition tec_net_data.hpp:144
const void * data() const
Returns const pointer to the beginning of serialized data.
Definition tec_net_data.hpp:93
NetData(const NetData &)=delete
Copy constructor – use explicit copy_from()
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)
Definition tec_net_data.hpp:275
size_t size() const
Returns current logical size of the message (according to header)
Definition tec_net_data.hpp:127
virtual size_t write_scalar(ElemHeader *hdr, const void *p)
Writes single scalar value with its header.
Definition tec_net_data.hpp:287
void rewind()
Resets read position to the beginning of the buffer.
Definition tec_net_data.hpp:119
virtual void read(ElemHeader *hdr, void *dst)
Generic dispatcher for reading scalar/sequence values.
Definition tec_net_data.hpp:405
NetData()=default
Default constructor - creates empty NetData object.
void move_from(NetData &&src, size_t size_to_shrink=0)
Efficiently moves content from another NetData instance.
Definition tec_net_data.hpp:111
virtual void read_scalar(const ElemHeader *hdr, void *dst)
Reads single scalar value.
Definition tec_net_data.hpp:436
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.
Definition tec_net_data.hpp:425
size_t write_container(ElemHeader *hdr, const TContainer &container)
Serializes sequence container (vector, deque, list, ...)
Definition tec_net_data.hpp:224
size_t write_object(ElemHeader *hdr, const TObject &obj)
Serializes custom object that implements store() method.
Definition tec_net_data.hpp:250
Header header
Global message header.
Definition tec_net_data.hpp:54
const Bytes & bytes() const
Returns const reference to internal byte buffer.
Definition tec_net_data.hpp:85
NetData & operator<<(const T &val)
Serialization operator (stream-like syntax)
Definition tec_net_data.hpp:166
NetData & operator>>(T &val)
Deserialization operator (stream-like syntax)
Definition tec_net_data.hpp:335
virtual size_t write_sequence(ElemHeader *hdr, const void *p)
Writes string or blob sequence (header + raw bytes)
Definition tec_net_data.hpp:304
size_t capacity() const
Returns current capacity of internal buffer.
Definition tec_net_data.hpp:135
NetData(NetData &&)=delete
Disabled – use explicit move_from()
Core type definitions and metadata for a lightweight binary serialization format.
Definition tec_nd_types.hpp:56
std::string String
String storage type.
Definition tec_nd_types.hpp:64
Helper type for ADL customization of input operations.
Definition tec_net_data.hpp:478
Helper type for ADL customization of output operations.
Definition tec_net_data.hpp:493
Generic container and map traits.
Common definitions and utilities for the tec namespace.
A byte buffer class with stream-like read/write semantics.
Core type definitions and metadata for a lightweight binary serialization format.
The base interface for serializable objects.