move helper method to SymbolString
This commit is contained in:
@@ -935,20 +935,6 @@ void Message::dumpField(const string& fieldName, bool withConditions, OutputForm
|
||||
dumpAttribute(false, outputFormat, fieldName, output);
|
||||
}
|
||||
|
||||
void addData(const SymbolString& data, ostringstream* output) {
|
||||
if (data.size() == 0) {
|
||||
return;
|
||||
}
|
||||
*output << ",\n \"" << (data.isMaster() ? "master" : "slave") << "\": [";
|
||||
for (size_t pos = 0; pos < data.size(); pos++) {
|
||||
if (pos > 0) {
|
||||
*output << ", ";
|
||||
}
|
||||
*output << dec << static_cast<unsigned>(data[pos]);
|
||||
}
|
||||
*output << "]";
|
||||
}
|
||||
|
||||
void Message::decodeJson(bool leadingSeparator, bool appendDirectionCondition, bool withData, bool addRaw,
|
||||
OutputFormat outputFormat, ostringstream* output) const {
|
||||
outputFormat |= OF_JSON;
|
||||
@@ -1005,8 +991,8 @@ void Message::decodeJson(bool leadingSeparator, bool appendDirectionCondition, b
|
||||
appendAttributes(outputFormat, output);
|
||||
if (hasData) {
|
||||
if (addRaw) {
|
||||
addData(m_lastMasterData, output);
|
||||
addData(m_lastSlaveData, output);
|
||||
m_lastMasterData.dumpJson(true, output);
|
||||
m_lastSlaveData.dumpJson(true, output);
|
||||
*output << dec;
|
||||
}
|
||||
size_t pos = (size_t)output->tellp();
|
||||
|
||||
@@ -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++) {
|
||||
|
||||
@@ -67,6 +67,7 @@ namespace ebusd {
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::ostringstream;
|
||||
|
||||
/** the base type for symbols sent to/from the eBUS. */
|
||||
typedef unsigned char symbol_t;
|
||||
@@ -158,6 +159,14 @@ class SymbolString {
|
||||
*/
|
||||
const string getStr(size_t skipFirstSymbols = 0) const;
|
||||
|
||||
/**
|
||||
* Dump the data in JSON format to the output.
|
||||
* @param withSeparator true to prepend the field separator.
|
||||
* @param output the @a ostringstream to format the messages to.
|
||||
* @return true if something was written to the output.
|
||||
*/
|
||||
bool dumpJson(bool withSeparator, ostringstream* output) const;
|
||||
|
||||
/**
|
||||
* Return a reference to the symbol at the specified index.
|
||||
* @param index the index of the symbol to return.
|
||||
|
||||
Reference in New Issue
Block a user