def _key_to_pb(self, pb):
key = self._key<EOL>if key is None:<EOL><INDENT>pairs = [(self._get_kind(), None)]<EOL>ref = key_module._ReferenceFromPairs(pairs, reference=pb.mutable_key())<EOL><DEDENT>else:<EOL><INDENT>ref = key.reference()<EOL>pb.mutable_key().CopyFrom(ref)<EOL><DEDENT>group = pb.mutable_entity_group()  <EOL>if key is not None and key.id():<EOL><INDENT>elem = ref.path().element(<NUM_LIT:0>)<EOL>if elem.id() or elem.name():<EOL><INDENT>group.add_element().CopyFrom(elem)<EOL><DEDENT><DEDENT>
Internal helper to copy the key into a protobuf.