Revert "Implement optional scalars for JSON (#7322)" (#7351)

This reverts commit a18ea40d6a.
This commit is contained in:
Derek Bailey
2022-06-15 00:32:28 -07:00
committed by GitHub
parent b4647beb8f
commit 9a1913a87a
5 changed files with 10 additions and 132 deletions

View File

@@ -248,23 +248,11 @@ struct JsonPrinter {
template<typename T>
bool GenField(const FieldDef &fd, const Table *table, bool fixed,
int indent) {
if (fixed) {
return PrintScalar(
reinterpret_cast<const Struct *>(table)->GetField<T>(fd.value.offset),
fd.value.type, indent);
} else if (fd.IsOptional()) {
auto opt = table->GetOptional<T, T>(fd.value.offset);
if (opt) {
return PrintScalar(*opt, fd.value.type, indent);
} else {
text += "null";
return true;
}
} else {
return PrintScalar(
table->GetField<T>(fd.value.offset, GetFieldDefault<T>(fd)),
fd.value.type, indent);
}
return PrintScalar(
fixed ? reinterpret_cast<const Struct *>(table)->GetField<T>(
fd.value.offset)
: table->GetField<T>(fd.value.offset, GetFieldDefault<T>(fd)),
fd.value.type, indent);
}
// Generate text for non-scalar field.

View File

@@ -1335,18 +1335,10 @@ CheckedError Parser::ParseTable(const StructDef &struct_def, std::string *value,
ECHECK(atot(field_value.constant.c_str(), *this, &val)); \
builder_.PushElement(val); \
} else { \
if (field->IsScalarOptional()) { \
if (field_value.constant != "null") { \
CTYPE val; \
ECHECK(atot(field_value.constant.c_str(), *this, &val)); \
builder_.AddElement(field_value.offset, val); \
} \
} else { \
CTYPE val, valdef; \
ECHECK(atot(field_value.constant.c_str(), *this, &val)); \
ECHECK(atot(field->value.constant.c_str(), *this, &valdef)); \
builder_.AddElement(field_value.offset, val, valdef); \
} \
CTYPE val, valdef; \
ECHECK(atot(field_value.constant.c_str(), *this, &val)); \
ECHECK(atot(field->value.constant.c_str(), *this, &valdef)); \
builder_.AddElement(field_value.offset, val, valdef); \
} \
break;
FLATBUFFERS_GEN_TYPES_SCALAR(FLATBUFFERS_TD)
@@ -2477,7 +2469,7 @@ bool Parser::SupportsOptionalScalars(const flatbuffers::IDLOptions &opts) {
IDLOptions::kRust | IDLOptions::kSwift | IDLOptions::kLobster |
IDLOptions::kKotlin | IDLOptions::kCpp | IDLOptions::kJava |
IDLOptions::kCSharp | IDLOptions::kTs | IDLOptions::kBinary |
IDLOptions::kGo | IDLOptions::kPython | IDLOptions::kJson;
IDLOptions::kGo | IDLOptions::kPython;
unsigned long langs = opts.lang_to_generate;
return (langs > 0 && langs < IDLOptions::kMAX) && !(langs & ~supported_langs);
}