def _to_pb(self, pb=None, allow_partial=False, set_key=True):
if not allow_partial:<EOL><INDENT>self._check_initialized()<EOL><DEDENT>if pb is None:<EOL><INDENT>pb = entity_pb.EntityProto()<EOL><DEDENT>if set_key:<EOL><INDENT>self._key_to_pb(pb)<EOL><DEDENT>for unused_name, prop in sorted(self._properties.iteritems()):<EOL><INDENT>prop._serialize(self, pb, projection=self._projection)<EOL><DEDENT>return pb<EOL>
Internal helper to turn an entity into an EntityProto protobuf.