parameters: (self, struct, bson_object)
return_statement: return field_usage_check
docstring: Generate the C++ code to deserialize list of fields.
docstring_summary: Generate the C++ code to deserialize list of fields.
docstring_tokens: Generate the C ++ code to deserialize list of fields .
function: def _gen_fields_deserializer_common(self, struct, bson_object):
          # type: (ast.Struct, str) -> _FieldUsageCheckerBase
          """Generate the C++ code to deserialize list of fields."""
          # pylint: disable=too-many-branches
          field_usage_check = _get_field_usage_checker(self._writer, struct)
          if isinstance(struct, ast.Command):
              self._writer.write_line('BSONElement commandElement;')
              self._writer.write_line('bool firstFieldFound = false;')
  
          self._writer.write_empty_line()
  
          with self._block('for (const auto& element :%s) {' % (bson_object), '}'):
  
              self._writer.write_line('const auto fieldName = element.fieldNameStringData();')
              self._writer.write_empty_line()
  
              if isinstance(struct, ast.Command):
                  with self._predicate("firstFieldFound == false"):
                      # Get the Command element if we need it for later in the deserializer to get the
                      # namespace
                      if struct.namespace != common.COMMAND_NAMESPACE_IGNORED:
                          self._writer.write_line('commandElement = element;')
  
                      self._writer.write_line('firstFieldFound = true;')
                      self._writer.write_line('continue;')
  
              self._writer.write_empty_line()
  
              first_field = True
              for field in struct.fields:
                  # Do not parse chained fields as fields since they are actually chained types.
                  if field.chained and not field.chained_struct_field:
                      continue
  
                  field_predicate = 'fieldName == %s' % (_get_field_constant_name(field))
  
                  with self._predicate(field_predicate, not first_field):
  
                      if field.ignore:
                          field_usage_check.add(field, "element")
  
                          self._writer.write_line('// ignore field')
                      else:
                          self.gen_field_deserializer(field, field.type, bson_object, "element",
                                                      field_usage_check)
  
                  if first_field:
                      first_field = False
  
              # End of for fields
              # Generate strict check for extranous fields
              if struct.strict:
                  # For commands, check if this is a well known command field that the IDL parser
                  # should ignore regardless of strict mode.
                  command_predicate = None
                  if isinstance(struct, ast.Command):
                      command_predicate = "!mongo::isGenericArgument(fieldName)"
  
                  with self._block('else {', '}'):
                      with self._predicate(command_predicate):
                          self._writer.write_line('ctxt.throwUnknownField(fieldName);')
              else:
                  with self._else(not first_field):
                      self._writer.write_line('auto push_result = usedFieldSet.insert(fieldName);')
                      with writer.IndentedScopedBlock(
                              self._writer, 'if (MONGO_unlikely(push_result.second == false)) {',
                              '}'):
                          self._writer.write_line('ctxt.throwDuplicateField(fieldName);')
  
          # Parse chained structs if not inlined
          # Parse chained types always here
          for field in struct.fields:
              if not field.chained or \
                      (field.chained and field.type.is_struct and struct.inline_chained_structs):
                  continue
  
              # Simply generate deserializers since these are all 'any' types
              self.gen_field_deserializer(field, field.type, bson_object, "element", None)
              self._writer.write_empty_line()
  
          self._writer.write_empty_line()
  
          return field_usage_check
function_tokens: def _gen_fields_deserializer_common ( self , struct , bson_object ) : # type: (ast.Struct, str) -> _FieldUsageCheckerBase # pylint: disable=too-many-branches field_usage_check = _get_field_usage_checker ( self . _writer , struct ) if isinstance ( struct , ast . Command ) : self . _writer . write_line ( 'BSONElement commandElement;' ) self . _writer . write_line ( 'bool firstFieldFound = false;' ) self . _writer . write_empty_line ( ) with self . _block ( 'for (const auto& element :%s) {' % ( bson_object ) , '}' ) : self . _writer . write_line ( 'const auto fieldName = element.fieldNameStringData();' ) self . _writer . write_empty_line ( ) if isinstance ( struct , ast . Command ) : with self . _predicate ( "firstFieldFound == false" ) : # Get the Command element if we need it for later in the deserializer to get the # namespace if struct . namespace != common . COMMAND_NAMESPACE_IGNORED : self . _writer . write_line ( 'commandElement = element;' ) self . _writer . write_line ( 'firstFieldFound = true;' ) self . _writer . write_line ( 'continue;' ) self . _writer . write_empty_line ( ) first_field = True for field in struct . fields : # Do not parse chained fields as fields since they are actually chained types. if field . chained and not field . chained_struct_field : continue field_predicate = 'fieldName == %s' % ( _get_field_constant_name ( field ) ) with self . _predicate ( field_predicate , not first_field ) : if field . ignore : field_usage_check . add ( field , "element" ) self . _writer . write_line ( '// ignore field' ) else : self . gen_field_deserializer ( field , field . type , bson_object , "element" , field_usage_check ) if first_field : first_field = False # End of for fields # Generate strict check for extranous fields if struct . strict : # For commands, check if this is a well known command field that the IDL parser # should ignore regardless of strict mode. command_predicate = None if isinstance ( struct , ast . Command ) : command_predicate = "!mongo::isGenericArgument(fieldName)" with self . _block ( 'else {' , '}' ) : with self . _predicate ( command_predicate ) : self . _writer . write_line ( 'ctxt.throwUnknownField(fieldName);' ) else : with self . _else ( not first_field ) : self . _writer . write_line ( 'auto push_result = usedFieldSet.insert(fieldName);' ) with writer . IndentedScopedBlock ( self . _writer , 'if (MONGO_unlikely(push_result.second == false)) {' , '}' ) : self . _writer . write_line ( 'ctxt.throwDuplicateField(fieldName);' ) # Parse chained structs if not inlined # Parse chained types always here for field in struct . fields : if not field . chained or ( field . chained and field . type . is_struct and struct . inline_chained_structs ) : continue # Simply generate deserializers since these are all 'any' types self . gen_field_deserializer ( field , field . type , bson_object , "element" , None ) self . _writer . write_empty_line ( ) self . _writer . write_empty_line ( ) return field_usage_check