IRSOL
C++ code implementing socket server for interacting with Baumer camera.
Protocol

Comprehensive structured types, utilities, and mechanisms for irsol protocol message exchange. More...

Files

file  assignment.hpp
 Protocol assignment operation representation.
 
file  binary.hpp
 Protocol binary data types and attributes definitions.
 
file  command.hpp
 Protocol command representation.
 
file  error.hpp
 Protocol error message representation.
 
file  inquiry.hpp
 Protocol inquiry representation.
 
file  success.hpp
 Protocol success message representation.
 
file  variants.hpp
 Definitions and utilities for incoming and outgoing protocol messages.
 
file  parser.hpp
 Parses raw protocol input strings into structured messages.
 
file  parser_result.hpp
 Encapsulates the result of a protocol parsing operation.
 
file  serialized_message.hpp
 Defines the SerializedMessage structure representing serialized protocol messages.
 
file  serializer.hpp
 Serialization utilities for protocol messages and primitive values.
 

Namespaces

namespace  irsol::protocol
 Core protocol message types, serialization, parsing, and communication utilities for the irsol framework.
 

Classes

struct  irsol::protocol::Assignment
 Represents an assignment operation in the protocol. More...
 
struct  irsol::protocol::BinaryDataAttribute
 Represents a single binary data attribute within the protocol. More...
 
struct  irsol::protocol::internal::BinaryDataBufferName< N >
 Helper to get a descriptive name for binary data buffers by dimensionality. More...
 
struct  irsol::protocol::internal::BinaryData< NBytes, N >
 Represents a binary data object within the protocol. More...
 
struct  irsol::protocol::Command
 Represents a command invocation in the protocol. More...
 
struct  irsol::protocol::Error
 Represents an error response message from the server. More...
 
struct  irsol::protocol::Inquiry
 Represents a value inquiry in the protocol. More...
 
struct  irsol::protocol::Success
 Represents a success response message from the server. More...
 
class  irsol::protocol::Parser
 Parses raw input strings into structured InMessage instances. More...
 
class  irsol::protocol::internal::ParserResult< T, >
 Wrapper for the result of a protocol parsing attempt. More...
 
struct  irsol::protocol::internal::SerializedMessage
 Represents a serialized protocol message with header and payload. More...
 
class  irsol::protocol::Serializer
 Serializes outgoing protocol messages and primitive values. More...
 

Typedefs

using irsol::protocol::BinaryDataBuffer = internal::BinaryData< 2, 1 >
 1-dimensional binary data buffer with 2 bytes per element.
 
using irsol::protocol::ImageBinaryData = internal::BinaryData< 2, 2 >
 2-dimensional binary data buffer with 2 bytes per element (e.g., grayscale images).
 
using irsol::protocol::ColorImageBinaryData = internal::BinaryData< 2, 3 >
 3-dimensional binary data buffer with 2 bytes per element (e.g., color images).
 
using irsol::protocol::InMessage = std::variant< Assignment, Inquiry, Command >
 Variant type representing any incoming message.
 
using irsol::protocol::OutMessage = std::variant< Success, BinaryDataBuffer, ImageBinaryData, ColorImageBinaryData, Error >
 Variant type representing any outgoing message.
 

Enumerations

enum class  irsol::protocol::InMessageKind { irsol::protocol::InMessageKind::ASSIGNMENT , irsol::protocol::InMessageKind::INQUIRY , irsol::protocol::InMessageKind::COMMAND }
 Represents the type of an incoming message. More...
 
enum class  irsol::protocol::OutMessageKind {
  irsol::protocol::OutMessageKind::SUCCESS , irsol::protocol::OutMessageKind::BINARY_BUFFER , irsol::protocol::OutMessageKind::BW_IMAGE , irsol::protocol::OutMessageKind::COLOR_IMAGE ,
  irsol::protocol::OutMessageKind::ERROR
}
 Represents the type of an outgoing message. More...
 

Functions

