def METHOD_NAME(self):
    # This method may be called multiple times on the same batch
    # i.e., on retries
    # we need to make sure we only close it out once
    # otherwise compressed messages may be double-compressed
    # see Issue 718
    if not self._closed:
        self._bytes_written = self._builder.size()
        self._buffer = bytes(self._builder.build())
        self._builder = None
    self._closed = True