13internal::SerializedMessage
19 using T = std::decay_t<
decltype(
msg)>;
20 return serialize<T>(std::move(
msg));
29 [](
auto&& val) -> std::string {
30 using T = std::decay_t<
decltype(val)>;
31 return serializeValue<T>(std::move(val));
44 "Body is not present in 'Success' message, created from 'Assignment'. This should "
45 "never happen, as a successful assignment should always provide a body for the "
46 "associated Success message.");
47 auto body = *
msg.body;
51 auto body = *
msg.body;
67 throw std::runtime_error(
"Binary data serialization not supported");
75 std::vector<irsol::types::byte_t> payload;
76 payload.reserve(
msg.data.size() + 128);
79 std::string imagePrefix =
"img=";
81 std::move(imagePrefixAsBytes.begin(), imagePrefixAsBytes.end(), std::back_inserter(payload));
86 ss <<
"u" <<
msg.BYTES_PER_ELEMENT * 8 <<
"[" <<
msg.shape[0] <<
"," <<
msg.shape[1] <<
"]";
87 for(
auto& att :
msg.attributes) {
90 auto attributesString = ss.str();
92 "Attributes for message '{}' serialized to {}",
msg.toString(), attributesString);
95 payload.insert(payload.end(), attributesStringAsBytes.begin(), attributesStringAsBytes.end());
100 size_t dataOffset = payload.size();
101 payload.resize(payload.size() +
msg.data.size());
102 std::memcpy(&payload[dataOffset],
msg.data.data(),
msg.data.size());
107 payload.begin() +
static_cast<std::ptrdiff_t
>(dataOffset), payload.end());
112 return std::move(message);
120 throw std::runtime_error(
"Binary data serialization not supported");
133 std::stringstream ss;
134 ss << att.identifier <<
"=" <<
serializeValue(std::move(att.value));
static std::string serializeBinaryDataAttribute(irsol::protocol::BinaryDataAttribute &&att)
Serialize a irsol::protocol::BinaryDataAttribute to a string.
static internal::SerializedMessage serializeBinaryDataBuffer(BinaryDataBuffer &&msg)
Serializes a irsol::protocol::BinaryDataBuffer message to a binary protocol message.
static internal::SerializedMessage serializeImageBinaryData(ImageBinaryData &&msg)
Serializes a irsol::protocol::ImageBinaryData message to a binary protocol message.
static constexpr const char * message_termination
Message line termination sequence (newline character) used to "close" a serialized message.
static std::string serializeValue(irsol::types::protocol_value_t &&value)
Serialize a protocol primitive value to a string.
static internal::SerializedMessage serializeColorImageBinaryData(ColorImageBinaryData &&msg)
Serializes a irsol::protocol::ColorImageBinaryData message to a binary protocol message.
static internal::SerializedMessage serialize(OutMessage &&msg)
Serialize an irsol::protocol::OutMessage variant into a serialized protocol message.
static internal::SerializedMessage serializeError(Error &&msg)
Serializes a irsol::protocol::Error message to a binary protocol message.
static internal::SerializedMessage serializeSuccess(Success &&msg)
Serializes a irsol::protocol::Success message to a binary protocol message.
#define IRSOL_ASSERT_ERROR
Error-level assertion macro.
#define IRSOL_LOG_DEBUG(...)
Logs a debug-level message using the default logger.
#define IRSOL_LOG_TRACE(...)
Logs a trace-level message using the default logger.
std::variant< Success, BinaryDataBuffer, ImageBinaryData, ColorImageBinaryData, Error > OutMessage
Variant type representing any outgoing message.
Logging utilities and configuration for the irsol library.
std::variant< int, double, std::string > protocol_value_t
Variant type representing protocol values that can be one of several types.
std::vector< irsol::types::byte_t > stringToBytes(const std::string &s)
Converts a std::string to a std::vector of irsol::types::byte_t.
Utility functions for protocol string handling and validation in the irsol library.
Serialization utilities for protocol messages and primitive values.
Utility for swapping pixel bytes in a buffer.
Represents a single binary data attribute within the protocol.
Represents an error response message from the server.
static constexpr irsol::types::byte_t SOH
Start of Header (SOH) byte: 0x01.
static constexpr irsol::types::byte_t STX
Start of Text (STX) byte: 0x02.
static constexpr irsol::types::byte_t ETX
End of Text (ETX) byte: 0x03.
Represents a success response message from the server.
Represents a binary data object within the protocol.
Represents a serialized protocol message with header and payload.
General utility functions used throughout the irsol library.