add types to json get with definition
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user