"""Standalone Python echo server for benchmarking.

Usage: python bench_python_server.py <cert_path> <key_path> <port> [codec]

codec: "json" or "protobuf" (default: "protobuf")

Starts a Knafeh server with a Python EchoService on the given port,
prints "READY" to stdout when bound, then serves forever.
"""

import asyncio
import sys

from knafeh._native import RpcServer, ServiceHandler, TlsConfig


async def main():
    cert_path, key_path, port = sys.argv[1], sys.argv[2], sys.argv[3]

    tls = TlsConfig.server(cert_path, key_path)
    server = RpcServer(f"127.0.0.1:{port}", tls)

    handler = ServiceHandler("echo")
    handler.add_unary_handler("echo", lambda req: req)
    server.add_service(handler)

    print("READY", flush=True)
    await server.start()


if __name__ == "__main__":
    asyncio.run(main())