constexpr const char * irsol::protocol::InMessageKindToString (InMessageKind kind)
 Converts an InMessageKind enum to a human-readable string.
 
constexpr const char * irsol::protocol::OutMessageKindToString (OutMessageKind kind)
 Converts an OutMessageKind enum to a human-readable string.
 
std::string irsol::protocol::toString (const InMessage &msg)
 Converts an incoming message variant to a human-readable string.
 
std::string irsol::protocol::toString (const OutMessage &msg)
 Converts an outgoing message variant to a human-readable string.
 
template<typename T , std::enable_if_t< irsol::traits::is_type_in_variant_v< T, InMessage >, int > = 0>
constexpr InMessageKind irsol::protocol::getInMessageKind (IRSOL_MAYBE_UNUSED const T &msg)
 Returns the InMessageKind enum value corresponding to a given incoming message type.
 
InMessageKind irsol::protocol::getInMessageKind (const InMessage &msg)
 Returns the InMessageKind enum value for a given incoming message variant.
 
template<typename T , std::enable_if_t< irsol::traits::is_type_in_variant_v< T, InMessage >, int > = 0>
constexpr bool irsol::protocol::isAssignment (IRSOL_MAYBE_UNUSED T &msg)
 Checks if a given incoming message type is an Assignment.
 
template<typename T , std::enable_if_t< irsol::traits::is_type_in_variant_v< T, InMessage >, int > = 0>
constexpr bool irsol::protocol::isInquiry (IRSOL_MAYBE_UNUSED T &msg)
 Checks if a given incoming message type is an Inquiry.
 
template<typename T , std::enable_if_t< irsol::traits::is_type_in_variant_v< T, InMessage >, int > = 0>
constexpr bool irsol::protocol::isCommand (IRSOL_MAYBE_UNUSED T &msg)
 Checks if a given incoming message type is a Command.
 
template<typename T , std::enable_if_t< irsol::traits::is_type_in_variant_v< T, OutMessage >, int > = 0>
constexpr OutMessageKind irsol::protocol::getOutMessageKind (IRSOL_MAYBE_UNUSED const T &msg)
 Returns the OutMessageKind enum value corresponding to a given outgoing message type.
 
OutMessageKind irsol::protocol::getOutMessageKind (const OutMessage &msg)
 Returns the OutMessageKind enum value for a given outgoing message variant.
 
template<typename T , std::enable_if_t< irsol::traits::is_type_in_variant_v< T, OutMessage >, int > = 0>
constexpr bool irsol::protocol::isSuccess (IRSOL_MAYBE_UNUSED T &msg)
 Checks if a given outgoing message type is Success.
 
template<typename T , std::enable_if_t< irsol::traits::is_type_in_variant_v< T, OutMessage >, int > = 0>
constexpr bool irsol::protocol::isBinaryDataBuffer (IRSOL_MAYBE_UNUSED T &msg)
 Checks if a given outgoing message type is BinaryDataBuffer.
 
template<typename T , std::enable_if_t< irsol::traits::is_type_in_variant_v< T, OutMessage >, int > = 0>
constexpr bool irsol::protocol::isImageBinaryData (IRSOL_MAYBE_UNUSED T &msg)
 Checks if a given outgoing message type is ImageBinaryData (black & white).
 
template<typename T , std::enable_if_t< irsol::traits::is_type_in_variant_v< T, OutMessage >, int > = 0>
constexpr bool irsol::protocol::isColorImageBinaryData (IRSOL_MAYBE_UNUSED T &msg)
 Checks if a given outgoing message type is ColorImageBinaryData.
 
template<typename T , std::enable_if_t< irsol::traits::is_type_in_variant_v< T, OutMessage >, int > = 0>
constexpr bool irsol::protocol::isError (IRSOL_MAYBE_UNUSED T &msg)
 Checks if a given outgoing message type is Error.
 

Detailed Description

Comprehensive structured types, utilities, and mechanisms for irsol protocol message exchange.

