def _projected_entity_to_message(ent, message_type):
msg = message_type()<EOL>analyzed = _analyze_indexed_fields(ent._projection)<EOL>for name, sublist in analyzed.iteritems():<EOL><INDENT>prop = ent._properties[name]<EOL>val = prop._get_value(ent)<EOL>assert isinstance(prop, model.StructuredProperty) == bool(sublist)<EOL>if sublist:<EOL><INDENT>field = message_type.field_by_name(name)<EOL>assert isinstance(field, messages.MessageField)<EOL>assert prop._repeated == field.repeated<EOL>if prop._repeated:<EOL><INDENT>assert isinstance(val, list)<EOL>val = [_projected_entity_to_message(v, field.type) for v in val]<EOL><DEDENT>else:<EOL><INDENT>assert isinstance(val, prop._modelclass)<EOL>val = _projected_entity_to_message(val, field.type)<EOL><DEDENT><DEDENT>setattr(msg, name, val)<EOL><DEDENT>return msg<EOL>
Recursive helper for _from_base_type() to convert an entity to a message.

    Args:
      ent: A Model instance.
      message_type: A Message subclass.

    Returns:
      An instance of message_type.