Files
Mahdi ramezaan zaadeandAlexander Medvednikov 8b92b156f6 net.grpc: add an experimental gRPC client and server (#29285)
* net.grpc: add an experimental gRPC client and server

Ports the gRPC runtime from we-be/grpc.v into vlib as net.grpc, closing
most of vlang/v#5017. It covers the wire layer only: 5-byte message
framing, the grpc-status/grpc-message terminal status, per-call
metadata, a native gRPC client and server over net.http's HTTP/2 stack,
and a Connect-protocol server for connectrpc.com clients.

Messages cross the wire as []u8, so the module stays codec-agnostic and
pairs with any protobuf runtime (protobuf.v and vpbgen remain external
vmodules).

Two fixes against the ported original:

- Client.do_call must set FetchConfig.enable_http2. net.http reverted
  HTTPS clients to HTTP/1.1 in #28996, so without it the client silently
  degrades and never speaks gRPC. The doc comment claiming net.http
  negotiates h2 on its own is corrected.
- Server wrappers now forward in_memory_verification, so TLS can be
  driven from in-memory PEM strings.

Client and both servers also gained verify/cert/cert_key pass-through,
needed because V has no client-side h2c: a loopback gRPC round-trip has
to go through TLS.

Listed in vlib/.vdocignore as experimental. Streaming stays buffered
(one POST per direction) because net.http's Handler is one request in /
one response out.

* examples: add a net.grpc key-value example

An etcd-lite key-value service showing net.grpc end to end: all three
RPC shapes (unary, server streaming, client streaming), a typed
StatusError crossing the wire as a grpc-status trailer, a call carrying
a deadline and request metadata, and response/trailer metadata.

net.grpc is transport-only and moves []u8 payloads, so the example owns
its codec: kv/codec.v is a hand-written proto3 encoder/decoder for the
schema in kv.proto, with tests. That keeps the example free of external
dependencies, which v build-examples needs since it walks every
examples/**/*.v file that declares `module main`.

The TLS certificate is required rather than optional: gRPC is HTTP/2-only
and net.http negotiates h2 only for https, so even a loopback round-trip
has to speak TLS, as V has no client-side h2c path.

* net.grpc: preserve explicit status and ordered request metadata

---------

Co-authored-by: Alexander Medvednikov <alexander@medvednikov.com>
2026-10-02 12:54:26 +03:00
..