The Protocol module encompasses the core abstractions and tools that define, handle, and facilitate client-server communication in the irsol framework.

This includes:

This module is designed with maintainability and extensibility in mind, enabling the protocol to evolve without breaking existing communication contracts.

Typedef Documentation

◆ BinaryDataBuffer

1-dimensional binary data buffer with 2 bytes per element.

Definition at line 196 of file binary.hpp.

◆ ColorImageBinaryData

3-dimensional binary data buffer with 2 bytes per element (e.g., color images).

Definition at line 208 of file binary.hpp.

◆ ImageBinaryData

2-dimensional binary data buffer with 2 bytes per element (e.g., grayscale images).

Definition at line 202 of file binary.hpp.

◆ InMessage

using irsol::protocol::InMessage = typedef std::variant<Assignment, Inquiry, Command>

Variant type representing any incoming message.

This variant holds one of the possible incoming message types:

Definition at line 86 of file variants.hpp.

◆ OutMessage

Variant type representing any outgoing message.

This variant holds one of the possible outgoing message types:

  • Success
  • BinaryDataBuffer
  • ImageBinaryData (black & white)
  • ColorImageBinaryData
  • Error

Definition at line 148 of file variants.hpp.

Enumeration Type Documentation

◆ InMessageKind

enum class irsol::protocol::InMessageKind
strong

Represents the type of an incoming message.

Incoming messages are categorized into three kinds:

  • ASSIGNMENT: Messages that assign values or configurations.
  • INQUIRY: Messages that request information.
  • COMMAND: Messages that trigger actions.
Enumerator
ASSIGNMENT 
INQUIRY 
COMMAND 

Definition at line 44 of file variants.hpp.

◆ OutMessageKind

Represents the type of an outgoing message.

Outgoing messages are categorized into:

  • SUCCESS: Acknowledgement of successful operation.
  • BINARY_BUFFER: Raw binary data payload.
  • BW_IMAGE: Black & White image data.
  • COLOR_IMAGE: Color image data.
  • ERROR: Error message.
Enumerator
SUCCESS 
BINARY_BUFFER 
BW_IMAGE 
COLOR_IMAGE 
ERROR 

Definition at line 99 of file variants.hpp.

Function Documentation

◆ getInMessageKind() [1/2]

InMessageKind irsol::protocol::getInMessageKind ( const InMessage msg)

Returns the InMessageKind enum value for a given incoming message variant.

Parameters
msgThe incoming message variant.
Returns
The corresponding InMessageKind value.

Definition at line 53 of file variants.cpp.

54{
55 return std::visit(
56 [](auto&& value) -> InMessageKind {
57 using T = std::decay_t<decltype(value)>;
58 return getInMessageKind<T>(value);
59 },
60 msg);
61}
auto value
auto msg

◆ getInMessageKind() [2/2]

template<typename T , std::enable_if_t< irsol::traits::is_type_in_variant_v< T, InMessage >, int > = 0>
constexpr InMessageKind irsol::protocol::getInMessageKind ( IRSOL_MAYBE_UNUSED const T &  msg)
constexpr

Returns the InMessageKind enum value corresponding to a given incoming message type.

Template Parameters
TThe concrete incoming message type.
Parameters
msgThe incoming message instance (unused).
Returns
The corresponding InMessageKind value.
Note
This function is constexpr and uses SFINAE to constrain T to be one of the InMessage variant types.

Definition at line 178 of file variants.hpp.

179{
180 if constexpr(std::is_same_v<T, Assignment>)
181 return InMessageKind::ASSIGNMENT;
182 else if constexpr(std::is_same_v<T, Inquiry>)
183 return InMessageKind::INQUIRY;
184 else if constexpr(std::is_same_v<T, Command>)
185 return InMessageKind::COMMAND;
186 else
187 IRSOL_MISSING_TEMPLATE_SPECIALIZATION(T, "getInMessageKind()");
188}
#define IRSOL_MISSING_TEMPLATE_SPECIALIZATION(T, funcNameLiteral)
Emits a compile-time error when no template specialization is available.
Definition macros.hpp:173

