Core Library 1.7.0.0 Library containing core utilities and tools for threading, networking, logging, INI and CSV file management etc.

Public Member Functions | Private Attributes | List of all members
core_lib::asio::messages::MessageBuilder Class Referencefinal

Default message builder class. More...

`#include <MessageUtils.h>`

## Public Member Functions
| MessageBuilder ()=default
| Default constructor.
| MessageBuilder (const std::string &magicString)
| Initialisatn constructor. More...
| ~MessageBuilder ()=default
| Default destructor.
| MessageBuilder (const MessageBuilder &)=default
| Default copy constructor.
MessageBuilder & | operator= (const MessageBuilder &)=default
| Default copy assignment operator.
| MessageBuilder (MessageBuilder &&)=default
| Default move constructor.
MessageBuilder & | operator= (MessageBuilder &&)=default
| Default move assignment operator.
defs::char_buffer_t const & | Build (int32_t messageId, const defs::connection_t &responseAddress) const
| Build message method for header only messages. More...
defs::char_buffer_t const & | Build (const defs::char_buffer_t &message, int32_t messageId, const defs::connection_t &responseAddress, defs::eArchiveType archiveType=defs::eArchiveType::raw) const
| Build message method for header plus buffer. More...
defs::char_buffer_t const & | Build (const void *message, size_t messageLength, int32_t messageId, const defs::connection_t &responseAddress, defs::eArchiveType archiveType=defs::eArchiveType::raw) const
| Build message method for header plus buffer. More...
template<typename T , typename A >
defs::char_buffer_t const & | Build (const T &message, int32_t messageId, const defs::connection_t &responseAddress) const
| Build message method for header + messaage body messages. More...

## Private Attributes
std::string | m_magicString {static_cast<char const*>(defs::DEFAULT_MAGIC_STRING)}
| Magic string.
defs::char_buffer_t | m_messageBuffer
defs::char_buffer_t | m_serialisationBuffer

## Detailed Description

Default message builder class.

This is used in the case of the simple network classes: SimpleTcpClient, SimpleTcpServer etc. It is used to build messages to be sent that require a MessageHeader followed by a message body.

## Constructor & Destructor Documentation

## ◆ MessageBuilder()

core_lib::asio::messages::MessageBuilder::MessageBuilder | ( | const std::string & | magicString | ) |
| explicit

Initialisatn constructor.

Parameters

  [in] | magicString | - Magic stirng used to identify start of valid message.

## Member Function Documentation

## ◆ Build() [1/4]

auto core_lib::asio::messages::MessageBuilder::Build | ( | int32_t | messageId,
|  | const defs::connection_t & | responseAddress
| ) |  | const

Build message method for header only messages.

Parameters

  [in] | messageId | - Unique ID for this message instance.
  [in] | responseAddress | - Connection object describing sender's response address and port.

Returns
  A const reference to a filled message buffer.

Sometimes network messages don't require a message body to be sent just some header information such as a command to possibly request some data in response. In this case we invoke this Build method.

## ◆ Build() [2/4]

auto core_lib::asio::messages::MessageBuilder::Build | ( | const defs::char_buffer_t & | message,
|  | int32_t | messageId,
|  | const defs::connection_t & | responseAddress,
|  | defs::eArchiveType | archiveType = `defs::eArchiveType::raw`
| ) |  | const

Build message method for header plus buffer.

Parameters

  [in] | message | - Message buffer created outside of the message builder.
  [in] | messageId | - Unique ID for this message instance.
  [in] | responseAddress | - Connection object describing sender's response address and port.
  [in] | archiveType | - Archive type used to when creating the messageBuffer.

Returns
  A const reference to a filled message buffer.

## ◆ Build() [3/4]

auto core_lib::asio::messages::MessageBuilder::Build | ( | const void * | message,
|  | size_t | messageLength,
|  | int32_t | messageId,
|  | const defs::connection_t & | responseAddress,
|  | defs::eArchiveType | archiveType = `defs::eArchiveType::raw`
| ) |  | const

Build message method for header plus buffer.

Parameters

  [in] | message | - Start of message buffer created outside of the message builder.
  [in] | messageLength | - Length of the message buffer in bytes.
  [in] | messageId | - Unique ID for this message instance.
  [in] | responseAddress | - Connection object describing sender's response address and port.
  [in] | archiveType | - Archive type used to when creating the messageBuffer.

Returns
  A const reference to a filled message buffer.

## ◆ Build() [4/4]

template<typename T , typename A >

defs::char_buffer_t const& core_lib::asio::messages::MessageBuilder::Build | ( | const T & | message,
|  | int32_t | messageId,
|  | const defs::connection_t & | responseAddress
| ) |  | const
| inline

Build message method for header + messaage body messages.

Parameters

  [in] | message | - Object to be sent as message body, to be serialized as chosen archive type
  [in] | messageId | - Unique ID for this message instance.
  [in] | responseAddress | - Connection opject describing sender's response address and port.

Returns
  A const reference to a filled message buffer.

The first template argument T defines the message object's type. The second template argument A defines the archive type for serialization.

Invoke thid overload of the Build function when a message comprising a header and body is to be sent.

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

- D:/Projects/CoreLibrary/Include/Asio/MessageUtils.h
- D:/Projects/CoreLibrary/Source/Asio/MessageUtils.cpp