summaryrefslogtreecommitdiff
path: root/buildscripts/idl
diff options
context:
space:
mode:
Diffstat (limited to 'buildscripts/idl')
-rw-r--r--buildscripts/idl/idl/generator.py45
-rw-r--r--buildscripts/idl/idl/struct_types.py38
2 files changed, 36 insertions, 47 deletions
diff --git a/buildscripts/idl/idl/generator.py b/buildscripts/idl/idl/generator.py
index f48edb84f70..9f591eccc4f 100644
--- a/buildscripts/idl/idl/generator.py
+++ b/buildscripts/idl/idl/generator.py
@@ -972,20 +972,31 @@ class _CppSourceFileWriter(_CppFileWriterBase):
return field_usage_check
+ def get_bson_deserializer_static_common(self, struct, static_method_info, method_info):
+ # type: (ast.Struct, struct_types.MethodInfo, struct_types.MethodInfo) -> None
+ """Generate the C++ deserializer static method."""
+ # pylint: disable=invalid-name
+ func_def = static_method_info.get_definition()
+
+ with self._block('%s {' % (func_def), '}'):
+ if isinstance(struct,
+ ast.Command) and struct.namespace != common.COMMAND_NAMESPACE_IGNORED:
+ self._writer.write_line('NamespaceString localNS;')
+ self._writer.write_line('%s object(localNS);' % (common.title_case(struct.name)))
+ else:
+ self._writer.write_line('%s object;' % common.title_case(struct.name))
+
+ self._writer.write_line(method_info.get_call('object'))
+ self._writer.write_line('return object;')
+
def gen_bson_deserializer_methods(self, struct):
# type: (ast.Struct) -> None
"""Generate the C++ deserializer method definitions."""
struct_type_info = struct_types.get_struct_info(struct)
- if not struct_type_info.get_deserializer_static_method():
- return
- assert not isinstance(struct, ast.Command)
-
- with self._block('%s {' %
- (struct_type_info.get_deserializer_static_method().get_definition()), '}'):
- self._writer.write_line('%s object;' % common.title_case(struct.name))
- self._writer.write_line(struct_type_info.get_deserializer_method().get_call('object'))
- self._writer.write_line('return object;')
+ self.get_bson_deserializer_static_common(struct,
+ struct_type_info.get_deserializer_static_method(),
+ struct_type_info.get_deserializer_method())
func_def = struct_type_info.get_deserializer_method().get_definition()
with self._block('%s {' % (func_def), '}'):
@@ -1010,18 +1021,10 @@ class _CppSourceFileWriter(_CppFileWriterBase):
struct_type_info = struct_types.get_struct_info(struct)
- func_def = struct_type_info.get_op_msg_request_deserializer_static_method().get_definition()
- with self._block('%s {' % (func_def), '}'):
- if isinstance(struct,
- ast.Command) and struct.namespace != common.COMMAND_NAMESPACE_IGNORED:
- self._writer.write_line('NamespaceString localNS;')
- self._writer.write_line('%s object(localNS);' % (common.title_case(struct.name)))
- else:
- self._writer.write_line('%s object;' % common.title_case(struct.name))
-
- self._writer.write_line(
- struct_type_info.get_op_msg_request_deserializer_method().get_call('object'))
- self._writer.write_line('return object;')
+ self.get_bson_deserializer_static_common(
+ struct,
+ struct_type_info.get_op_msg_request_deserializer_static_method(),
+ struct_type_info.get_op_msg_request_deserializer_method())
func_def = struct_type_info.get_op_msg_request_deserializer_method().get_definition()
with self._block('%s {' % (func_def), '}'):
diff --git a/buildscripts/idl/idl/struct_types.py b/buildscripts/idl/idl/struct_types.py
index 4db645235a4..9e2a9504acd 100644
--- a/buildscripts/idl/idl/struct_types.py
+++ b/buildscripts/idl/idl/struct_types.py
@@ -219,18 +219,6 @@ class _StructTypeInfo(StructTypeInfoBase):
class_name = common.title_case(self._struct.name)
return MethodInfo(class_name, class_name, [])
- def get_serializer_method(self):
- # type: () -> MethodInfo
- return MethodInfo(
- common.title_case(self._struct.name),
- 'serialize', ['BSONObjBuilder* builder'],
- 'void',
- const=True)
-
- def get_to_bson_method(self):
- # type: () -> MethodInfo
- return MethodInfo(common.title_case(self._struct.name), 'toBSON', [], 'BSONObj', const=True)
-
def get_deserializer_static_method(self):
# type: () -> MethodInfo
class_name = common.title_case(self._struct.name)
@@ -246,6 +234,18 @@ class _StructTypeInfo(StructTypeInfoBase):
common.title_case(self._struct.name), 'parseProtected',
['const IDLParserErrorContext& ctxt', 'const BSONObj& bsonObject'], 'void')
+ def get_serializer_method(self):
+ # type: () -> MethodInfo
+ return MethodInfo(
+ common.title_case(self._struct.name),
+ 'serialize', ['BSONObjBuilder* builder'],
+ 'void',
+ const=True)
+
+ def get_to_bson_method(self):
+ # type: () -> MethodInfo
+ return MethodInfo(common.title_case(self._struct.name), 'toBSON', [], 'BSONObj', const=True)
+
def get_op_msg_request_serializer_method(self):
# type: () -> Optional[MethodInfo]
return None
@@ -285,20 +285,6 @@ class _CommandBaseTypeInfo(_StructTypeInfo):
super(_CommandBaseTypeInfo, self).__init__(command)
- def get_deserializer_static_method(self):
- # type: () -> MethodInfo
- # For commands, do not generate a parse(BSONObj) method because if the "$db" is missing,
- # users may not know that it defaults to admin. Force them to explictly use OpMsgRequest
- # and OpMsgRequest::fromDbAndBody.
- return None
-
- def get_deserializer_method(self):
- # type: () -> MethodInfo
- # For commands, do not generate a parse(BSONObj) method because if the "$db" is missing,
- # users may not know that it defaults to admin. Force them to explictly use OpMsgRequest
- # and OpMsgRequest::fromDbAndBody.
- return None
-
def get_op_msg_request_serializer_method(self):
# type: () -> Optional[MethodInfo]
return MethodInfo(