◆ getOutMessageKind() [1/2]

OutMessageKind irsol::protocol::getOutMessageKind ( const OutMessage msg)

Returns the OutMessageKind enum value for a given outgoing message variant.

Parameters
msgThe outgoing message variant.
Returns
The corresponding OutMessageKind value.

Definition at line 82 of file variants.cpp.

83{
84 return std::visit(
85 [](auto&& value) -> OutMessageKind {
86 using T = std::decay_t<decltype(value)>;
87 return getOutMessageKind<T>(value);
88 },
89 msg);
90}

◆ getOutMessageKind() [2/2]

template<typename T , std::enable_if_t< irsol::traits::is_type_in_variant_v< T, OutMessage >, int > = 0>
constexpr OutMessageKind irsol::protocol::getOutMessageKind ( IRSOL_MAYBE_UNUSED const T &  msg)
constexpr

Returns the OutMessageKind enum value corresponding to a given outgoing message type.

Template Parameters
TThe concrete outgoing message type.
Parameters
msgThe outgoing message instance (unused).
Returns
The corresponding OutMessageKind value.
Note
This function is constexpr and uses SFINAE to constrain T to be one of the OutMessage variant types.

Definition at line 254 of file variants.hpp.

255{
256 if constexpr(std::is_same_v<T, Success>)
257 return OutMessageKind::SUCCESS;
258 else if constexpr(std::is_same_v<T, Error>)
259 return OutMessageKind::ERROR;
260 else if constexpr(std::is_same_v<T, BinaryDataBuffer>)
261 return OutMessageKind::BINARY_BUFFER;
262 else if constexpr(std::is_same_v<T, ImageBinaryData>)
263 return OutMessageKind::BW_IMAGE;
264 else if constexpr(std::is_same_v<T, ColorImageBinaryData>)
265 return OutMessageKind::COLOR_IMAGE;
266 else
267 IRSOL_MISSING_TEMPLATE_SPECIALIZATION(T, "getOutMessageKind()");
268}

◆ InMessageKindToString()

constexpr const char * irsol::protocol::InMessageKindToString ( InMessageKind  kind)
constexpr

Converts an InMessageKind enum to a human-readable string.

Parameters
kindThe InMessageKind value to convert.
Returns
A string representation of the given InMessageKind.
Note
This function is constexpr and can be used in compile-time contexts.

Definition at line 59 of file variants.hpp.

60{
61 switch(kind) {
62 case InMessageKind::ASSIGNMENT:
63 return "ASSIGNMENT";
64 case InMessageKind::INQUIRY:
65 return "INQUIRY";
66 case InMessageKind::COMMAND:
67 return "COMMAND";
68 }
70}
#define IRSOL_UNREACHABLE()
Indicates unreachable code to the compiler.
Definition macros.hpp:107

◆ isAssignment()

template<typename T , std::enable_if_t< irsol::traits::is_type_in_variant_v< T, InMessage >, int > = 0>
constexpr bool irsol::protocol::isAssignment ( IRSOL_MAYBE_UNUSED T &  msg)
constexpr

Checks if a given incoming message type is an Assignment.

Template Parameters
TThe concrete incoming message type.
Parameters
msgThe incoming message instance.
Returns
True if T is Assignment, false otherwise.

Definition at line 207 of file variants.hpp.

208{
209 return std::is_same_v<T, Assignment>;
210}

◆ isBinaryDataBuffer()

template<typename T , std::enable_if_t< irsol::traits::is_type_in_variant_v< T, OutMessage >, int > = 0>
constexpr bool irsol::protocol::isBinaryDataBuffer ( IRSOL_MAYBE_UNUSED T &  msg)
constexpr

Checks if a given outgoing message type is BinaryDataBuffer.

