add types to json get with definition

This commit is contained in:
John
2021-11-05 10:54:17 +01:00
parent c7d77607c7
commit edb1e365a6
4 changed files with 44 additions and 3 deletions
+7 -2
View File
@@ -2199,8 +2199,13 @@ result_t MainLoop::executeGet(const vector<string>& args, bool* connected, ostri
*ostream << ",\n \"reconnects\": " << m_reconnectCount
<< ",\n \"masters\": " << m_busHandler->getMasterCount()
<< ",\n \"messages\": " << m_messages->size()
<< ",\n \"lastup\": " << static_cast<unsigned>(maxLastUp)
<< "\n }"
<< ",\n \"lastup\": " << static_cast<unsigned>(maxLastUp);
if (withDefinition) {
*ostream << ",\n \"types\": [";
DataTypeList::getInstance()->dump(verbosity, true, ostream);
*ostream << "\n ]";
}
*ostream << "\n }"
<< "\n}";
type = 6;
}
+25
View File
@@ -1116,6 +1116,31 @@ DataTypeList* DataTypeList::getInstance() {
return &s_instance;
}
void DataTypeList::dump(OutputFormat outputFormat, bool appendDivisor, ostream* output) const {
bool json = outputFormat & OF_JSON;
string sep = "\n";
for (int withLength=0; withLength<2; withLength++) {
const map<string, const DataType*>* types = withLength==0 ? &m_typesById : &m_typesByIdLength;
for (const auto &it: *types) {
const DataType *dataType = it.second;
if (json) {
*output << sep << " {";
}
if ((dataType->getBitCount() % 8) != 0) {
dataType->dump(outputFormat, dataType->getBitCount(), appendDivisor, output);
} else {
dataType->dump(outputFormat, dataType->getBitCount() / 8, appendDivisor, output);
}
if (json) {
*output << "}";
sep = ",\n";
} else {
*output << "\n";
}
}
}
}
void DataTypeList::clear() {
for (auto& it : m_cleanupTypes) {
delete it;
+8
View File
@@ -575,6 +575,14 @@ class DataTypeList {
*/
static DataTypeList* getInstance();
/**
* Dump the type list optionally including the divisor to the output.
* @param outputFormat the @a OutputFormat options.
* @param appendDivisor whether to append the divisor (if available).
* @param output the @a ostream to dump to.
*/
void dump(OutputFormat outputFormat, bool appendDivisor, ostream* output) const;
/**
* Removes all @a DataType instances.
*/