added DataField::getCount(), exclude name wrap when fieldIndex is used in SingleDataField::read(), corrected json indent
This commit is contained in:
@@ -532,16 +532,20 @@ result_t SingleDataField::read(const SymbolString& data, size_t offset,
|
||||
if (leadingSeparator) {
|
||||
*output << ",";
|
||||
}
|
||||
if (!shortFormat) {
|
||||
if (fieldIndex < 0 && !shortFormat) {
|
||||
*output << "\n ";
|
||||
}
|
||||
if (outputIndex >= 0 || m_name.empty() || !(outputFormat & OF_NAMES)) {
|
||||
if (fieldIndex < 0) {
|
||||
*output << "\"" << static_cast<signed int>(outputIndex < 0 ? 0 : outputIndex) << "\":";
|
||||
}
|
||||
if (!shortFormat) {
|
||||
*output << " {\"name\": \"" << m_name << "\"" << ", \"value\": ";
|
||||
}
|
||||
} else {
|
||||
if (fieldIndex < 0) {
|
||||
*output << "\"" << m_name << "\":";
|
||||
}
|
||||
if (!shortFormat) {
|
||||
*output << " {\"value\": ";
|
||||
}
|
||||
|
||||
@@ -249,6 +249,12 @@ class DataField : public AttributedItem {
|
||||
const map<unsigned int, string>& values, map<string, string>* attributes,
|
||||
vector<const SingleDataField*>* fields) const = 0;
|
||||
|
||||
/**
|
||||
* Get the field count (excluding ignored fields).
|
||||
* @return the field count (excluding ignored fields).
|
||||
*/
|
||||
virtual size_t getCount() const = 0;
|
||||
|
||||
/**
|
||||
* Get the specified field name.
|
||||
* @param fieldIndex the index of the field (excluding ignored fields), or -1 for this.
|
||||
@@ -392,6 +398,9 @@ class SingleDataField : public DataField {
|
||||
*/
|
||||
bool hasFullByteOffset(bool after) const;
|
||||
|
||||
// @copydoc
|
||||
size_t getCount() const override { return isIgnored() ? 0 : 1; }
|
||||
|
||||
// @copydoc
|
||||
virtual string getName(ssize_t fieldIndex) const {
|
||||
return isIgnored() || fieldIndex > 0 ? "" : m_name;
|
||||
@@ -628,6 +637,9 @@ class DataFieldSet : public DataField {
|
||||
// @copydoc
|
||||
size_t getLength(PartType partType, size_t maxLength) const override;
|
||||
|
||||
// @copydoc
|
||||
size_t getCount() const override { return m_fields.size() - m_ignoredCount; }
|
||||
|
||||
// @copydoc
|
||||
string getName(ssize_t fieldIndex) const override;
|
||||
|
||||
|
||||
@@ -267,12 +267,18 @@ class Message : public AttributedItem {
|
||||
*/
|
||||
static bool checkLevel(const string& level, const string& checkLevels);
|
||||
|
||||
/**
|
||||
* Get the number of non-ignored fields.
|
||||
* @return the number of non-ignored fields.
|
||||
*/
|
||||
size_t getFieldCount() const { return m_data->getCount(); }
|
||||
|
||||
/**
|
||||
* Get the specified field name.
|
||||
* @param fieldIndex the index of the field (excluding ignored fields).
|
||||
* @return the field name, or the index as string if not unique or not available.
|
||||
* @return the field name, or the index as string if not unique, or empty not available.
|
||||
*/
|
||||
virtual string getFieldName(ssize_t fieldIndex) const { return m_data->getName(fieldIndex); }
|
||||
string getFieldName(ssize_t fieldIndex) const { return m_data->getName(fieldIndex); }
|
||||
|
||||
/**
|
||||
* Get whether this is a write message.
|
||||
|
||||
Reference in New Issue
Block a user