move helper method to SymbolString

This commit is contained in:
John
2021-11-05 19:45:04 +01:00
parent 1c5ede04e9
commit 7a567e69fb
3 changed files with 30 additions and 16 deletions
+19
View File
@@ -28,6 +28,7 @@ namespace ebusd {
using std::ostringstream;
using std::nouppercase;
using std::setw;
using std::dec;
using std::hex;
using std::setfill;
@@ -157,6 +158,24 @@ const string SymbolString::getStr(size_t skipFirstSymbols) const {
return sstr.str();
}
bool SymbolString::dumpJson(bool withSeparator, ostringstream* output) const {
if (size() == 0) {
return false;
}
if (withSeparator) {
*output << ",\n ";
}
*output << "\"" << (isMaster() ? "master" : "slave") << "\": [";
for (size_t pos = 0; pos < size(); pos++) {
if (pos > 0) {
*output << ", ";
}
*output << dec << static_cast<unsigned>(m_data[pos]);
}
*output << "]";
return true;
}
symbol_t SymbolString::calcCrc() const {
symbol_t crc = 0;
for (size_t i = 0; i < m_data.size(); i++) {