def to_netstring(buff):
    """
    Converts a buffer into a netstring.

        >>> to_netstring(b'hello')
        b'5:hello,'
        >>> to_netstring(b'with a nul\\x00')
        b'11:with a nul\\x00,'
    """
    bytes_length = str(len(buff)).encode('ascii')
    return bytes_length + b':' + buff + b','