Changeset View
Changeset View
Standalone View
Standalone View
src/protocol.cpp
Show First 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | CMessageHeader::CMessageHeader(const MessageMagic &pchMessageStartIn) { | ||||
memset(pchChecksum, 0, CHECKSUM_SIZE); | memset(pchChecksum, 0, CHECKSUM_SIZE); | ||||
} | } | ||||
CMessageHeader::CMessageHeader(const MessageMagic &pchMessageStartIn, | CMessageHeader::CMessageHeader(const MessageMagic &pchMessageStartIn, | ||||
const char *pszCommand, | const char *pszCommand, | ||||
unsigned int nMessageSizeIn) { | unsigned int nMessageSizeIn) { | ||||
memcpy(std::begin(pchMessageStart), std::begin(pchMessageStartIn), | memcpy(std::begin(pchMessageStart), std::begin(pchMessageStartIn), | ||||
MESSAGE_START_SIZE); | MESSAGE_START_SIZE); | ||||
memset(pchCommand.data(), 0, sizeof(pchCommand)); | // Copy the command name, zero-padding to COMMAND_SIZE bytes | ||||
strncpy(pchCommand.data(), pszCommand, COMMAND_SIZE); | size_t i = 0; | ||||
for (; i < pchCommand.size() && pszCommand[i] != 0; ++i) { | |||||
pchCommand[i] = pszCommand[i]; | |||||
} | |||||
// Assert that the command name passed in is not longer than COMMAND_SIZE | |||||
assert(pszCommand[i] == 0); | |||||
for (; i < pchCommand.size(); ++i) { | |||||
pchCommand[i] = 0; | |||||
} | |||||
nMessageSize = nMessageSizeIn; | nMessageSize = nMessageSizeIn; | ||||
memset(pchChecksum, 0, CHECKSUM_SIZE); | memset(pchChecksum, 0, CHECKSUM_SIZE); | ||||
} | } | ||||
std::string CMessageHeader::GetCommand() const { | std::string CMessageHeader::GetCommand() const { | ||||
// return std::string(pchCommand.begin(), pchCommand.end()); | // return std::string(pchCommand.begin(), pchCommand.end()); | ||||
return std::string(pchCommand.data(), | return std::string(pchCommand.data(), | ||||
pchCommand.data() + | pchCommand.data() + | ||||
▲ Show 20 Lines • Show All 142 Lines • Show Last 20 Lines |