gizlang:grpc
gRPC (https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md) over HTTP/2. A message is bytes (the caller encodes it with gizlang:protobuf, or any codec). service makes the Http handler of the methods of a server; dial and Channel.call call a server. A call sends all its request messages and reads all its replies: unary, client-streaming and server-streaming calls fit, and the server may send its replies as it makes them. Messages are not compressed.
import * as Grpc from "gizlang:grpc";Types
Status
type Status = { code: i64; message: string; }How a call ended: a code (OK, or one above) and the server's message.
code:i64message:string
Replies
type RepliesThe replies of a call in progress, sent as the method makes them.
Opaque: create and use it through this module's functions.
Handler
type Handler = (request: Http.Request, messages: Vec<bytes>, replies: mut Replies) => StatusA method: it gets the request (its headers are the call's metadata) and the request messages, sends replies, and returns the status.
Method
type Method = { path: string; run: Handler; }The method at path, "/package.Service/Method".
path:stringrun:(request: gizlang_http.Request, messages: Vec<bytes>, replies: mut gizlang_grpc.Replies) => gizlang_grpc.Status
Channel
type ChannelA connection to a gRPC server.
Opaque: create and use it through this module's functions.
Functions
frame
function frame(message: bytes): bytesA message with its 5-byte prefix: not compressed, and its length.
Effects: fail.
unframe
function unframe(data: bytes): Vec<bytes> throws stringThe messages of a body made of framed messages; an error for a cut or compressed one.
Effects: fail.
service
function service(methods: Vec<Method>): (request: Http.Request) => Http.ReplyPlanThe handler of a gRPC server for Http.serve (over h2c or TLS with ALPN h2): a request for a path that is not a method gets UNIMPLEMENTED, and one that is not a gRPC call gets 415. A method that returns does so with the status in the trailers.
use
function use(stream: Stream, authority: string, secure: bool): Channel throws stringCalls over a stream that speaks HTTP/2 from its first byte (a TLS stream that chose h2, with secure).
Effects: fail, io.
dial
function dial(sys: System, host: string, port: i64): Channel throws stringA channel to host:port over a plain TCP connection (h2c).
Effects: fail, io.
Methods
Replies.send
function Replies.send(self: mut Replies, message: bytes): bool throws Http.HttpErrorSends one reply message.
Effects: fail, read, write, console, io.
Channel.call
function Channel.call(self: mut Channel, path: string, messages: Vec<bytes>, metadata: Vec<Http.Header>): Vec<bytes> throws StatusOne call: the request messages go out, the replies and the server's status come back. metadata are extra request headers.
Err has the status when the call ended in an error.
Effects: fail, io.
Channel.close
function Channel.close(self: mut Channel): voidCloses the channel.
Effects: fail, io.
Constants
OK
const OK = 0The status codes of a call.
CANCELLED
const CANCELLED = 1The caller cancelled the call.
UNKNOWN
const UNKNOWN = 2An error that no other code describes.
INVALID_ARGUMENT
const INVALID_ARGUMENT = 3The client gave an argument that is not valid.
DEADLINE_EXCEEDED
const DEADLINE_EXCEEDED = 4The deadline ended before the call completed.
NOT_FOUND
const NOT_FOUND = 5The requested entity does not exist.
ALREADY_EXISTS
const ALREADY_EXISTS = 6The entity that the client tried to create exists.
PERMISSION_DENIED
const PERMISSION_DENIED = 7The caller may not do the operation.
RESOURCE_EXHAUSTED
const RESOURCE_EXHAUSTED = 8A resource or quota is used up.
FAILED_PRECONDITION
const FAILED_PRECONDITION = 9The system is not in the state that the operation needs.
ABORTED
const ABORTED = 10The operation stopped, often on a concurrency conflict.
OUT_OF_RANGE
const OUT_OF_RANGE = 11The operation went past the valid range.
UNIMPLEMENTED
const UNIMPLEMENTED = 12The server does not implement or support the operation.
INTERNAL
const INTERNAL = 13An internal error of the server.
UNAVAILABLE
const UNAVAILABLE = 14The service is not available now; a retry can succeed.
DATA_LOSS
const DATA_LOSS = 15Data was lost or corrupted and cannot be recovered.
UNAUTHENTICATED
const UNAUTHENTICATED = 16The call has no valid credentials.