code: def _flatten_projection(cls, projection):
          
  
          # If `projection` is empty return a full projection
          if not projection:
              return {'__': False}, {}, {}
  
          # Flatten the projection
          flat_projection = {}
          references = {}
          subs = {}
          inclusive = True
          for key, value in deepcopy(projection).items():
              if isinstance(value, dict):
                  # Store a reference/SubFrame projection
                  if '$ref' in value:
                      references[key] = value
                  elif '$sub' in value or '$sub.' in value:
                      subs[key] = value
                  flat_projection[key] = True
  
              elif key == '$ref':
                  # Strip any `$ref` key
                  continue
  
              elif key == '$sub' or key == '$sub.':
                  # Strip any `$sub` key
                  continue
  
              else:
                  # Store the root projection value
                  flat_projection[key] = value
                  inclusive = False
  
          # If only references and `SubFrames` were specified in the projection
          # then return a full projection.
          if inclusive:
              flat_projection = {'__': False}
  
          return flat_projection, references, subs
docs: Flatten a structured projection (structure projections support for
          projections of (to be) dereferenced fields.