Skip to content

11 Protocol Router Pseudocode

Protocol Router (pseudocode) def on_new_connection(sock): # Optionally wrap in TLS first and use ALPN to fast-path selection peek = sock.peek(8)

if looks_like_postgres_startup(peek):
return handle_postgres(sock)
if looks_like_tds_prelogin(peek):
return handle_tds(sock)
if looks_like_drda_excsat(peek):
return handle_drda(sock)
if looks_like_oracle_connect(peek):
return handle_oracle(sock)
# MySQL expects *server sends first* (HandshakeV10)
if undecided():
return handle_mysql(sock) # send handshake; proceed
if looks_like_http(peek):
path = sniff_http_path(sock)
if path.startswith("/snowflake/"):
return handle_snowflake_http(sock)
if path.startswith("/dbsql/"):
return handle_databricks_http(sock)
if path.startswith("/pinecone/"):
return handle_pinecone_http(sock)
reject_with_clear_error(sock, "Unsupported or malformed protocol")

Handler contract

Parse auth → SessionCtx (user, db, roles, tx mode).

Parse query/stmt → LogicalPlan via dialect adapter.

Execute plan → stream RowBatches.

Map Errors to ecosystem-native codes.