IRSOL
C++ code implementing socket server for interacting with Baumer camera.
irsol::protocol::internal::SerializedMessage Struct Reference

Represents a serialized protocol message with header and payload. More...

#include <serialized_message.hpp>

Public Member Functions

 SerializedMessage (const std::string &header, std::vector< irsol::types::byte_t > &&payload)
 Constructs a SerializedMessage with a header and binary payload.
 
 SerializedMessage (SerializedMessage &&) noexcept=default
 Move constructor (defaulted).
 
SerializedMessageoperator= (SerializedMessage &&) noexcept=default
 Move assignment operator (defaulted).
 
 SerializedMessage (const SerializedMessage &)=delete
 Deleted copy constructor to prevent copying.
 
SerializedMessageoperator= (const SerializedMessage &)=delete
 Deleted copy assignment operator to prevent copying.
 
bool hasHeader () const
 Checks whether the serialized message contains a non-empty header.
 
bool hasPayload () const
 Checks whether the serialized message contains a non-empty payload.
 
size_t payloadSize () const
 Returns the size of the payload in bytes.
 
std::string toString () const
 Converts the serialized message to a string representation.
 

Public Attributes

std::string header
 The textual header of the serialized message.
 
std::vector< irsol::types::byte_tpayload {}
 The binary payload of the serialized message.
 

Detailed Description

Represents a serialized protocol message with header and payload.

This structure stores the serialized form of an outgoing protocol message. It consists of:

  • A textual header stored as a std::string.
  • A binary payload stored as a std::vector<irsol::types::byte_t>.

The class supports move semantics but disables copying to avoid expensive copies of potentially large payloads.

Utility member functions provide information about the presence of header and payload data, the payload size, and allow conversion to a string representation.

Definition at line 42 of file serialized_message.hpp.

Constructor & Destructor Documentation

◆ SerializedMessage() [1/3]

irsol::protocol::internal::SerializedMessage::SerializedMessage ( const std::string &  header,
std::vector< irsol::types::byte_t > &&  payload 
)

Constructs a SerializedMessage with a header and binary payload.

The constructor moves the payload into the member to avoid copies.

Parameters
headerThe message header string.
payloadThe binary payload vector to move.

Definition at line 9 of file serialized_message.cpp.

12 : header(header), payload(std::move(payload))
13{}
std::vector< irsol::types::byte_t > payload
The binary payload of the serialized message.
std::string header
The textual header of the serialized message.

◆ SerializedMessage() [2/3]

irsol::protocol::internal::SerializedMessage::SerializedMessage ( SerializedMessage &&  )
defaultnoexcept

Move constructor (defaulted).

◆ SerializedMessage() [3/3]

irsol::protocol::internal::SerializedMessage::SerializedMessage ( const SerializedMessage )
delete

Deleted copy constructor to prevent copying.

Member Function Documentation

◆ hasHeader()

bool irsol::protocol::internal::SerializedMessage::hasHeader ( ) const

Checks whether the serialized message contains a non-empty header.

Returns
true if the header string is not empty, false otherwise.

Definition at line 16 of file serialized_message.cpp.

17{
18 return header.size() > 0;
19}

◆ hasPayload()

bool irsol::protocol::internal::SerializedMessage::hasPayload ( ) const

Checks whether the serialized message contains a non-empty payload.

Returns
true if the payload vector is not empty, false otherwise.

Definition at line 22 of file serialized_message.cpp.

23{
24 return payloadSize() > 0;
25}
size_t payloadSize() const
Returns the size of the payload in bytes.

◆ operator=() [1/2]

SerializedMessage & irsol::protocol::internal::SerializedMessage::operator= ( const SerializedMessage )
delete

Deleted copy assignment operator to prevent copying.

◆ operator=() [2/2]

SerializedMessage & irsol::protocol::internal::SerializedMessage::operator= ( SerializedMessage &&  )
defaultnoexcept

Move assignment operator (defaulted).

◆ payloadSize()

size_t irsol::protocol::internal::SerializedMessage::payloadSize ( ) const

Returns the size of the payload in bytes.

Returns
The number of bytes stored in the payload.

Definition at line 28 of file serialized_message.cpp.

29{
30 return payload.size();
31}

◆ toString()

std::string irsol::protocol::internal::SerializedMessage::toString ( ) const

Converts the serialized message to a string representation.

This method typically returns a human-readable form of the serialized message, possibly concatenating the header and a textual form of the payload.

Returns
A string representation of the serialized message.

Definition at line 33 of file serialized_message.cpp.

34{
35 std::ostringstream oss;
36 oss << "SerializedMessage{"
37 << "header: '" << header << "'";
38 if(hasPayload()) {
39 oss << ", payload size: " << payload.size() << "bytes";
40 } else {
41 oss << ", no payload";
42 }
43 oss << "}";
44 return oss.str();
45}
bool hasPayload() const
Checks whether the serialized message contains a non-empty payload.

Member Data Documentation

◆ header

std::string irsol::protocol::internal::SerializedMessage::header

The textual header of the serialized message.

This string typically contains the message type and metadata in a human-readable format.

Definition at line 49 of file serialized_message.hpp.

◆ payload

std::vector<irsol::types::byte_t> irsol::protocol::internal::SerializedMessage::payload {}

The binary payload of the serialized message.

This vector contains the binary data part of the message, following the header.

Definition at line 56 of file serialized_message.hpp.

56{};

The documentation for this struct was generated from the following files: