Changeset View
Changeset View
Standalone View
Standalone View
src/protocol.h
Show All 30 Lines | |||||
* Message header. | * Message header. | ||||
* (4) message start. | * (4) message start. | ||||
* (12) command. | * (12) command. | ||||
* (4) size. | * (4) size. | ||||
* (4) checksum. | * (4) checksum. | ||||
*/ | */ | ||||
class CMessageHeader { | class CMessageHeader { | ||||
public: | public: | ||||
enum { | static constexpr size_t MESSAGE_START_SIZE = 4; | ||||
MESSAGE_START_SIZE = 4, | static constexpr size_t COMMAND_SIZE = 12; | ||||
COMMAND_SIZE = 12, | static constexpr size_t MESSAGE_SIZE_SIZE = 4; | ||||
MESSAGE_SIZE_SIZE = 4, | static constexpr size_t CHECKSUM_SIZE = 4; | ||||
CHECKSUM_SIZE = 4, | static constexpr size_t MESSAGE_SIZE_OFFSET = | ||||
MESSAGE_START_SIZE + COMMAND_SIZE; | |||||
MESSAGE_SIZE_OFFSET = MESSAGE_START_SIZE + COMMAND_SIZE, | static constexpr size_t CHECKSUM_OFFSET = | ||||
CHECKSUM_OFFSET = MESSAGE_SIZE_OFFSET + MESSAGE_SIZE_SIZE, | MESSAGE_SIZE_OFFSET + MESSAGE_SIZE_SIZE; | ||||
HEADER_SIZE = MESSAGE_START_SIZE + COMMAND_SIZE + MESSAGE_SIZE_SIZE + | static constexpr size_t HEADER_SIZE = | ||||
CHECKSUM_SIZE | MESSAGE_START_SIZE + COMMAND_SIZE + MESSAGE_SIZE_SIZE + CHECKSUM_SIZE; | ||||
}; | |||||
typedef std::array<uint8_t, MESSAGE_START_SIZE> MessageMagic; | typedef std::array<uint8_t, MESSAGE_START_SIZE> MessageMagic; | ||||
explicit CMessageHeader(const MessageMagic &pchMessageStartIn); | explicit CMessageHeader(const MessageMagic &pchMessageStartIn); | ||||
CMessageHeader(const MessageMagic &pchMessageStartIn, | CMessageHeader(const MessageMagic &pchMessageStartIn, | ||||
const char *pszCommand, unsigned int nMessageSizeIn); | const char *pszCommand, unsigned int nMessageSizeIn); | ||||
std::string GetCommand() const; | std::string GetCommand() const; | ||||
bool IsValid(const Config &config) const; | bool IsValid(const Config &config) const; | ||||
▲ Show 20 Lines • Show All 413 Lines • Show Last 20 Lines |