/** * @file include/ActivMiddleware/ActivBase/MessageBuilder.h * * @brief Header file for the message builder class. */ #if (!defined ACTIV_BASE_MESSAGE_BUILDER_H) #define ACTIV_BASE_MESSAGE_BUILDER_H #include "ActivMiddleware/ActivBase/External.h" #include "ActivMiddleware/ActivBase/MessageHandler.h" #include "ActivMiddleware/ActivBase/StatusCodeException.h" #include "ActivMiddleware/Misc/Base64.h" #include "ActivMiddleware/Misc/MemoryHelper.h" #include ACTIV_BOOST_INCLUDE(integer_traits.hpp) #include ACTIV_BOOST_INCLUDE(move/move.hpp) #include //! Activ namespace. namespace Activ { template class MessageBuilderConstantLengthDispatch; // --------------------------------------------------------------------------------------------------------------------------------- /** * @brief Message builder class. */ class MessageBuilder : public MessageHandler { public: /** * @brief Helper class to reset a MessageBuilder to the MessageBuilder's length at the point of construction. * * Usage: * * ScopedCleanup scopedResetLength(messageBuilder); * if (STATUS_CODE_SUCCESS != messageBuilder.Append(...)) return; * if (STATUS_CODE_SUCCESS != messageBuilder.Append(...)) return; * ... * // Message built successfully. * scopedResetLength.Clear(); */ class ResetLengthHelper { public: /** * @brief Constructor. * * @param messageBuilder */ ResetLengthHelper(MessageBuilder &messageBuilder); /** * @brief Reset length. */ void operator()(); private: MessageBuilder &m_messageBuilder; size_t m_originalLength; }; /** * @brief Default constructor. * * @param initialBufferSize the initial size of the message buffer. * @param shouldAdjustBufferSize indicates whether the size of the message buffer should be adjusted (if required). * @param messageVersion optional version. * * @throw StatusCodeException */ MessageBuilder(const size_t initialBufferSize = 0, const bool shouldAdjustBufferSize = true, const MessageVersion messageVersion = MESSAGE_VERSION_UNDEFINED) : MessageHandler(messageVersion), m_pBuffer(ACTIV_NULLPTR), m_bufferSize(0), m_pTail(0), m_pBufferEnd(0), m_shouldAdjustBufferSize(shouldAdjustBufferSize), m_pStaticBuffer(ACTIV_NULLPTR), m_staticBufferSize(0) { if (0 != initialBufferSize) { ACTIV_THROW_RESULT_IF(STATUS_CODE_SUCCESS, != , AdjustBufferSize(initialBufferSize)); } } /** * @brief Constructor. * * @param pBuffer the address of the message buffer. * @param bufferSize the size of the message buffer. * @param shouldAdjustBufferSize indicates whether the size of the message buffer should be adjusted (if required). * @param messageVersion optional version. */ MessageBuilder(void * const pBuffer, const size_t bufferSize, const bool shouldAdjustBufferSize = true, const MessageVersion messageVersion = MESSAGE_VERSION_UNDEFINED) : MessageHandler(messageVersion), m_pBuffer(static_cast(pBuffer)), m_bufferSize(bufferSize), m_pTail(m_pBuffer), m_pBufferEnd(m_pBuffer + m_bufferSize), m_shouldAdjustBufferSize(shouldAdjustBufferSize), m_pStaticBuffer(pBuffer), m_staticBufferSize(bufferSize) { } /** * @brief Copy constructor. * * @param rhs the value to assign to this object. * * @throw StatusCodeException */ MessageBuilder(const MessageBuilder &rhs) : MessageHandler(rhs.GetMessageVersion()), m_pBuffer(ACTIV_NULLPTR), m_bufferSize(0), m_pTail(0), m_pBufferEnd(0), m_shouldAdjustBufferSize(rhs.m_shouldAdjustBufferSize), m_pStaticBuffer(ACTIV_NULLPTR), m_staticBufferSize(0) { ACTIV_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, InternalAppendBuffer(rhs.GetMessage(), rhs.GetLength())); } /** * @brief Move constructor. * * @param rhs the value to move to this object. */ MessageBuilder(ACTIV_BOOST_RV_REF(MessageBuilder) rhs) : MessageHandler(rhs.GetMessageVersion()), m_pBuffer(rhs.m_pBuffer), m_bufferSize(rhs.m_bufferSize), m_pTail(rhs.m_pTail), m_pBufferEnd(rhs.m_pBufferEnd), m_shouldAdjustBufferSize(rhs.m_shouldAdjustBufferSize), m_pStaticBuffer(rhs.m_pStaticBuffer), m_staticBufferSize(rhs.m_staticBufferSize) { rhs.Uninitialize(); } //! Destructor. ~MessageBuilder(); /** * @brief Addition operator. * * @param rhs the value to add to this object. * * @return a reference to this object. * * @throw StatusCodeException */ const MessageBuilder operator+(const MessageBuilder &rhs) const; /** * @brief Addition assignment operator. * * @param rhs the value to add to this object. * * @return a reference to this object. * * @throw StatusCodeException */ MessageBuilder &operator+=(const MessageBuilder &rhs); /** * @brief Copy assignment operator. * * @param rhs the value to assign to this object. * * @return a reference to this object. * * @throw StatusCodeException */ MessageBuilder &operator=(ACTIV_BOOST_COPY_ASSIGN_REF(MessageBuilder) rhs) { if (this != &rhs) { ACTIV_THROW_RESULT_IF(STATUS_CODE_SUCCESS, != , SetLength(0)); ACTIV_THROW_RESULT_IF(STATUS_CODE_SUCCESS, != , InternalAppendBuffer(rhs.GetMessage(), rhs.GetLength())); } return *this; } /** * @brief Move assignment operator. * * @param rhs the value to move to this object. * * @return a reference to this object. */ MessageBuilder &operator=(ACTIV_BOOST_RV_REF(MessageBuilder) rhs) { if (this != &rhs) { FreeInternalBuffer(); SetMessageVersion(rhs.GetMessageVersion()); m_pBuffer = rhs.m_pBuffer; m_bufferSize = rhs.m_bufferSize; m_pTail = rhs.m_pTail; m_pBufferEnd = rhs.m_pBufferEnd; m_shouldAdjustBufferSize = rhs.m_shouldAdjustBufferSize; m_pStaticBuffer = rhs.m_pStaticBuffer; m_staticBufferSize = rhs.m_staticBufferSize; rhs.Uninitialize(); } return *this; } /** * @brief Initialize. * * @param initialBufferSize the initial size of the message buffer. * @param shouldAdjustBufferSize indicates whether the size of the message buffer should be adjusted (if required). * @param messageVersion optional version. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_HEAP_EMPTY */ StatusCode Initialize(const size_t initialBufferSize, const bool shouldAdjustBufferSize = true, const MessageVersion messageVersion = MESSAGE_VERSION_UNDEFINED); /** * @brief Initialize. * * @param pBuffer the address of the message buffer. * @param bufferSize the size of the message buffer. * @param shouldAdjustBufferSize indicates whether the size of the message buffer should be adjusted (if required). * @param messageVersion optional version. * * @retval STATUS_CODE_SUCCESS */ StatusCode Initialize(void * const pBuffer, const size_t bufferSize, const bool shouldAdjustBufferSize = true, const MessageVersion messageVersion = MESSAGE_VERSION_UNDEFINED); /** * @brief Reset. * * @param messageVersion optional version. */ void Reset(const MessageVersion messageVersion = MESSAGE_VERSION_UNDEFINED); /** * @brief Get the address of the message. * * @return the address of the message. */ const void *GetMessage() const; /** * @brief Get the length of the message. * * @return the length of the message. */ size_t GetLength() const; /** * @brief Set the length of the message. * * Can be used to truncate a message. * * @param length the length of the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_INVALID_PARAMETER @a length is greater than the current length of the message. */ StatusCode SetLength(const size_t length); /** * @brief Get the message buffer size. * * @return the size of the message buffer. */ size_t GetBufferSize() const; /** * @brief Set the message buffer size. * * The function will fail if the provided size is smaller than the current message length. * * @param bufferSize the size of the message buffer. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ StatusCode SetBufferSize(const size_t bufferSize); /** * @brief Extend the message by a number of bytes. * * This is similar to Append() below, except that you have no control over the bytes appended to the message; they * will be arbitrary as a result of whatever is in the internal buffer. * * @param numberOfBytes number of bytes to append to the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ StatusCode Extend(const size_t numberOfBytes); /** * @brief Append a buffer. * * @param pBuffer the address of the buffer to place in the message. * @param length the length of the buffer to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ StatusCode AppendBuffer(const void * const pBuffer, const size_t length); /** * @brief Format and append a printf-style buffer. * * Note this differs from AppendPrintfString() in that no length is inlined in to the message; the pure formatted * buffer is appended only. * * Note no NUL is appended. * * @param pFormat pointer to a printf-style format string. * @param ... variable arguments for the format string. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ ACTIV_PRINTF_FUNCTION(printf, 2, 3) ACTIV_BASE_API StatusCode AppendPrintf(const char * const pFormat, ...); /** * @brief Format and append a printf-style buffer. * * @param pFormat pointer to a printf-style format string. * @param args variable arguments for the format string. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ ACTIV_PRINTF_FUNCTION(printf, 2, 0) ACTIV_BASE_API StatusCode AppendPrintfV(const char * const pFormat, std::va_list args); /** * @brief Append the contents of another MessageBuilder to this. * * @param messageBuilder * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ StatusCode Append(const MessageBuilder &messageBuilder); /** * @brief Append a byte. * * @param value the byte to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ StatusCode Append(const byte_t value); /** * @brief Append a character. * * @param character the character to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ StatusCode Append(const char character); /** * @brief Append characters. * * @param character the character to place in the message. * @param count the number of character to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ StatusCode AppendCount(const char character, const size_t count); /** * @brief Append a string. * * @param str the string to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ StatusCode Append(const String &str); /** * @brief Append a c-string. * * The terminating nul in @a pStr is not stored in the message. * * @param pStr the string to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ StatusCode Append(const char * const pStr); /** * @brief Format and append a printf-style string. * * Note this differs from AppendPrintf() in that a length is inlined in to the message in a similar vein to * the other string Append()s (and therefore a string appended with this function is deserializable with * MessageValidator::ValidateString()). * * Note no NUL is appended. * * @param pFormat pointer to a printf-style format string. * @param ... variable arguments for the format string. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ ACTIV_PRINTF_FUNCTION(printf, 2, 3) ACTIV_BASE_API StatusCode AppendPrintfString(const char * const pFormat, ...); /** * @brief Append a built-in type. * * ENDIAN the endian to copy the value in. * T is the built-in type. * * @param value the value to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ template StatusCode Append(const T value); /** * @brief Append a built-in type. * * ENDIAN the endian to copy the value in. * T is the built-in type. * * @param value the value to place in the message. * @param size the number of bytes of @a value to append. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER for instance if @a size > sizeof(T). * @retval STATUS_CODE_OUT_OF_RANGE if @a value will not fit in @a size bytes. * @retval STATUS_CODE_HEAP_EMPTY */ template StatusCode Append(const T value, const size_t size); /** * @brief Append a built-in type. * * ENDIAN the endian to copy the value in. * SIZE the number of bytes of @a value to append. * T is the built-in type. * * @param value the value to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER for instance if @a SIZE > sizeof(T). * @retval STATUS_CODE_OUT_OF_RANGE if @a value will not fit in @a SIZE bytes. * @retval STATUS_CODE_HEAP_EMPTY */ template StatusCode Append(const T value); /** * @brief Append a boolean value. * * @param value the boolean value to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ StatusCode AppendBoolean(const bool value); /** * @brief Append a binary stream encoded as base64. * * BASE64_ENCODER the Base64 class to encode with. * * @param pData * @param dataLength * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ template StatusCode AppendBase64(const void * const pData, const size_t dataLength); /** * @brief Append a binary stream encoded as base64. * * BASE64_ENCODER the Base64 class to encode with. * ITERATOR_HELPER is a class that should provide static members size_t GetLength(iterator &) and * void *GetData(iterator &) in order to access the length and data pointer from a buffer iterator. * ITERATOR an iterator to a buffer. * * @param begin iterator to the first buffer. * @param end iterator to passed the last buffer. * @param offset offset within the buffer range begin,end at which to start encoding. * @param dataLength the amount of data starting at offset @a offset within the buffer range to encode. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ template StatusCode AppendBase64(const ITERATOR begin, const ITERATOR end, const size_t offset, const size_t dataLength); /** * @brief Erase a buffer / binary integral value. * * @param offset the offset in the message from which to erase. * @param length the length of the buffer to erase from the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER */ StatusCode Erase(const size_t offset, const size_t length); /** * @brief Insert a buffer. * * @param offset the offset at which to insert in the message. * @param pBuffer the address of the buffer to place in the message. * @param length the length of the buffer to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ StatusCode InsertBuffer(const size_t offset, const void * const pBuffer, const size_t length); /** * @brief Insert a byte. * * @param offset the offset at which to insert in the message. * @param value the value to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ StatusCode Insert(const size_t offset, const byte_t value); /** * @brief Insert a character. * * @param offset the offset at which to insert in the message. * @param character the character to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ StatusCode Insert(const size_t offset, const char character); /** * @brief Insert characters. * * @param offset the offset at which to insert in the message. * @param character the character to place in the message. * @param count the number of characters to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ StatusCode InsertCount(const size_t offset, const char character, const size_t count); /** * @brief Insert a string. * * @param offset the offset at which to insert in the message. * @param str the string to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ StatusCode Insert(const size_t offset, const String &str); /** * @brief Insert a nul terminated string. * * @param offset the offset at which to insert in the message. * @param pStr the string to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ StatusCode Insert(const size_t offset, const char * const pStr); /** * @brief Insert a built-in type. * * ENDIAN the endian to copy the value in. * T is the built-in type. * * @param offset the offset at which to insert in the message. * @param value the value to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ template StatusCode Insert(const size_t offset, const T value); /** * @brief Insert a built-in type. * * ENDIAN the endian to copy the value in. * T is the built-in type. * * @param offset the offset at which to insert in the message. * @param value the value to place in the message. * @param size the number of bytes of @a value to append. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER for instance if @a size > sizeof(T). * @retval STATUS_CODE_OUT_OF_RANGE if @a value will not fit in @a size bytes. * @retval STATUS_CODE_HEAP_EMPTY */ template StatusCode Insert(const size_t offset, const T value, const size_t size); /** * @brief Insert a built-in type. * * ENDIAN the endian to copy the value in. * SIZE the number of bytes of @a value to append. * T is the built-in type. * * @param offset the offset at which to insert in the message. * @param value the value to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER for instance if @a SIZE > sizeof(T). * @retval STATUS_CODE_OUT_OF_RANGE if @a value will not fit in @a SIZE bytes. * @retval STATUS_CODE_HEAP_EMPTY */ template StatusCode Insert(const size_t offset, const T value); /** * @brief Insert a boolean value. * * @param offset the offset at which to insert in the message. * @param value the boolean value to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ StatusCode InsertBoolean(const size_t offset, const bool value); /** * @brief Overwrite a buffer. * * @param offset the offset at which to overwrite in the message. * @param pBuffer the address of the buffer to place in the message. * @param length the length of the buffer to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ StatusCode OverwriteBuffer(const size_t offset, const void * const pBuffer, const size_t length); /** * @brief Overwrite a byte. * * @param offset the offset at which to insert in the message. * @param value the value to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ StatusCode Overwrite(const size_t offset, const byte_t value); /** * @brief Overwrite a character. * * @param offset the offset at which to insert in the message. * @param character the character to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ StatusCode Overwrite(const size_t offset, const char character); /** * @brief Overwrite characters. * * @param offset the offset at which to insert in the message. * @param character the character to place in the message. * @param count the number of character to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ StatusCode OverwriteCount(const size_t offset, const char character, const size_t count); /** * @brief Overwrite a string. * * @param offset the offset at which to overwrite in the message. * @param str the string to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ StatusCode Overwrite(const size_t offset, const String &str); /** * @brief Overwrite a nul terminated string. * * @param offset the offset at which to overwrite in the message. * @param pStr the string to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ StatusCode Overwrite(const size_t offset, const char * const pStr); /** * @brief Overwrite a built-in type. * * ENDIAN the endian to copy the value in. * T is the built-in type. * * @param offset the offset at which to overwrite in the message. * @param value the value to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ template StatusCode Overwrite(const size_t offset, const T value); /** * @brief Overwrite a built-in type. * * ENDIAN the endian to copy the value in. * T is the built-in type. * * @param offset the offset at which to overwrite in the message. * @param value the value to place in the message. * @param size the number of bytes of @a value to append. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER for instance if @a size > sizeof(T). * @retval STATUS_CODE_OUT_OF_RANGE if @a value will not fit in @a size bytes. * @retval STATUS_CODE_HEAP_EMPTY */ template StatusCode Overwrite(const size_t offset, const T value, const size_t size); /** * @brief Overwrite a built-in type. * * ENDIAN the endian to copy the value in. * SIZE the number of bytes of @a value to append. * T is the built-in type. * * @param offset the offset at which to overwrite in the message. * @param value the value to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER for instance if @a SIZE > sizeof(T). * @retval STATUS_CODE_OUT_OF_RANGE if @a value will not fit in @a SIZE bytes. * @retval STATUS_CODE_HEAP_EMPTY */ template StatusCode Overwrite(const size_t offset, const T value); /** * @brief Overwrite a boolean value. * * @param offset the offset at which to overwrite in the message. * @param value the boolean value to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ StatusCode OverwriteBoolean(const size_t offset, const bool value); private: //! Free any internal buffer. void FreeInternalBuffer(); //! Cleardown after a move-away. void Uninitialize(); /** * @brief Append a variable length binary integral value with a given endian ordering. * * ENDIAN the endian to copy the value in. * * @param pValue the address of the value to place in the message. * @param size the size of the value to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ template StatusCode InternalAppendInEndian(const void * const pValue, const size_t size); /** * @brief Append a built-in type. * * ENDIAN the endian to copy the value in. * T is the built-in type. * N is the length to serialize to. * * @param value the value to place in the message. * @param endian the endian to copy the value in. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_OUT_OF_RANGE if @value will not fit in N bytes. * @retval STATUS_CODE_HEAP_EMPTY */ template StatusCode InternalAppendInRange(const T value); /** * @brief Append a built-in type. * * T is the built-in type. * * @param value the value to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ template StatusCode InternalAppendBuiltIn(const T value); /** * @brief Append a buffer. * * @param REVERSE_BYTE_ORDER whether the byte order should be reversed. * * @param pBuffer the address of the buffer to place in the message. * @param length the length of the buffer to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ template StatusCode InternalAppendBuffer(const void * const pBuffer, const size_t length); /** * @brief Erase a buffer. * * @param offset the offset at which to erase in the message. * @param length the length of the buffer to erase in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER */ ACTIV_BASE_API StatusCode InternalEraseBuffer(const size_t offset, const size_t length); /** * @brief Insert a variable length binary integral value with a given endian ordering. * * ENDIAN the endian to copy the value in. * * @param offset the offset at which to insert in the message. * @param pValue the address of the value to place in the message. * @param size the size of the value to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ template StatusCode InternalInsertInEndian(const size_t offset, const void * const pValue, const size_t size); /** * @brief Insert a built-in type. * * ENDIAN the endian to copy the value in. * T is the built-in type. * N is the length to serialize to. * * @param offset the offset at which to insert in the message. * @param value the value to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_OUT_OF_RANGE if @value will not fit in N bytes. * @retval STATUS_CODE_HEAP_EMPTY */ template StatusCode InternalInsertInRange(const size_t offset, const T value); /** * @brief Insert a built-in type. * * T is the built-in type. * * @param offset the offset at which to insert in the message. * @param value the value to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ template StatusCode InternalInsertBuiltIn(const size_t offset, const T value); /** * @brief Insert a buffer. * * @param REVERSE_BYTE_ORDER whether the byte order should be reversed. * * @param offset the offset at which to insert in the message. * @param pBuffer the address of the buffer to place in the message. * @param length the length of the buffer to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ template StatusCode InternalInsertBuffer(const size_t offset, const void * const pBuffer, const size_t length); /** * @brief Overwrite a variable length binary integral value with a given endian ordering. * * ENDIAN the endian to copy the value in. * * @param offset the offset at which to overwrite in the message. * @param pValue the address of the value to place in the message. * @param size the size of the value to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ template StatusCode InternalOverwriteInEndian(const size_t offset, const void * const pValue, const size_t size); /** * @brief Overwrite a built-in type. * * ENDIAN the endian to copy the value in. * T is the built-in type. * N is the length to serialize to. * * @param offset the offset at which to overwrite in the message. * @param value the value to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_OUT_OF_RANGE if @value will not fit in N bytes. * @retval STATUS_CODE_HEAP_EMPTY */ template StatusCode InternalOverwriteInRange(const size_t offset, const T value); /** * @brief Overwrite a built-in type. * * T is the built-in type. * * @param offset the offset at which to overwrite in the message. * @param value the value to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ template StatusCode InternalOverwriteBuiltIn(const size_t offset, const T value); /** * @brief Overwrite a buffer. * * REVERSE_BYTE_ORDER whether the byte order should be reversed. * * @param offset the offset at which to overwrite in the message. * @param pBuffer the address of the buffer to place in the message. * @param length the length of the buffer to place in the message. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_BUFFER_OVERFLOW * @retval STATUS_CODE_INVALID_PARAMETER * @retval STATUS_CODE_HEAP_EMPTY */ template StatusCode InternalOverwriteBuffer(const size_t offset, const void * const pBuffer, const size_t length); /** * @brief Adjusts the size of the message buffer dependent on shouldAdjustBufferSize passed to the constructor. * * @param additionalSize * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_HEAP_EMPTY * @retval STATUS_CODE_BUFFER_OVERFLOW shouldAdjustBufferSize was false. */ ACTIV_BASE_API StatusCode MaybeAdjustBufferSize(const size_t additionalSize); /** * @brief Adjusts the size of the message buffer. * * @param bufferSize the size of the message buffer. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_HEAP_EMPTY */ ACTIV_BASE_API StatusCode AdjustBufferSize(const size_t bufferSize); /** * @brief Get buffer size required to hold additional bytes. * * @param additionalSize the amount of additional space required in the message. * * @return The buffer size. */ size_t GetAdjustedBufferSize(const size_t additionalSize) const; byte_t *m_pBuffer; ///< The address of the message buffer. size_t m_bufferSize; ///< The size of the message buffer. byte_t *m_pTail; ///< Current end of the built message. byte_t *m_pBufferEnd; ///< End of the available message buffer. bool m_shouldAdjustBufferSize; ///< Indicates whether the size of the message buffer should be adjusted. void * m_pStaticBuffer; ///< The address of the static message buffer. size_t m_staticBufferSize; ///< The size of the static message buffer. ACTIV_BOOST_COPYABLE_AND_MOVABLE(MessageBuilder) template friend class MessageBuilderConstantLengthDispatch; }; // --------------------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------------------- /** * @brief Class template to check a value is in the acceptable range of a variable number of bytes. * * Explicit specializations need to be at namespace scope. */ template class MessageBuilderVariableLengthRangeCheck { }; // --------------------------------------------------------------------------------------------------------------------------------- //! Specialization of MessageBuilderVariableLengthRangeCheck for signed values. template<> class MessageBuilderVariableLengthRangeCheck { public: /** * @brief Function operator. * * @param value the value to check. * @param numberOfBytes the number of bytes to check that @a value fits in. * * @return true if @a value is in range. */ template bool operator()(const T value, const size_t numberOfBytes) const { assert(numberOfBytes <= sizeof(T)); const T max = (T(1) << ((numberOfBytes * CHAR_BIT) - 1)) - 1; const T min = (-max) - 1; return ((value >= min) && (value <= max)); } }; // --------------------------------------------------------------------------------------------------------------------------------- //! Specialization of MessageBuilderVariableLengthRangeCheck for unsigned values. template<> class MessageBuilderVariableLengthRangeCheck { public: /** * @brief Function operator. * * @param value the value to check. * @param numberOfBytes the number of bytes to check that @a value fits in. * * @return true if @a value is in range. */ template bool operator()(const T value, const size_t numberOfBytes) const { assert(numberOfBytes <= sizeof(T)); const T max = static_cast(Boost::integer_traits::const_max >> ((sizeof(T) - numberOfBytes) * CHAR_BIT)); return (value <= max); } }; // --------------------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------------------- /** * @brief Class template to check a value is in the acceptable range of a constant number of bytes. * * Explicit specializations need to be at namespace scope. */ template class MessageBuilderConstLengthRangeCheck { }; // --------------------------------------------------------------------------------------------------------------------------------- //! Specialization of MessageBuilderConstLengthRangeCheck for signed values. template class MessageBuilderConstLengthRangeCheck { public: /** * @brief Function operator. * * @param value the value to check. * * @return true if @a value is in range. */ template bool operator()(const T value) const { ACTIV_BOOST_STATIC_ASSERT(NUMBER_OF_BYTES <= sizeof(T)); const T max = (T(1) << ((NUMBER_OF_BYTES * CHAR_BIT) - 1)) - 1; const T min = (-max) - 1; return ((value >= min) && (value <= max)); } }; // --------------------------------------------------------------------------------------------------------------------------------- //! Specialization of MessageBuilderConstLengthRangeCheck for unsigned values. template class MessageBuilderConstLengthRangeCheck { public: /** * @brief Function operator. * * @param value the value to check. * * @return true if @a value is in range. */ template bool operator()(const T value) const { ACTIV_BOOST_STATIC_ASSERT(NUMBER_OF_BYTES <= sizeof(T)); const T max = static_cast(Boost::integer_traits::const_max >> ((sizeof(T) - NUMBER_OF_BYTES) * CHAR_BIT)); return (value <= max); } }; // --------------------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------------------- //! Class template to swap the endian of a value if the requested endian does not match the local machine. template class MessageBuilderMaybeByteSwap { }; // --------------------------------------------------------------------------------------------------------------------------------- //! Specialization of MessageBuilderMaybeByteSwap to not reverse the endian of a value. template<> class MessageBuilderMaybeByteSwap { public: template T operator()(const T value) { return value; } }; // --------------------------------------------------------------------------------------------------------------------------------- //! Specialization of MessageBuilderMaybeByteSwap to reverse the endian of a value. template<> class MessageBuilderMaybeByteSwap { public: template T operator()(const T value) { return ByteSwap(value); } }; // --------------------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------------------- //! Class template to copy memory and potentially reverse the byte order. template class MessageBuilderMaybeMemoryReverseCopy { }; // --------------------------------------------------------------------------------------------------------------------------------- //! Specialization of MessageBuilderMaybeByteSwap to not reverse memory when copying. template<> class MessageBuilderMaybeMemoryReverseCopy { public: void operator()(void * const pDest, const void * const pBuffer, const size_t length) const { MemoryCopy(pDest, pBuffer, length); } }; // --------------------------------------------------------------------------------------------------------------------------------- //! Specialization of MessageBuilderMaybeByteSwap to reverse memory when copying. template<> class MessageBuilderMaybeMemoryReverseCopy { public: void operator()(void * const pDest, const void * const pBuffer, const size_t length) const { MemoryReverseCopy(pDest, pBuffer, length); } }; // --------------------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------------------- /** * @brief Helper for dispatching the appropriate Append/Overwrite/Insert call for a compile-time length. */ template class MessageBuilderConstantLengthDispatch { public: template StatusCode Append(MessageBuilder &messageBuilder, const T value) const { if (ACTIV_UNLIKELY((!MessageBuilderConstLengthRangeCheck::is_signed, SIZE>()(value)))) return STATUS_CODE_OUT_OF_RANGE; #if (defined ACTIV_LITTLE_ENDIAN) ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, messageBuilder.InternalAppendInEndian(&value, SIZE)); #else ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, messageBuilder.InternalAppendInEndian(reinterpret_cast(&value) + sizeof(T) - SIZE, SIZE)); #endif return STATUS_CODE_SUCCESS; } template StatusCode Insert(MessageBuilder &messageBuilder, const size_t offset, const T value) const { if (ACTIV_UNLIKELY((!MessageBuilderConstLengthRangeCheck::is_signed, SIZE>()(value)))) return STATUS_CODE_OUT_OF_RANGE; #if (defined ACTIV_LITTLE_ENDIAN) ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, messageBuilder.InternalInsertInEndian(offset, &value, SIZE)); #else ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, messageBuilder.InternalInsertInEndian(offset, reinterpret_cast(&value) + sizeof(T) - SIZE, SIZE)); #endif return STATUS_CODE_SUCCESS; } template StatusCode Overwrite(MessageBuilder &messageBuilder, const size_t offset, const T value) const { if (ACTIV_UNLIKELY((!MessageBuilderConstLengthRangeCheck::is_signed, SIZE>()(value)))) return STATUS_CODE_OUT_OF_RANGE; #if (defined ACTIV_LITTLE_ENDIAN) ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, messageBuilder.InternalOverwriteInEndian(offset, &value, SIZE)); #else ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, messageBuilder.InternalOverwriteInEndian(offset, reinterpret_cast(&value) + sizeof(T) - SIZE, SIZE)); #endif return STATUS_CODE_SUCCESS; } }; // --------------------------------------------------------------------------------------------------------------------------------- template class MessageBuilderConstantLengthDispatch { public: template StatusCode Append(MessageBuilder &messageBuilder, const T value) const { return messageBuilder.InternalAppendInRange(value); } template StatusCode Insert(MessageBuilder &messageBuilder, const size_t offset, const T value) const { return messageBuilder.InternalInsertInRange(offset, value); } template StatusCode Overwrite(MessageBuilder &messageBuilder, const size_t offset, const T value) const { return messageBuilder.InternalOverwriteInRange(offset, value); } }; // --------------------------------------------------------------------------------------------------------------------------------- template class MessageBuilderConstantLengthDispatch { public: template StatusCode Append(MessageBuilder &messageBuilder, const T value) const { return messageBuilder.InternalAppendInRange(value); } template StatusCode Insert(MessageBuilder &messageBuilder, const size_t offset, const T value) const { return messageBuilder.InternalInsertInRange(offset, value); } template StatusCode Overwrite(MessageBuilder &messageBuilder, const size_t offset, const T value) const { return messageBuilder.InternalOverwriteInRange(offset, value); } }; // --------------------------------------------------------------------------------------------------------------------------------- template class MessageBuilderConstantLengthDispatch { public: template StatusCode Append(MessageBuilder &messageBuilder, const T value) const { return messageBuilder.InternalAppendInRange(value); } template StatusCode Insert(MessageBuilder &messageBuilder, const size_t offset, const T value) const { return messageBuilder.InternalInsertInRange(offset, value); } template StatusCode Overwrite(MessageBuilder &messageBuilder, const size_t offset, const T value) const { return messageBuilder.InternalOverwriteInRange(offset, value); } }; // --------------------------------------------------------------------------------------------------------------------------------- template class MessageBuilderConstantLengthDispatch { public: template StatusCode Append(MessageBuilder &messageBuilder, const T value) const { ACTIV_BOOST_STATIC_ASSERT(sizeof(T) <= 8); return messageBuilder.Append( static_cast::is_signed>::Type>(value)); } template StatusCode Insert(MessageBuilder &messageBuilder, const size_t offset, const T value) const { ACTIV_BOOST_STATIC_ASSERT(sizeof(T) <= 8); return messageBuilder.Insert(offset, static_cast::is_signed>::Type>(value)); } template StatusCode Overwrite(MessageBuilder &messageBuilder, const size_t offset, const T value) const { ACTIV_BOOST_STATIC_ASSERT(sizeof(T) <= 8); return messageBuilder.Overwrite(offset, static_cast::is_signed>::Type>(value)); } }; // --------------------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------------------- inline MessageBuilder::~MessageBuilder() { FreeInternalBuffer(); } // --------------------------------------------------------------------------------------------------------------------------------- inline const MessageBuilder MessageBuilder::operator+(const MessageBuilder &rhs) const { return MessageBuilder(*this) += rhs; } // --------------------------------------------------------------------------------------------------------------------------------- inline MessageBuilder &MessageBuilder::operator+=(const MessageBuilder &rhs) { ACTIV_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, InternalAppendBuffer(rhs.GetMessage(), rhs.GetLength())); return *this; } // --------------------------------------------------------------------------------------------------------------------------------- inline StatusCode MessageBuilder::Initialize(const size_t initialBufferSize, const bool shouldAdjustBufferSize, const MessageVersion messageVersion) { ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, AdjustBufferSize(0)); m_pBuffer = ACTIV_NULLPTR; m_bufferSize = 0; m_pBufferEnd = 0; m_shouldAdjustBufferSize = shouldAdjustBufferSize; m_pStaticBuffer = ACTIV_NULLPTR; m_staticBufferSize = 0; if (0 != initialBufferSize) { ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, AdjustBufferSize(initialBufferSize)); } Reset(messageVersion); return STATUS_CODE_SUCCESS; } // --------------------------------------------------------------------------------------------------------------------------------- inline StatusCode MessageBuilder::Initialize(void * const pBuffer, const size_t bufferSize, const bool shouldAdjustBufferSize, const MessageVersion messageVersion) { ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, AdjustBufferSize(0)); m_pBuffer = static_cast(pBuffer); m_bufferSize = bufferSize; m_pBufferEnd = m_pBuffer + m_bufferSize; m_shouldAdjustBufferSize = shouldAdjustBufferSize; m_pStaticBuffer = pBuffer; m_staticBufferSize = bufferSize; Reset(messageVersion); return STATUS_CODE_SUCCESS; } // --------------------------------------------------------------------------------------------------------------------------------- inline void MessageBuilder::Reset(const MessageVersion messageVersion) { SetMessageVersion(messageVersion); m_pTail = m_pBuffer; } // --------------------------------------------------------------------------------------------------------------------------------- inline const void *MessageBuilder::GetMessage() const { return m_pBuffer; } // --------------------------------------------------------------------------------------------------------------------------------- inline size_t MessageBuilder::GetLength() const { return (m_pTail - m_pBuffer); } // --------------------------------------------------------------------------------------------------------------------------------- inline StatusCode MessageBuilder::SetLength(const size_t length) { byte_t * const pNewTail = m_pBuffer + length; if (ACTIV_UNLIKELY(pNewTail > m_pTail)) return STATUS_CODE_INVALID_PARAMETER; m_pTail = pNewTail; return STATUS_CODE_SUCCESS; } // --------------------------------------------------------------------------------------------------------------------------------- inline size_t MessageBuilder::GetBufferSize() const { return m_bufferSize; } // --------------------------------------------------------------------------------------------------------------------------------- inline StatusCode MessageBuilder::SetBufferSize(const size_t bufferSize) { if (ACTIV_UNLIKELY(bufferSize < GetLength())) return STATUS_CODE_INVALID_PARAMETER; return AdjustBufferSize(bufferSize); } // --------------------------------------------------------------------------------------------------------------------------------- inline StatusCode MessageBuilder::Extend(const size_t numberOfBytes) { byte_t *pNewTail = m_pTail + numberOfBytes; if (ACTIV_UNLIKELY(pNewTail > m_pBufferEnd)) { ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, MaybeAdjustBufferSize(numberOfBytes)); pNewTail = m_pTail + numberOfBytes; } m_pTail = pNewTail; return STATUS_CODE_SUCCESS; } // --------------------------------------------------------------------------------------------------------------------------------- inline StatusCode MessageBuilder::AppendBuffer(const void * const pBuffer, const size_t length) { return InternalAppendBuffer(pBuffer, length); } // --------------------------------------------------------------------------------------------------------------------------------- inline StatusCode MessageBuilder::Append(const MessageBuilder &messageBuilder) { return AppendBuffer(messageBuilder.GetMessage(), messageBuilder.GetLength()); } // --------------------------------------------------------------------------------------------------------------------------------- inline StatusCode MessageBuilder::Append(const byte_t value) { return InternalAppendBuiltIn(value); } // --------------------------------------------------------------------------------------------------------------------------------- inline StatusCode MessageBuilder::Append(const char character) { return InternalAppendBuiltIn(character); } // --------------------------------------------------------------------------------------------------------------------------------- inline StatusCode MessageBuilder::AppendCount(const char character, const size_t count) { byte_t *pNewTail = m_pTail + count; if (ACTIV_UNLIKELY(pNewTail > m_pBufferEnd)) { ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, MaybeAdjustBufferSize(count)); pNewTail = m_pTail + count; } std::memset(m_pTail, character, count); m_pTail = pNewTail; return STATUS_CODE_SUCCESS; } // --------------------------------------------------------------------------------------------------------------------------------- inline StatusCode MessageBuilder::Append(const String &str) { if (ACTIV_UNLIKELY(str.length() > Boost::integer_traits::const_max)) return STATUS_CODE_INVALID_PARAMETER; const StringLength length = static_cast(str.length()); ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, (Append(length))); return InternalAppendBuffer(str.c_str(), length); } // --------------------------------------------------------------------------------------------------------------------------------- inline StatusCode MessageBuilder::Append(const char * const pStr) { if (ACTIV_UNLIKELY(0 == pStr)) return STATUS_CODE_INVALID_PARAMETER; const size_t strLength = ::strlen(pStr); if (ACTIV_UNLIKELY(strLength > Boost::integer_traits::const_max)) return STATUS_CODE_INVALID_PARAMETER; const StringLength length = static_cast(strLength); ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, (Append(length))); return InternalAppendBuffer(pStr, strLength); } // --------------------------------------------------------------------------------------------------------------------------------- template inline StatusCode MessageBuilder::Append(const T value) { typedef typename TypeToIntegralType::Type Target; return InternalAppendBuiltIn(static_cast(MessageBuilderMaybeByteSwap()(value))); } // --------------------------------------------------------------------------------------------------------------------------------- template StatusCode MessageBuilder::Append(const T value, const size_t size) { // Assert T is an integral type, as we cast it to an ACTIV integral type (or use its address). ACTIV_BOOST_STATIC_ASSERT(Boost::is_integral::value); if (ACTIV_UNLIKELY(size > sizeof(T))) { return STATUS_CODE_INVALID_PARAMETER; } else if (ACTIV_UNLIKELY(size == sizeof(T))) { typedef typename TypeToIntegralType::Type Target; return Append(static_cast(value)); } switch (size) { case 1: return InternalAppendInRange(value); case 2: return InternalAppendInRange(value); case 4: return InternalAppendInRange(value); case 8: // GCC throws up silly warnings if we go the range-check route with a 64-bit target, so avoid the check // and assert the source type isn't bigger than 64-bits... ACTIV_BOOST_STATIC_ASSERT(sizeof(T) <= 8); return Append(static_cast::is_signed>::Type>(value)); default: break; } if (ACTIV_UNLIKELY(!MessageBuilderVariableLengthRangeCheck::is_signed>()(value, size))) return STATUS_CODE_OUT_OF_RANGE; #if (defined ACTIV_LITTLE_ENDIAN) ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, InternalAppendInEndian(&value, size)); #else ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, InternalAppendInEndian(reinterpret_cast(&value) + sizeof(T) - size, size)); #endif return STATUS_CODE_SUCCESS; } // --------------------------------------------------------------------------------------------------------------------------------- template inline StatusCode MessageBuilder::Append(const T value) { ACTIV_BOOST_STATIC_ASSERT(Boost::is_integral::value); ACTIV_BOOST_STATIC_ASSERT(SIZE <= sizeof(T)); return MessageBuilderConstantLengthDispatch().Append(*this, value); } // --------------------------------------------------------------------------------------------------------------------------------- inline StatusCode MessageBuilder::AppendBoolean(const bool value) { return InternalAppendBuiltIn(static_cast(value ? 1 : 0)); } // --------------------------------------------------------------------------------------------------------------------------------- template StatusCode MessageBuilder::AppendBase64(const void * const pData, const size_t dataLength) { const size_t maxEncodedLength = BASE64_ENCODER::GetMaximumEncodedLength(dataLength); byte_t *pNewTail = m_pTail + maxEncodedLength; if (ACTIV_UNLIKELY(pNewTail > m_pBufferEnd)) { ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, MaybeAdjustBufferSize(maxEncodedLength)); pNewTail = m_pTail + maxEncodedLength; } size_t encodedLength = m_bufferSize - GetLength(); ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, BASE64_ENCODER::Encode(pData, dataLength, reinterpret_cast(m_pTail), encodedLength)); m_pTail = pNewTail; return STATUS_CODE_SUCCESS; } // --------------------------------------------------------------------------------------------------------------------------------- template StatusCode MessageBuilder::AppendBase64(const ITERATOR begin, const ITERATOR end, const size_t offset, const size_t dataLength) { const size_t maxEncodedLength = BASE64_ENCODER::GetMaximumEncodedLength(dataLength); byte_t *pNewTail = m_pTail + maxEncodedLength; if (ACTIV_UNLIKELY(pNewTail > m_pBufferEnd)) { ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, MaybeAdjustBufferSize(maxEncodedLength)); pNewTail = m_pTail + maxEncodedLength; } size_t encodedLength = m_bufferSize - GetLength(); ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, (BASE64_ENCODER::template Encode(begin, end, offset, dataLength, reinterpret_cast(m_pTail), encodedLength))); m_pTail = pNewTail; return STATUS_CODE_SUCCESS; } // --------------------------------------------------------------------------------------------------------------------------------- inline StatusCode MessageBuilder::Erase(const size_t offset, const size_t length) { return InternalEraseBuffer(offset, length); } // --------------------------------------------------------------------------------------------------------------------------------- inline StatusCode MessageBuilder::InsertBuffer(const size_t offset, const void * const pBuffer, const size_t length) { return InternalInsertBuffer(offset, pBuffer, length); } // --------------------------------------------------------------------------------------------------------------------------------- inline StatusCode MessageBuilder::Insert(const size_t offset, const byte_t value) { return InternalInsertBuiltIn(offset, value); } // --------------------------------------------------------------------------------------------------------------------------------- inline StatusCode MessageBuilder::Insert(const size_t offset, const char character) { return InternalInsertBuiltIn(offset, character); } // --------------------------------------------------------------------------------------------------------------------------------- inline StatusCode MessageBuilder::InsertCount(const size_t offset, const char character, const size_t count) { const size_t originalLength = GetLength(); if (ACTIV_UNLIKELY(offset > originalLength)) return STATUS_CODE_INVALID_PARAMETER; byte_t *pNewTail = m_pTail + count; if (ACTIV_UNLIKELY(pNewTail > m_pBufferEnd)) { ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, MaybeAdjustBufferSize(count)); pNewTail = m_pTail + count; } void * const pDest = reinterpret_cast(m_pBuffer) + offset; std::memmove(reinterpret_cast(pDest) + count, pDest, originalLength - offset); std::memset(pDest, character, count); m_pTail = pNewTail; return STATUS_CODE_SUCCESS; } // --------------------------------------------------------------------------------------------------------------------------------- inline StatusCode MessageBuilder::Insert(const size_t offset, const String &str) { if (ACTIV_UNLIKELY(str.length() > Boost::integer_traits::const_max)) return STATUS_CODE_INVALID_PARAMETER; StringLength length = static_cast(str.length()); ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, (Insert(offset, length))); return InternalInsertBuffer(offset + sizeof(length), str.c_str(), length); } // --------------------------------------------------------------------------------------------------------------------------------- inline StatusCode MessageBuilder::Insert(const size_t offset, const char * const pStr) { if (ACTIV_UNLIKELY(0 == pStr)) return STATUS_CODE_INVALID_PARAMETER; const size_t strLength = ::strlen(pStr); if (ACTIV_UNLIKELY(strLength > Boost::integer_traits::const_max)) return STATUS_CODE_INVALID_PARAMETER; const StringLength length = static_cast(strLength); ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, (Insert(offset, length))); return InternalInsertBuffer(offset + sizeof(length), pStr, strLength); } // --------------------------------------------------------------------------------------------------------------------------------- template inline StatusCode MessageBuilder::Insert(const size_t offset, const T value) { typedef typename TypeToIntegralType::Type Target; return InternalInsertBuiltIn(offset, static_cast(MessageBuilderMaybeByteSwap()(value))); } // --------------------------------------------------------------------------------------------------------------------------------- template StatusCode MessageBuilder::Insert(const size_t offset, const T value, const size_t size) { // Assert T is an integral type, as we cast it to an ACTIV integral type (or use its address). ACTIV_BOOST_STATIC_ASSERT(Boost::is_integral::value); if (ACTIV_UNLIKELY(size > sizeof(T))) { return STATUS_CODE_INVALID_PARAMETER; } else if (ACTIV_UNLIKELY(size == sizeof(T))) { typedef typename TypeToIntegralType::Type Target; return Insert(offset, static_cast(value)); } switch (size) { case 1: return InternalInsertInRange(offset, value); case 2: return InternalInsertInRange(offset, value); case 4: return InternalInsertInRange(offset, value); case 8: // GCC throws up silly warnings if we go the range-check route with a 64-bit target, so avoid the check // and assert the source type isn't bigger than 64-bits... ACTIV_BOOST_STATIC_ASSERT(sizeof(T) <= 8); return Insert(offset, static_cast::is_signed>::Type>(value)); default: break; } if (ACTIV_UNLIKELY(!MessageBuilderVariableLengthRangeCheck::is_signed>()(value, size))) return STATUS_CODE_OUT_OF_RANGE; #if (defined ACTIV_LITTLE_ENDIAN) ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, InternalInsertInEndian(offset, &value, size)); #else ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, InternalInsertInEndian(offset, reinterpret_cast(&value) + sizeof(T) - size, size)); #endif return STATUS_CODE_SUCCESS; } // --------------------------------------------------------------------------------------------------------------------------------- template inline StatusCode MessageBuilder::Insert(const size_t offset, const T value) { ACTIV_BOOST_STATIC_ASSERT(Boost::is_integral::value); ACTIV_BOOST_STATIC_ASSERT(SIZE <= sizeof(T)); return MessageBuilderConstantLengthDispatch().Insert(*this, offset, value); } // --------------------------------------------------------------------------------------------------------------------------------- inline StatusCode MessageBuilder::InsertBoolean(const size_t offset, const bool value) { return InternalInsertBuiltIn(offset, static_cast(value ? 1 : 0)); } // --------------------------------------------------------------------------------------------------------------------------------- inline StatusCode MessageBuilder::OverwriteBuffer(const size_t offset, const void * const pBuffer, const size_t length) { return InternalOverwriteBuffer(offset, pBuffer, length); } // --------------------------------------------------------------------------------------------------------------------------------- inline StatusCode MessageBuilder::Overwrite(const size_t offset, const byte_t value) { return InternalOverwriteBuiltIn(offset, value); } // --------------------------------------------------------------------------------------------------------------------------------- inline StatusCode MessageBuilder::Overwrite(const size_t offset, const char character) { return InternalOverwriteBuiltIn(offset, character); } // --------------------------------------------------------------------------------------------------------------------------------- inline StatusCode MessageBuilder::OverwriteCount(const size_t offset, const char character, const size_t count) { const size_t originalLength = GetLength(); if (ACTIV_UNLIKELY(offset > originalLength)) return STATUS_CODE_INVALID_PARAMETER; if (ACTIV_UNLIKELY((offset + count) > originalLength)) { const size_t additionalLength = offset + count - originalLength; byte_t *pNewTail = m_pTail + additionalLength; if (ACTIV_UNLIKELY(pNewTail > m_pBufferEnd)) { ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, MaybeAdjustBufferSize(additionalLength)); pNewTail = m_pTail + additionalLength; } m_pTail = pNewTail; } void * const pDest = reinterpret_cast(m_pBuffer) + offset; std::memset(pDest, character, count); return STATUS_CODE_SUCCESS; } // --------------------------------------------------------------------------------------------------------------------------------- inline StatusCode MessageBuilder::Overwrite(const size_t offset, const String &str) { if (ACTIV_UNLIKELY(str.length() > Boost::integer_traits::const_max)) return STATUS_CODE_INVALID_PARAMETER; StringLength length = static_cast(str.length()); ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, (Overwrite(offset, length))); return InternalOverwriteBuffer(offset + sizeof(length), str.c_str(), length); } // --------------------------------------------------------------------------------------------------------------------------------- inline StatusCode MessageBuilder::Overwrite(const size_t offset, const char * const pStr) { if (ACTIV_UNLIKELY(0 == pStr)) return STATUS_CODE_INVALID_PARAMETER; const size_t strLength = ::strlen(pStr); if (ACTIV_UNLIKELY(strLength > Boost::integer_traits::const_max)) return STATUS_CODE_INVALID_PARAMETER; const StringLength length = static_cast(strLength); ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, (Overwrite(offset, length))); return InternalOverwriteBuffer(offset + sizeof(length), pStr, strLength); } // --------------------------------------------------------------------------------------------------------------------------------- template inline StatusCode MessageBuilder::Overwrite(const size_t offset, const T value) { typedef typename TypeToIntegralType::Type Target; return InternalOverwriteBuiltIn(offset, static_cast(MessageBuilderMaybeByteSwap()(value))); } // --------------------------------------------------------------------------------------------------------------------------------- template StatusCode MessageBuilder::Overwrite(const size_t offset, const T value, const size_t size) { // Assert T is an integral type, as we cast it to an ACTIV integral type (or use its address). ACTIV_BOOST_STATIC_ASSERT(Boost::is_integral::value); if (ACTIV_UNLIKELY(size > sizeof(T))) { return STATUS_CODE_INVALID_PARAMETER; } else if (ACTIV_UNLIKELY(size == sizeof(T))) { typedef typename TypeToIntegralType::Type Target; return Overwrite(offset, static_cast(value)); } switch (size) { case 1: return InternalOverwriteInRange(offset, value); case 2: return InternalOverwriteInRange(offset, value); case 4: return InternalOverwriteInRange(offset, value); case 8: // GCC throws up silly warnings if we go the range-check route with a 64-bit target, so avoid the check // and assert the source type isn't bigger than 64-bits... ACTIV_BOOST_STATIC_ASSERT(sizeof(T) <= 8); return Overwrite(offset, static_cast::is_signed>::Type>(value)); default: break; } if (ACTIV_UNLIKELY(!MessageBuilderVariableLengthRangeCheck::is_signed>()(value, size))) return STATUS_CODE_OUT_OF_RANGE; #if (defined ACTIV_LITTLE_ENDIAN) ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, InternalOverwriteInEndian(offset, &value, size)); #else ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, InternalOverwriteInEndian(offset, reinterpret_cast(&value) + sizeof(T) - size, size)); #endif return STATUS_CODE_SUCCESS; } // --------------------------------------------------------------------------------------------------------------------------------- template StatusCode MessageBuilder::Overwrite(const size_t offset, const T value) { ACTIV_BOOST_STATIC_ASSERT(Boost::is_integral::value); ACTIV_BOOST_STATIC_ASSERT(SIZE <= sizeof(T)); return MessageBuilderConstantLengthDispatch().Overwrite(*this, offset, value); } // --------------------------------------------------------------------------------------------------------------------------------- inline StatusCode MessageBuilder::OverwriteBoolean(const size_t offset, const bool value) { return InternalOverwriteBuiltIn(offset, static_cast(value ? 1 : 0)); } // --------------------------------------------------------------------------------------------------------------------------------- inline void MessageBuilder::FreeInternalBuffer() { if ((m_pStaticBuffer != m_pBuffer) && (ACTIV_NULLPTR != m_pBuffer)) std::free(m_pBuffer); } // --------------------------------------------------------------------------------------------------------------------------------- inline void MessageBuilder::Uninitialize() { m_pBuffer = ACTIV_NULLPTR; m_bufferSize = 0; m_pTail = ACTIV_NULLPTR; m_pBufferEnd = ACTIV_NULLPTR; m_pStaticBuffer = ACTIV_NULLPTR; m_staticBufferSize = 0; } // --------------------------------------------------------------------------------------------------------------------------------- template inline StatusCode MessageBuilder::InternalAppendInEndian(const void * const pValue, const size_t size) { return InternalAppendBuffer(pValue, size); } // --------------------------------------------------------------------------------------------------------------------------------- template inline StatusCode MessageBuilder::InternalAppendInRange(const T value) { typedef typename LengthToIntegralType::is_signed>::Type Target; if (ACTIV_UNLIKELY(!InRangeOfIntegralType()(value))) return STATUS_CODE_OUT_OF_RANGE; return Append(static_cast(value)); } // --------------------------------------------------------------------------------------------------------------------------------- template ACTIV_FORCE_INLINE StatusCode MessageBuilder::InternalAppendBuiltIn(const T value) { byte_t *pNewTail = m_pTail + sizeof(T); if (ACTIV_UNLIKELY(pNewTail > m_pBufferEnd)) { ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, MaybeAdjustBufferSize(sizeof(T))); pNewTail = m_pTail + sizeof(T); } CopyValueToUnalignedPointer(m_pTail, value); m_pTail = pNewTail; return STATUS_CODE_SUCCESS; } // --------------------------------------------------------------------------------------------------------------------------------- template inline StatusCode MessageBuilder::InternalAppendBuffer(const void * const pBuffer, const size_t length) { byte_t *pNewTail = m_pTail + length; if (ACTIV_UNLIKELY(pNewTail > m_pBufferEnd)) { ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, MaybeAdjustBufferSize(length)); pNewTail = m_pTail + length; } MessageBuilderMaybeMemoryReverseCopy()(m_pTail, pBuffer, length); m_pTail = pNewTail; return STATUS_CODE_SUCCESS; } // --------------------------------------------------------------------------------------------------------------------------------- template inline StatusCode MessageBuilder::InternalInsertInEndian(const size_t offset, const void * const pValue, const size_t size) { return InternalInsertBuffer(offset, pValue, size); } // --------------------------------------------------------------------------------------------------------------------------------- template inline StatusCode MessageBuilder::InternalInsertInRange(const size_t offset, const T value) { typedef typename LengthToIntegralType::is_signed>::Type Target; if (ACTIV_UNLIKELY(!InRangeOfIntegralType()(value))) return STATUS_CODE_OUT_OF_RANGE; return Insert(offset, static_cast(value)); } // --------------------------------------------------------------------------------------------------------------------------------- template inline StatusCode MessageBuilder::InternalInsertBuiltIn(const size_t offset, const T value) { const size_t originalLength = GetLength(); if (ACTIV_UNLIKELY(offset > originalLength)) return STATUS_CODE_INVALID_PARAMETER; byte_t *pNewTail = m_pTail + sizeof(T); if (ACTIV_UNLIKELY(pNewTail > m_pBufferEnd)) { ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, MaybeAdjustBufferSize(sizeof(T))); pNewTail = m_pTail + sizeof(T); } void * const pDest = reinterpret_cast(m_pBuffer) + offset; std::memmove(reinterpret_cast(pDest) + sizeof(T), pDest, originalLength - offset); CopyValueToUnalignedPointer(pDest, value); m_pTail = pNewTail; return STATUS_CODE_SUCCESS; } // --------------------------------------------------------------------------------------------------------------------------------- template inline StatusCode MessageBuilder::InternalInsertBuffer(const size_t offset, const void * const pBuffer, const size_t length) { const size_t originalLength = GetLength(); if (ACTIV_UNLIKELY(offset > originalLength)) return STATUS_CODE_INVALID_PARAMETER; byte_t *pNewTail = m_pTail + length; if (ACTIV_UNLIKELY(pNewTail > m_pBufferEnd)) { ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, MaybeAdjustBufferSize(length)); pNewTail = m_pTail + length; } void * const pDest = reinterpret_cast(m_pBuffer) + offset; std::memmove(reinterpret_cast(pDest) + length, pDest, originalLength - offset); MessageBuilderMaybeMemoryReverseCopy()(pDest, pBuffer, length); m_pTail = pNewTail; return STATUS_CODE_SUCCESS; } // --------------------------------------------------------------------------------------------------------------------------------- template inline StatusCode MessageBuilder::InternalOverwriteInEndian(const size_t offset, const void * const pValue, const size_t size) { return InternalOverwriteBuffer(offset, pValue, size); } // --------------------------------------------------------------------------------------------------------------------------------- template inline StatusCode MessageBuilder::InternalOverwriteInRange(const size_t offset, const T value) { typedef typename LengthToIntegralType::is_signed>::Type Target; if (ACTIV_UNLIKELY(!InRangeOfIntegralType()(value))) return STATUS_CODE_OUT_OF_RANGE; return Overwrite(offset, static_cast(value)); } // --------------------------------------------------------------------------------------------------------------------------------- template inline StatusCode MessageBuilder::InternalOverwriteBuiltIn(const size_t offset, const T value) { const size_t originalLength = GetLength(); if (ACTIV_UNLIKELY(offset > originalLength)) return STATUS_CODE_INVALID_PARAMETER; if (ACTIV_UNLIKELY((offset + sizeof(T)) > originalLength)) { const size_t additionalLength = offset + sizeof(T) - originalLength; byte_t *pNewTail = m_pTail + additionalLength; if (ACTIV_UNLIKELY(pNewTail > m_pBufferEnd)) { ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, MaybeAdjustBufferSize(additionalLength)); pNewTail = m_pTail + additionalLength; } m_pTail = pNewTail; } void * const pDest = reinterpret_cast(m_pBuffer) + offset; CopyValueToUnalignedPointer(pDest, value); return STATUS_CODE_SUCCESS; } // --------------------------------------------------------------------------------------------------------------------------------- template inline StatusCode MessageBuilder::InternalOverwriteBuffer(const size_t offset, const void * const pBuffer, const size_t length) { const size_t originalLength = GetLength(); if (ACTIV_UNLIKELY(offset > originalLength)) return STATUS_CODE_INVALID_PARAMETER; if (ACTIV_UNLIKELY((offset + length) > originalLength)) { const size_t additionalLength = offset + length - originalLength; byte_t *pNewTail = m_pTail + additionalLength; if (ACTIV_UNLIKELY(pNewTail > m_pBufferEnd)) { ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, MaybeAdjustBufferSize(additionalLength)); pNewTail = m_pTail + additionalLength; } m_pTail = pNewTail; } void * const pDest = reinterpret_cast(m_pBuffer) + offset; MessageBuilderMaybeMemoryReverseCopy()(pDest, pBuffer, length); return STATUS_CODE_SUCCESS; } // --------------------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------------------- inline MessageBuilder::ResetLengthHelper::ResetLengthHelper(MessageBuilder &messageBuilder) : m_messageBuilder(messageBuilder), m_originalLength(messageBuilder.GetLength()) { } // --------------------------------------------------------------------------------------------------------------------------------- inline void MessageBuilder::ResetLengthHelper::operator()() { (void) m_messageBuilder.SetLength(m_originalLength); } } // namespace Activ #endif // (!defined ACTIV_BASE_MESSAGE_BUILDER_H)