mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
SERVER-55960 always pass field name to IDL serializer
This commit is contained in:
parent
0e967d6ed3
commit
eff94d95ae
@ -1980,7 +1980,11 @@ class _CppSourceFileWriter(_CppFileWriterBase):
|
||||
method_name = writer.get_method_name(field.type.serializer)
|
||||
template_params['method_name'] = method_name
|
||||
|
||||
if field.type.is_array:
|
||||
if field.chained:
|
||||
# Just directly call the serializer for chained structs without opening up a
|
||||
# nested document.
|
||||
self._writer.write_template('${access_member}.${method_name}(builder);')
|
||||
elif field.type.is_array:
|
||||
self._writer.write_template(
|
||||
'BSONArrayBuilder arrayBuilder(builder->subarrayStart(${field_name}));')
|
||||
with self._block('for (const auto& item : ${access_member}) {', '}'):
|
||||
@ -1988,7 +1992,8 @@ class _CppSourceFileWriter(_CppFileWriterBase):
|
||||
'BSONObjBuilder subObjBuilder(arrayBuilder.subobjStart());')
|
||||
self._writer.write_template('item.${method_name}(&subObjBuilder);')
|
||||
else:
|
||||
self._writer.write_template('${access_member}.${method_name}(builder);')
|
||||
self._writer.write_template(
|
||||
'${access_member}.${method_name}(${field_name}, builder);')
|
||||
|
||||
def _gen_serializer_method_struct(self, field):
|
||||
# type: (ast.Field) -> None
|
||||
|
@ -172,14 +172,14 @@ public:
|
||||
uasserted(ErrorCodes::FailedToParse, "w has to be a number or string");
|
||||
}
|
||||
|
||||
void serializeWriteConcernW(BSONObjBuilder* builder) const {
|
||||
void serializeWriteConcernW(StringData fieldName, BSONObjBuilder* builder) const {
|
||||
if (auto stringVal = stdx::get_if<std::string>(&_w)) {
|
||||
builder->append("w", *stringVal);
|
||||
builder->append(fieldName, *stringVal);
|
||||
return;
|
||||
}
|
||||
auto intVal = stdx::get_if<std::int64_t>(&_w);
|
||||
invariant(intVal);
|
||||
builder->appendNumber("w", static_cast<long long>(*intVal));
|
||||
builder->appendNumber(fieldName, static_cast<long long>(*intVal));
|
||||
}
|
||||
|
||||
WriteConcernW() : _w{1}, _usedDefault{true} {};
|
||||
|
Loading…
Reference in New Issue
Block a user