added SymbolString::adjustHeader(), avoid strcasecmp, code style
This commit is contained in:
@@ -98,7 +98,7 @@ result_t TemParamDataType::writeSymbols(istringstream& input,
|
||||
string token;
|
||||
|
||||
const char* str = input.str().c_str();
|
||||
if (strcasecmp(str, NULL_VALUE) == 0) {
|
||||
if (strcmp(str, NULL_VALUE) == 0) {
|
||||
value = m_replacement; // replacement value
|
||||
} else {
|
||||
if (input.eof() || !getline(input, token, '-')) {
|
||||
|
||||
@@ -792,7 +792,7 @@ result_t NumberDataType::writeSymbols(istringstream& input,
|
||||
unsigned int value;
|
||||
|
||||
const char* str = input.str().c_str();
|
||||
if (!hasFlag(REQ) && (isIgnored() || strcasecmp(str, NULL_VALUE) == 0)) {
|
||||
if (!hasFlag(REQ) && (isIgnored() || strcmp(str, NULL_VALUE) == 0)) {
|
||||
value = m_replacement; // replacement value
|
||||
} else if (str == NULL || *str == 0) {
|
||||
return RESULT_ERR_EOF; // input too short
|
||||
|
||||
@@ -59,7 +59,7 @@ using std::mutex;
|
||||
#define VALUE_SEPARATOR ';'
|
||||
|
||||
/** special marker string for skipping columns in @a MappedFileReader. */
|
||||
static const string SKIP_COLUMN = "\b";
|
||||
static const char SKIP_COLUMN[] = "\b";
|
||||
|
||||
/**
|
||||
* An abstract class that support reading definitions from a file.
|
||||
|
||||
@@ -669,7 +669,6 @@ result_t Message::prepareMasterPart(MasterSymbolString& master, istringstream& i
|
||||
if (index != 0) {
|
||||
return RESULT_ERR_NOTFOUND;
|
||||
}
|
||||
size_t pos = master.size();
|
||||
master.push_back(0); // length, will be set later
|
||||
for (size_t i = 2; i < m_id.size(); i++) {
|
||||
master.push_back(m_id[i]);
|
||||
@@ -678,7 +677,7 @@ result_t Message::prepareMasterPart(MasterSymbolString& master, istringstream& i
|
||||
if (result != RESULT_OK) {
|
||||
return result;
|
||||
}
|
||||
master[pos] = (symbol_t)(master.size()-pos-1);
|
||||
master.adjustHeader();
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -692,7 +691,7 @@ result_t Message::prepareSlave(istringstream& input, SlaveSymbolString& slave) {
|
||||
if (result != RESULT_OK) {
|
||||
return result;
|
||||
}
|
||||
slave[0] = (symbol_t)(slave.size()-1);
|
||||
slave.adjustHeader();
|
||||
time(&m_lastUpdateTime);
|
||||
if (slave != m_lastSlaveData) {
|
||||
m_lastChangeTime = m_lastUpdateTime;
|
||||
@@ -1201,11 +1200,9 @@ result_t ChainedMessage::combineLastParts() {
|
||||
}
|
||||
}
|
||||
// adjust NN
|
||||
if (master.size()-5 > 255 || slave.size()-1 > 255) {
|
||||
if (!master.adjustHeader() || !slave.adjustHeader()) {
|
||||
return RESULT_ERR_INVALID_POS;
|
||||
}
|
||||
master[4] = (symbol_t)(master.size()-5);
|
||||
slave[0] = (symbol_t)(slave.size()-1);
|
||||
result_t result = Message::storeLastData(master, 0);
|
||||
if (result == RESULT_OK) {
|
||||
result = Message::storeLastData(slave, 0);
|
||||
@@ -2449,7 +2446,7 @@ deque<Message*> MessageMap::findAll(const string& circuit, const string& name, c
|
||||
|
||||
Message* MessageMap::find(MasterSymbolString& master, bool anyDestination,
|
||||
const bool withRead, const bool withWrite, const bool withPassive, const bool onlyAvailable) const {
|
||||
if (master.size() >= 5 && master[4] == 0 && anyDestination && master[2] == 0x07 && master[3] == 0x04) {
|
||||
if (anyDestination && master.size() >= 5 && master[4] == 0 && master[2] == 0x07 && master[3] == 0x04) {
|
||||
return m_scanMessage;
|
||||
}
|
||||
uint64_t baseKey = Message::createKey(master,
|
||||
|
||||
@@ -1215,7 +1215,8 @@ class MessageMap : public MappedFileReader {
|
||||
* @param addAll whether to add all messages, even if duplicate.
|
||||
* @param preferLanguage the preferred language to use, or empty.
|
||||
*/
|
||||
explicit MessageMap(const bool addAll = false, const string preferLanguage = "") : MappedFileReader::MappedFileReader(true),
|
||||
explicit MessageMap(const bool addAll = false, const string preferLanguage = "")
|
||||
: MappedFileReader::MappedFileReader(true),
|
||||
m_addAll(addAll), m_additionalScanMessages(false), m_maxIdLength(0), m_maxBroadcastIdLength(0),
|
||||
m_messageCount(0), m_conditionalMessageCount(0), m_passiveMessageCount(0) {
|
||||
m_scanMessage = Message::createScanMessage();
|
||||
|
||||
+16
-1
@@ -130,7 +130,7 @@ class SymbolString {
|
||||
* @param value the escaped value to add to the current CRC.
|
||||
*/
|
||||
static void updateCrc(symbol_t& crc, const symbol_t value);
|
||||
// TODO add SymbolString::updateHeader() for adjusting length field
|
||||
|
||||
/**
|
||||
* Return whether this instance if for the master part.
|
||||
* @return whether this instance if for the master part.
|
||||
@@ -226,6 +226,21 @@ class SymbolString {
|
||||
*/
|
||||
size_t size() const { return m_data.size(); }
|
||||
|
||||
/**
|
||||
* Adjust the header NN field to the number of data bytes DD.
|
||||
* @return true on success, false if the number of data bytes DD is too big.
|
||||
*/
|
||||
bool adjustHeader() {
|
||||
size_t lengthOffset = (m_isMaster ? 4 : 0);
|
||||
if (m_data.size() <= lengthOffset) {
|
||||
m_data.resize(lengthOffset+1);
|
||||
} else if (m_data.size() >= lengthOffset+255) {
|
||||
return false;
|
||||
}
|
||||
m_data[lengthOffset] = (symbol_t)(m_data.size() - 1 - lengthOffset);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the offset to the first data byte DD.
|
||||
* @return the offset to the first data byte DD.
|
||||
|
||||
Reference in New Issue
Block a user