def _rewind_past_close_curly(output_buffer):
    """A utility function for rewinding a buffer that had a JSON object emitted to it.  It rewinds past the
    last closing curly brace in the buffer, and then also erases the last non-whitespace character after that
    if it is a comma (which shouldn't happen in practice).  This is meant to prepare the buffer for emitting
    new fields into the JSON object's serialization.

    @param output_buffer:  The buffer to rewind.
    @type output_buffer: StringO
    """
    # Now go back and find the last '}' and delete it so that we can open up the JSON again.
    location = output_buffer.tell()
    while location > 0:
        location -= 1
        output_buffer.seek(location)
        if output_buffer.read(1) == '}':
            break

    # Now look for the first non-white character.  We need to add in a comma after it.
    last_char = None
    while location > 0:
        location -= 1
        output_buffer.seek(location)
        last_char = output_buffer.read(1)
        if not last_char.isspace():
            break

    # If the character happened to a comma, back up over that since we want to write our own comma.
    if location > 0 and last_char == ',':
        location -= 1

    if location < 0:
        raise Exception('Could not locate trailing "}" and non-whitespace in JSON serialization')

    # Now chop off everything after the character at the location.
    location += 1
    output_buffer.seek(location)
    output_buffer.truncate()


# The last timestamp used for any event uploaded to the server.  We need to guarantee that this is monotonically
# increasing so we track it in a global var.
dataset/ETHPy150Open scalyr/scalyr-agent-2/scalyr_agent/scalyr_client.py/_rewind_past_close_curly/original