include length suffix and optionally flags and result type in json dump
This commit is contained in:
@@ -44,8 +44,17 @@ using std::endl;
|
|||||||
|
|
||||||
bool DataType::dump(OutputFormat outputFormat, size_t length, bool appendDivisor, ostream* output) const {
|
bool DataType::dump(OutputFormat outputFormat, size_t length, bool appendDivisor, ostream* output) const {
|
||||||
if (outputFormat & OF_JSON) {
|
if (outputFormat & OF_JSON) {
|
||||||
*output << "\"type\": \"" << m_id << "\", \"isbits\": "
|
*output << "\"type\": \"" << m_id;
|
||||||
<< (getBitCount() < 8 ? "true" : "false") << ", \"length\": ";
|
if (!isAdjustableLength() && hasFlag(WLS)) {
|
||||||
|
*output << LENGTH_SEPARATOR << static_cast<unsigned>(length);
|
||||||
|
}
|
||||||
|
*output << "\", \"isbits\": "
|
||||||
|
<< (getBitCount() < 8 ? "true" : "false");
|
||||||
|
if (outputFormat & OF_ALL_ATTRS) {
|
||||||
|
*output << ", \"isadjustable\": " << (isAdjustableLength() ? "true" : "false");
|
||||||
|
*output << ", \"isignored\": " << (isIgnored() ? "true" : "false");
|
||||||
|
}
|
||||||
|
*output << ", \"length\": ";
|
||||||
if (isAdjustableLength() && length == REMAIN_LEN) {
|
if (isAdjustableLength() && length == REMAIN_LEN) {
|
||||||
*output << "-1";
|
*output << "-1";
|
||||||
} else {
|
} else {
|
||||||
@@ -69,6 +78,14 @@ bool DataType::dump(OutputFormat outputFormat, size_t length, bool appendDivisor
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool StringDataType::dump(OutputFormat outputFormat, size_t length, bool appendDivisor, ostream* output) const {
|
||||||
|
DataType::dump(outputFormat, length, appendDivisor, output);
|
||||||
|
if ((outputFormat & OF_JSON) && (outputFormat & OF_ALL_ATTRS)) {
|
||||||
|
*output << ", \"result\": \"" << (isIgnored() ? "void" : "string") << "\"";
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
result_t StringDataType::readRawValue(size_t, size_t, const SymbolString&, unsigned int*) const {
|
result_t StringDataType::readRawValue(size_t, size_t, const SymbolString&, unsigned int*) const {
|
||||||
return RESULT_EMPTY;
|
return RESULT_EMPTY;
|
||||||
}
|
}
|
||||||
@@ -204,6 +221,14 @@ result_t StringDataType::writeSymbols(size_t offset, size_t length, istringstrea
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool DateTimeDataType::dump(OutputFormat outputFormat, size_t length, bool appendDivisor, ostream* output) const {
|
||||||
|
DataType::dump(outputFormat, length, appendDivisor, output);
|
||||||
|
if ((outputFormat & OF_JSON) && (outputFormat & OF_ALL_ATTRS)) {
|
||||||
|
*output << ", \"result\": \"" << (hasDate() ? hasTime() ? "datetime" : "date" : "time") << "\"";
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
result_t DateTimeDataType::readRawValue(size_t, size_t, const SymbolString&, unsigned int*) const {
|
result_t DateTimeDataType::readRawValue(size_t, size_t, const SymbolString&, unsigned int*) const {
|
||||||
return RESULT_EMPTY;
|
return RESULT_EMPTY;
|
||||||
}
|
}
|
||||||
@@ -573,25 +598,32 @@ bool NumberDataType::dump(OutputFormat outputFormat, size_t length, bool appendD
|
|||||||
} else {
|
} else {
|
||||||
DataType::dump(outputFormat, length, appendDivisor, output);
|
DataType::dump(outputFormat, length, appendDivisor, output);
|
||||||
}
|
}
|
||||||
|
if ((outputFormat & OF_JSON) && (outputFormat & OF_ALL_ATTRS)) {
|
||||||
|
*output << ", \"result\": \"number\"";
|
||||||
|
}
|
||||||
if (!appendDivisor) {
|
if (!appendDivisor) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
bool ret = false;
|
||||||
if (m_baseType) {
|
if (m_baseType) {
|
||||||
if (m_baseType->m_divisor != m_divisor) {
|
if (m_baseType->m_divisor != m_divisor) {
|
||||||
if (outputFormat & OF_JSON) {
|
if (outputFormat & OF_JSON) {
|
||||||
*output << ", \"divisor\": ";
|
*output << ", \"divisor\": ";
|
||||||
}
|
}
|
||||||
*output << (m_divisor / m_baseType->m_divisor);
|
*output << (m_divisor / m_baseType->m_divisor);
|
||||||
return true;
|
ret = true;
|
||||||
}
|
}
|
||||||
} else if (m_divisor != 1) {
|
} else if (m_divisor != 1) {
|
||||||
if (outputFormat & OF_JSON) {
|
if (outputFormat & OF_JSON) {
|
||||||
*output << ", \"divisor\": ";
|
*output << ", \"divisor\": ";
|
||||||
}
|
}
|
||||||
*output << m_divisor;
|
*output << m_divisor;
|
||||||
return true;
|
ret = true;
|
||||||
}
|
}
|
||||||
return false;
|
if (ret && (outputFormat & OF_JSON) && (outputFormat & OF_ALL_ATTRS)) {
|
||||||
|
*output << ", \"precision\": " << static_cast<unsigned>(getPrecision());
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
result_t NumberDataType::derive(int divisor, size_t bitCount, const NumberDataType** derived) const {
|
result_t NumberDataType::derive(int divisor, size_t bitCount, const NumberDataType** derived) const {
|
||||||
|
|||||||
@@ -325,6 +325,9 @@ class StringDataType : public DataType {
|
|||||||
*/
|
*/
|
||||||
virtual ~StringDataType() {}
|
virtual ~StringDataType() {}
|
||||||
|
|
||||||
|
// @copydoc
|
||||||
|
bool dump(OutputFormat outputFormat, size_t length, bool appendDivisor, ostream* output) const override;
|
||||||
|
|
||||||
// @copydoc
|
// @copydoc
|
||||||
result_t readRawValue(size_t offset, size_t length, const SymbolString& input,
|
result_t readRawValue(size_t offset, size_t length, const SymbolString& input,
|
||||||
unsigned int* value) const override;
|
unsigned int* value) const override;
|
||||||
@@ -369,6 +372,9 @@ class DateTimeDataType : public DataType {
|
|||||||
*/
|
*/
|
||||||
virtual ~DateTimeDataType() {}
|
virtual ~DateTimeDataType() {}
|
||||||
|
|
||||||
|
// @copydoc
|
||||||
|
bool dump(OutputFormat outputFormat, size_t length, bool appendDivisor, ostream* output) const override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if date part is present.
|
* @return true if date part is present.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user