Class: gRPC
用于编码与解码二进制 gRPC 和 gRPC-Web 帧的辅助工具。
Helpers for encoding and decoding binary gRPC and gRPC-Web frames.
See
Constructors
Constructor
new gRPC():
gRPC
Returns
gRPC
Methods
decode()
staticdecode(bytesBody?):Uint8Array<ArrayBufferLike>
解码单个二进制 gRPC 帧,并在压缩标志要求时解压 gzip 负载。
Decodes a single binary gRPC frame and decompresses a gzip payload when required by the compression flag.
Parameters
bytesBody?
Uint8Array<ArrayBufferLike> = ...
带帧结构的 gRPC 消息。
The framed gRPC message.
Returns
Uint8Array<ArrayBufferLike>
去除帧结构后的 protobuf 负载。
The unframed protobuf payload.
decodeWeb()
staticdecodeWeb(bytesBody?):object
解码包含一个数据帧和可选末尾 trailer 帧的二进制一元 gRPC-Web 响应。
Decodes a binary unary gRPC-Web response containing one data frame and an optional final trailer frame.
Parameters
bytesBody?
Uint8Array<ArrayBufferLike> = ...
完整的 gRPC-Web 响应体。
The complete gRPC-Web response body.
Returns
object
解析后的 trailer 标头与 protobuf 负载。
The parsed trailer headers and protobuf payload.
bodyBytes
bodyBytes:
Uint8Array
header
header:
Record<string,string>
Throws
当帧格式错误、使用不支持的标志、包含多个数据帧,或 trailer 不在末尾时抛出。
Thrown when a frame is malformed, uses an unsupported flag, contains multiple data frames, or places a trailer before the end.
encode()
staticencode(body?,encoding?):Uint8Array<ArrayBufferLike>
将 protobuf 负载编码为单个二进制 gRPC 帧。
Encodes a protobuf payload as a single binary gRPC frame.
Parameters
body?
Uint8Array<ArrayBufferLike> = ...
protobuf 负载。
The protobuf payload.
encoding?
"identity" | "gzip"
负载编码方式。
The payload encoding.
Returns
Uint8Array<ArrayBufferLike>
带帧结构的 gRPC 消息。
The framed gRPC message.