Documentation
¶
Overview ¶
Package protocol carries sqlc's codegen plugin wire format across this module's boundary and no further.
sqlc invokes a plugin as a subprocess: it writes a GenerateRequest protobuf to the process's stdin, and reads a GenerateResponse protobuf back from its stdout. That makes stdout a protocol channel rather than a place to print, which is why every other package here logs to stderr and why Serve takes its streams as arguments instead of reaching for os.Stdin and os.Stdout — a test can drive the whole exchange in memory.
The wire framing stops here. Reading the analysis a request carries is the convergence core's job, and rendering it is an emitter's; this package only gets the bytes on and off the process boundary.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsPluginInvocation ¶
IsPluginInvocation reports whether args (os.Args[1:]) and stdin describe a call from sqlc rather than a person at a shell.
sqlc v1.24.0 and later pass the gRPC method to invoke as the first argument — "/plugin.CodegenService/Generate" — which is why a leading slash is the signal. Nothing a person would type as a subcommand starts with one.
Older sqlc passed no arguments at all, which is indistinguishable from a person typing `unison` and expecting help. stdin settles it: sqlc pipes the request in, a terminal does not.
func Serve ¶
Serve reads one GenerateRequest from stdin, hands it to gen, and writes the GenerateResponse to stdout. It is the entire lifetime of a plugin process: sqlc starts one per block and reads exactly one response.
An error from gen is returned rather than encoded, and nothing is written to stdout in that case. sqlc treats a non-zero exit with no response as a plugin failure and reports the process's stderr, which is where our diagnostics already are.