Template Parameters
TThe concrete outgoing message type.
Parameters
msgThe outgoing message instance.
Returns
True if T is BinaryDataBuffer, false otherwise.

Definition at line 302 of file variants.hpp.

303{
304 return std::is_same_v<T, BinaryDataBuffer>;
305}

◆ isColorImageBinaryData()

template<typename T , std::enable_if_t< irsol::traits::is_type_in_variant_v< T, OutMessage >, int > = 0>
constexpr bool irsol::protocol::isColorImageBinaryData ( IRSOL_MAYBE_UNUSED T &  msg)
constexpr

Checks if a given outgoing message type is ColorImageBinaryData.

Template Parameters
TThe concrete outgoing message type.
Parameters
msgThe outgoing message instance.
Returns
True if T is ColorImageBinaryData, false otherwise.

Definition at line 332 of file variants.hpp.

333{
334 return std::is_same_v<T, ColorImageBinaryData>;
335}

◆ isCommand()

template<typename T , std::enable_if_t< irsol::traits::is_type_in_variant_v< T, InMessage >, int > = 0>
constexpr bool irsol::protocol::isCommand ( IRSOL_MAYBE_UNUSED T &  msg)
constexpr

Checks if a given incoming message type is a Command.

Template Parameters
TThe concrete incoming message type.
Parameters
msgThe incoming message instance.
Returns
True if T is Command, false otherwise.

Definition at line 237 of file variants.hpp.

238{
239 return std::is_same_v<T, Command>;
240}

◆ isError()

template<typename T , std::enable_if_t< irsol::traits::is_type_in_variant_v< T, OutMessage >, int > = 0>
constexpr bool irsol::protocol::isError ( IRSOL_MAYBE_UNUSED T &  msg)
constexpr

Checks if a given outgoing message type is Error.

Template Parameters
TThe concrete outgoing message type.
Parameters
msgThe outgoing message instance.
Returns
True if T is Error, false otherwise.

Definition at line 347 of file variants.hpp.

348{
349 return std::is_same_v<T, Error>;
350}

◆ isImageBinaryData()

template<typename T , std::enable_if_t< irsol::traits::is_type_in_variant_v< T, OutMessage >, int > = 0>
constexpr bool irsol::protocol::isImageBinaryData ( IRSOL_MAYBE_UNUSED T &  msg)
constexpr

Checks if a given outgoing message type is ImageBinaryData (black & white).

Template Parameters
TThe concrete outgoing message type.
Parameters
msgThe outgoing message instance.
Returns
True if T is ImageBinaryData, false otherwise.

Definition at line 317 of file variants.hpp.

318{
319 return std::is_same_v<T, ImageBinaryData>;
320}

◆ isInquiry()

template<typename T , std::enable_if_t< irsol::traits::is_type_in_variant_v< T, InMessage >, int > = 0>
constexpr bool irsol::protocol::isInquiry ( IRSOL_MAYBE_UNUSED T &  msg)
constexpr

Checks if a given incoming message type is an Inquiry.

Template Parameters
TThe concrete incoming message type.
Parameters
msgThe incoming message instance.
Returns
True if T is Inquiry, false otherwise.

Definition at line 222 of file variants.hpp.

223{
224 return std::is_same_v<T, Inquiry>;
225}

◆ isSuccess()

template<typename T , std::enable_if_t< irsol::traits::is_type_in_variant_v< T, OutMessage >, int > = 0>
constexpr bool irsol::protocol::isSuccess ( IRSOL_MAYBE_UNUSED T &  msg)
constexpr

Checks if a given outgoing message type is Success.

Template Parameters
TThe concrete outgoing message type.
Parameters
msgThe outgoing message instance.
Returns
True if T is Success, false otherwise.

Definition at line 287 of file variants.hpp.

288{
289 return std::is_same_v<T, Success>;
290}

◆ OutMessageKindToString()

constexpr const char * irsol::protocol::OutMessageKindToString ( OutMessageKind  kind)
constexpr

