IRSOL
C++ code implementing socket server for interacting with Baumer camera.
serialized_message.cpp
Go to the documentation of this file.
2
3#include <sstream>
4
5namespace irsol {
6namespace protocol {
7namespace internal {
8
10 const std::string& header,
11 std::vector<irsol::types::byte_t>&& payload)
12 : header(header), payload(std::move(payload))
13{}
14
15bool
17{
18 return header.size() > 0;
19}
20
21bool
23{
24 return payloadSize() > 0;
25}
26
27size_t
29{
30 return payload.size();
31}
32std::string
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}
46} // namespace internal
47} // namespace protocol
48} // namespace irsol
Defines the SerializedMessage structure representing serialized protocol messages.
std::vector< irsol::types::byte_t > payload
The binary payload of the serialized message.
std::string header
The textual header of the serialized message.
bool hasHeader() const
Checks whether the serialized message contains a non-empty header.
std::string toString() const
Converts the serialized message to a string representation.
size_t payloadSize() const
Returns the size of the payload in bytes.
bool hasPayload() const
Checks whether the serialized message contains a non-empty payload.
SerializedMessage(const std::string &header, std::vector< irsol::types::byte_t > &&payload)
Constructs a SerializedMessage with a header and binary payload.