82 lines
2.1 KiB
C++
82 lines
2.1 KiB
C++
/**
|
|
* @file include/ActivMiddleware/ActivBase/GenericMessages/Formats/Activ/FieldHeaderActiv.h
|
|
*
|
|
* @brief Header for FieldHeader class.
|
|
*/
|
|
|
|
#if (!defined ACTIV_BASE_GENERIC_MESSAGES_FORMATS_ACTIV_FIELD_HEADER_ACTIV_H)
|
|
#define ACTIV_BASE_GENERIC_MESSAGES_FORMATS_ACTIV_FIELD_HEADER_ACTIV_H
|
|
|
|
#include "ActivMiddleware/ActivBase/GenericMessages/Types.h"
|
|
#include "ActivMiddleware/ActivBase/FieldTypes/ActivFieldTypes.h"
|
|
#include "ActivMiddleware/Misc/BitFields.h"
|
|
|
|
//! Activ namespace.
|
|
namespace Activ
|
|
{
|
|
|
|
//! GenericMessages namespace.
|
|
namespace GenericMessages
|
|
{
|
|
|
|
// Formats namespace.
|
|
namespace Formats
|
|
{
|
|
|
|
// ACTIV format namespace.
|
|
namespace Activ
|
|
{
|
|
|
|
/**
|
|
* @brief Field header bitmap.
|
|
*/
|
|
class FieldHeader : public Bitmap<8, LsbOrigin>
|
|
{
|
|
public:
|
|
typedef BitField<FieldHeader, 5> ContentType;
|
|
typedef BitField<ContentType, 2> Length;
|
|
// Reserved 1 bit.
|
|
|
|
/**
|
|
* @brief Convert an integral length to a value suitable for the Length field.
|
|
*
|
|
* @param numberOfBytes integral length, must be 1,2,4 or 8.
|
|
*
|
|
* @return Value suitable for the Length field.
|
|
*/
|
|
static Type IntegralLengthToLengthBits(const size_t numberOfBytes)
|
|
{
|
|
assert((1 == numberOfBytes) || (2 == numberOfBytes) || (4 == numberOfBytes) || (8 == numberOfBytes));
|
|
|
|
return static_cast<Type>(HighestBitPosition<size_t>()(numberOfBytes) - 1);
|
|
}
|
|
|
|
/**
|
|
* @brief Convert the value of a Length field to an integral length.
|
|
*
|
|
* @param lengthBits
|
|
*
|
|
* @return Integral length; 1,2,4 or 8 bytes.
|
|
*/
|
|
static size_t LengthBitsToIntegralLength(const Type lengthBits)
|
|
{
|
|
return (size_t(1) << lengthBits);
|
|
}
|
|
};
|
|
|
|
ACTIV_BOOST_STATIC_ASSERT(CONTENT_TYPE_INITIAL >= static_cast<ContentType>(NUMBER_OF_FIELD_TYPES));
|
|
ACTIV_BOOST_STATIC_ASSERT(CONTENT_TYPE_TERMINAL <= static_cast<ContentType>(FieldHeader::ContentType::maxValue));
|
|
|
|
// Do not change this value, it will break the wire format!
|
|
const size_t maxNumberOfConsecutiveNullSequenceElements = 2;
|
|
|
|
} // namespace Activ
|
|
|
|
} // namespace Formats
|
|
|
|
} // namespace GenericMessages
|
|
|
|
} // namespace Activ
|
|
|
|
#endif // (!defined ACTIV_BASE_GENERIC_MESSAGES_FORMATS_ACTIV_FIELD_HEADER_ACTIV_H)
|