Converts an OutMessageKind enum to a human-readable string.

Parameters
kindThe OutMessageKind value to convert.
Returns
A string representation of the given OutMessageKind.
Note
This function is constexpr and can be used in compile-time contexts.

Definition at line 116 of file variants.hpp.

117{
118 switch(kind) {
119 case OutMessageKind::SUCCESS:
120 return "SUCCESS";
121 case OutMessageKind::BINARY_BUFFER:
122 return "BINARY_BUFFER";
123 case OutMessageKind::BW_IMAGE:
124 return "BW_IMAGE";
125 case OutMessageKind::COLOR_IMAGE:
126 return "COLOR_IMAGE";
127 case OutMessageKind::ERROR:
128 return "ERROR";
129 }
131}

◆ toString() [1/2]

std::string irsol::protocol::toString ( const InMessage msg)

Converts an incoming message variant to a human-readable string.

Parameters
msgThe incoming message variant.
Returns
A string representation of the contained message.

Definition at line 19 of file variants.cpp.

20{
21 if(isAssignment(msg)) {
22 return std::get<Assignment>(msg).toString();
23 } else if(isInquiry(msg)) {
24 return std::get<Inquiry>(msg).toString();
25 } else if(isCommand(msg)) {
26 return std::get<Command>(msg).toString();
27 } else {
28 IRSOL_ASSERT_FALSE("Unknown in message type");
29 throw std::invalid_argument("Unknown in message type");
30 }
31}
#define IRSOL_ASSERT_FALSE(message)
Assertion macro that always fails fatally.
Definition assert.hpp:136
constexpr bool isCommand(IRSOL_MAYBE_UNUSED T &msg)
Checks if a given incoming message type is a Command.
Definition variants.hpp:237
constexpr bool isInquiry(IRSOL_MAYBE_UNUSED T &msg)
Checks if a given incoming message type is an Inquiry.
Definition variants.hpp:222
constexpr bool isAssignment(IRSOL_MAYBE_UNUSED T &msg)
Checks if a given incoming message type is an Assignment.
Definition variants.hpp:207

◆ toString() [2/2]

std::string irsol::protocol::toString ( const OutMessage msg)

Converts an outgoing message variant to a human-readable string.

Parameters
msgThe outgoing message variant.
Returns
A string representation of the contained message.

Definition at line 34 of file variants.cpp.

35{
36 if(isSuccess(msg)) {
37 return std::get<Success>(msg).toString();
38 } else if(isError(msg)) {
39 return std::get<Error>(msg).toString();
40 } else if(isBinaryDataBuffer(msg)) {
41 return std::get<BinaryDataBuffer>(msg).toString();
42 } else if(isImageBinaryData(msg)) {
43 return std::get<ImageBinaryData>(msg).toString();
44 } else if(isColorImageBinaryData(msg)) {
45 return std::get<ColorImageBinaryData>(msg).toString();
46 } else {
47 IRSOL_ASSERT_FALSE("Unknown out message type");
48 throw std::invalid_argument("Unknown out message type");
49 }
50}
constexpr bool isError(IRSOL_MAYBE_UNUSED T &msg)
Checks if a given outgoing message type is Error.
Definition variants.hpp:347
constexpr bool isSuccess(IRSOL_MAYBE_UNUSED T &msg)
Checks if a given outgoing message type is Success.
Definition variants.hpp:287
constexpr bool isColorImageBinaryData(IRSOL_MAYBE_UNUSED T &msg)
Checks if a given outgoing message type is ColorImageBinaryData.
Definition variants.hpp:332
constexpr bool isBinaryDataBuffer(IRSOL_MAYBE_UNUSED T &msg)
Checks if a given outgoing message type is BinaryDataBuffer.
Definition variants.hpp:302
constexpr bool isImageBinaryData(IRSOL_MAYBE_UNUSED T &msg)
Checks if a given outgoing message type is ImageBinaryData (black & white).
Definition variants.hpp:317