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

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

Namespaces

namespace  internal
 
namespace  utils
 Utility functions for string manipulation and validation.
 

Classes

struct  Assignment
 Represents an assignment operation in the protocol. More...
 
struct  BinaryDataAttribute
 Represents a single binary data attribute within the protocol. More...
 
struct  Command
 Represents a command invocation in the protocol. More...
 
struct  Error
 Represents an error response message from the server. More...
 
struct  Inquiry
 Represents a value inquiry in the protocol. More...
 
class  Parser
 Parses raw input strings into structured InMessage instances. More...
 
class  Serializer
 Serializes outgoing protocol messages and primitive values. More...
 
struct  Success
 Represents a success response message from the server. More...
 

Typedefs

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

Enumerations

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

Functions

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

Detailed Description

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

The irsol::protocol namespace encapsulates all components related to the structured communication protocol between clients and servers within the irsol ecosystem.

Key responsibilities and features include:

  • Message Representations: Defines strongly typed C++ structures representing protocol messages, including incoming commands, outgoing responses, errors, and data payloads.
  • Tagged Variants: Groups related message types using std::variant or similar tagged unions to enable type-safe polymorphism for incoming and outgoing messages.
  • Serialization and Deserialization: Provides classes and functions to serialize protocol messages and primitive protocol values into wire-format strings or binary buffers, and to parse raw input into strongly typed message instances.
  • Protocol Traits and Type Introspection: Supplies compile-time traits to check if a type is part of a message variant, facilitating generic programming and template dispatch.
  • Parsing Utilities: Implements parsers that consume raw input data, producing parse trees or structured message objects, supporting validation and error reporting.
  • Communication Primitives: Defines low-level constructs such as special byte constants (e.g., SOH, STX, ETX), message delimiters, and framing conventions consistent with the Simple Communication Protocol employed by irsol.
  • Logging and Debugging Support: Converts protocol messages and events into human-readable string representations for logging, diagnostics, and tracing.
  • Extensibility and Maintenance: Designed with clear separation of concerns and compile-time safety to allow future protocol message extensions, new message types, or serialization formats without compromising existing codebases.

Together, these features enable robust, efficient, and maintainable communication handling in client-server interactions, ensuring interoperability and clear semantics across the irsol system.

Note
Most message and utility types are contained in sub-namespaces such as internal for implementation details, and traits for type traits.

Function Documentation

◆ isAssignment()

bool irsol::protocol::isAssignment ( const InMessage msg)

Definition at line 64 of file variants.cpp.

65{
66 return getInMessageKind(msg) == InMessageKind::ASSIGNMENT;
67}
constexpr InMessageKind getInMessageKind(IRSOL_MAYBE_UNUSED const T &msg)
Returns the InMessageKind enum value corresponding to a given incoming message type.
Definition variants.hpp:178
auto msg

◆ isBinaryDataBuffer()

bool irsol::protocol::isBinaryDataBuffer ( const OutMessage msg)

Definition at line 99 of file variants.cpp.

100{
101 return getOutMessageKind(msg) == OutMessageKind::BINARY_BUFFER;
102}
constexpr OutMessageKind getOutMessageKind(IRSOL_MAYBE_UNUSED const T &msg)
Returns the OutMessageKind enum value corresponding to a given outgoing message type.
Definition variants.hpp:254

◆ isColorImageBinaryData()

bool irsol::protocol::isColorImageBinaryData ( const OutMessage msg)

Definition at line 111 of file variants.cpp.

112{
113 return getOutMessageKind(msg) == OutMessageKind::COLOR_IMAGE;
114}

◆ isCommand()

bool irsol::protocol::isCommand ( const InMessage msg)

Definition at line 76 of file variants.cpp.

77{
78 return getInMessageKind(msg) == InMessageKind::COMMAND;
79}

◆ isError()

bool irsol::protocol::isError ( const OutMessage msg)

Definition at line 116 of file variants.cpp.

117{
118 return getOutMessageKind(msg) == OutMessageKind::ERROR;
119}

◆ isImageBinaryData()

bool irsol::protocol::isImageBinaryData ( const OutMessage msg)

Definition at line 105 of file variants.cpp.

106{
107 return getOutMessageKind(msg) == OutMessageKind::BW_IMAGE;
108}

◆ isInquiry()

bool irsol::protocol::isInquiry ( const InMessage msg)

Definition at line 70 of file variants.cpp.

71{
72 return getInMessageKind(msg) == InMessageKind::INQUIRY;
73}

◆ isSuccess()

bool irsol::protocol::isSuccess ( const OutMessage msg)

Definition at line 93 of file variants.cpp.

94{
95 return getOutMessageKind(msg) == OutMessageKind::SUCCESS;
96}