diff options
author | Sara Golemon <sara.golemon@mongodb.com> | 2021-08-05 18:46:09 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-08-23 18:41:54 +0000 |
commit | 5f0ea16eed2bf1292077baa654f80a0acefeed8b (patch) | |
tree | b02ed69c288c5b01f95489a62f8a95ac6bf9e431 /buildscripts | |
parent | 7bada458c6185d97803390e9850590aa799b37b0 (diff) | |
download | mongo-5f0ea16eed2bf1292077baa654f80a0acefeed8b.tar.gz |
SERVER-59453 Add support for generic BSONArray to IDL
Diffstat (limited to 'buildscripts')
-rw-r--r-- | buildscripts/idl/idl/binder.py | 2 | ||||
-rw-r--r-- | buildscripts/idl/idl/bson.py | 2 | ||||
-rw-r--r-- | buildscripts/idl/idl/cpp_types.py | 32 | ||||
-rw-r--r-- | buildscripts/idl/idl/generator.py | 2 |
4 files changed, 35 insertions, 3 deletions
diff --git a/buildscripts/idl/idl/binder.py b/buildscripts/idl/idl/binder.py index 2f1917a6f06..ab50d0bcc35 100644 --- a/buildscripts/idl/idl/binder.py +++ b/buildscripts/idl/idl/binder.py @@ -201,7 +201,7 @@ def _validate_type_properties(ctxt, idl_type, syntax_type): ctxt.add_missing_ast_required_field_error(idl_type, syntax_type, idl_type.name, "deserializer") - elif not bson_type in ["object", "bindata"]: + elif not bson_type in ["array", "object", "bindata"]: if idl_type.deserializer is None: ctxt.add_missing_ast_required_field_error(idl_type, syntax_type, idl_type.name, "deserializer") diff --git a/buildscripts/idl/idl/bson.py b/buildscripts/idl/idl/bson.py index 3d1e004dbc0..3f8e5190f9d 100644 --- a/buildscripts/idl/idl/bson.py +++ b/buildscripts/idl/idl/bson.py @@ -40,7 +40,7 @@ _BSON_TYPE_INFORMATION = { "double": {'scalar': True, 'bson_type_enum': 'NumberDouble'}, "string": {'scalar': True, 'bson_type_enum': 'String'}, "object": {'scalar': False, 'bson_type_enum': 'Object'}, - # TODO: add support: "array" : { 'scalar' : False, 'bson_type_enum' : 'Array'}, + "array": {'scalar': False, 'bson_type_enum': 'Array'}, "bindata": {'scalar': True, 'bson_type_enum': 'BinData'}, "undefined": {'scalar': True, 'bson_type_enum': 'Undefined'}, "objectid": {'scalar': True, 'bson_type_enum': 'jstOID'}, diff --git a/buildscripts/idl/idl/cpp_types.py b/buildscripts/idl/idl/cpp_types.py index bb7ec7d0a22..8971d5715c8 100644 --- a/buildscripts/idl/idl/cpp_types.py +++ b/buildscripts/idl/idl/cpp_types.py @@ -652,6 +652,34 @@ class _ObjectBsonCppTypeBase(BsonCppTypeBase): return "localObject" +class _ArrayBsonCppTypeBase(BsonCppTypeBase): + """Custom C++ support for array BSON types.""" + + def gen_deserializer_expression(self, indented_writer, object_instance): + # type: (writer.IndentedTextWriter, str) -> str + if self._ast_type.deserializer: + indented_writer.write_line( + common.template_args('BSONArray localArray(${object_instance}.Obj());', + object_instance=object_instance)) + return "localArray" + + # Just pass the BSONObj through without trying to parse it. + return common.template_args('BSONArray(${object_instance}.Obj())', + object_instance=object_instance) + + def has_serializer(self): + # type: () -> bool + return self._ast_type.serializer is not None + + def gen_serializer_expression(self, indented_writer, expression): + # type: (writer.IndentedTextWriter, str) -> str + method_name = writer.get_method_name(self._ast_type.serializer) + indented_writer.write_line( + common.template_args('BSONArray localArray(${expression}.${method_name}());', + expression=expression, method_name=method_name)) + return "localArray" + + class _BinDataBsonCppTypeBase(BsonCppTypeBase): """Custom C++ support for all binData BSON types.""" @@ -690,6 +718,7 @@ class _BinDataBsonCppTypeBase(BsonCppTypeBase): def get_bson_cpp_type(ast_type): # type: (ast.Type) -> Optional[BsonCppTypeBase] """Get a class that provides custom serialization for the given BSON type.""" + # pylint: disable=too-many-return-statements # Does not support list of types if len(ast_type.bson_serialization_type) > 1: @@ -701,6 +730,9 @@ def get_bson_cpp_type(ast_type): if ast_type.bson_serialization_type[0] == 'object': return _ObjectBsonCppTypeBase(ast_type) + if ast_type.bson_serialization_type[0] == 'array': + return _ArrayBsonCppTypeBase(ast_type) + if ast_type.bson_serialization_type[0] == 'bindata': return _BinDataBsonCppTypeBase(ast_type) diff --git a/buildscripts/idl/idl/generator.py b/buildscripts/idl/idl/generator.py index a20f64bbcd8..51569af4d4f 100644 --- a/buildscripts/idl/idl/generator.py +++ b/buildscripts/idl/idl/generator.py @@ -1206,7 +1206,7 @@ class _CppSourceFileWriter(_CppFileWriterBase): method_name=method_name, expression=expression) # BSONObjects are allowed to be pass through without deserialization - assert ast_type.bson_serialization_type == ['object'] + assert ast_type.bson_serialization_type in [['object'], ['array']] return expression # Call a static class method with the signature: |