def encode_request(command, pathname, params):
    """Encode a command, pathname and parameters into a turnip-proto-request.
    """
    if b' ' in command or b'\x00' in pathname:
        raise ValueError('Metacharacter in arguments')
    bits = [pathname]
    for name in sorted(params):
        value = params[name]
        if b'=' in name or b'\x00' in name + value:
            raise ValueError('Metacharacter in arguments')
        bits.append(name + b'=' + value)
    return command + b' ' + b'\x00'.join(bits) + b'\x00'
