def _format(command, body, headers):
    """
    Return a formatted STOMP frame as a bytestring.
    """
    bits = [command, '\n']
    if body:
        bits.extend(('content-length:', str(len(body)), '\n'))
    for key, value in headers.iteritems():
        bits.extend((key.replace('_', '-'), ':', str(value), '\n'))
    bits.extend(('\n', body or '', '\x00\n\n\n\n'))
    return ''.join(bits)
