API
#github.com/xulang-org/packages/grpc
Xu 0.8.8 API
import: grpc #github.com/xulang-org/packages/grpc
counts: 19 fns, 8 methods, 5 types, 20 consts, 0 ifaces
gRPC & HTTP/2 High-Performance RPC Driver for Xu Implements HTTP/2 frame framing, HPACK headers, Protobuf serialization, and Unary RPC connection pooling.
github.com/xulang-org/packages · 0.1.1 · Install and use
struct Response
pub struct Response {
pub status int
pub message string
pub payload string
}
Purpose
Public struct `Response`.
Parameters
status int- field (int)
message string- field (string)
payload string- field (string)
struct GrpcClient
pub struct GrpcClient {
pub host string
pub port int
}
Purpose
Public struct `GrpcClient`.
Parameters
host string- host
port int- port
new_client
pub fn new_client(endpoint string) GrpcClient
Purpose
Construct client.
Parameters
endpoint string- endpoint (string)
Returns
GrpcClient — a value of this type
(GrpcClient) read_h2_frame
pub fn (c GrpcClient) read_h2_frame(fd int) H2Frame
Purpose
Method on `GrpcClient`: read h2 frame. Throws on failure.
Parameters
c GrpcClient- receiver GrpcClient (value receiver)
fd int- file descriptor (int)
Returns
H2Frame — a value of this type
(GrpcClient) connect
pub fn (c GrpcClient) connect() int
Purpose
Call `connect` on `GrpcClient`. Throws on failure.
Parameters
c GrpcClient- receiver GrpcClient (value receiver)
Returns
int — a value of this type
(GrpcClient) call_unary
pub fn (c GrpcClient) call_unary(path string, req_bytes string) Response
Purpose
Executes an Unary RPC Call over HTTP/2 with gRPC framing Throws on failure.
Parameters
c GrpcClient- receiver GrpcClient (value receiver)
path string- filesystem path (string)
req_bytes string- req_bytes (string)
Returns
Response — a value of this type
(GrpcClient) call_unary_on_fd
pub fn (c GrpcClient) call_unary_on_fd(fd int, path string, req_bytes string, stream_id int) Response
Purpose
Method on `GrpcClient`: call unary on fd. Throws on failure.
Parameters
c GrpcClient- receiver GrpcClient (value receiver)
fd int- file descriptor (int)
path string- filesystem path (string)
req_bytes string- req_bytes (string)
stream_id int- stream_id (int)
Returns
Response — a value of this type
const h2_client_preface
pub const h2_client_preface = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"
Purpose
Public constant `h2_client_preface`. Value `"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"`.
Parameters
none
const frame_data
Purpose
HTTP/2 Frame Types Value `0`.
Parameters
none
const frame_priority
pub const frame_priority = 2
Purpose
Public constant `frame_priority`. Value `2`.
Parameters
none
const frame_rst_stream
pub const frame_rst_stream = 3
Purpose
Public constant `frame_rst_stream`. Value `3`.
Parameters
none
const frame_settings
pub const frame_settings = 4
Purpose
Public constant `frame_settings`. Value `4`.
Parameters
none
const frame_push_promise
pub const frame_push_promise = 5
Purpose
Public constant `frame_push_promise`. Value `5`.
Parameters
none
const frame_ping
Purpose
Public constant `frame_ping`. Value `6`.
Parameters
none
const frame_goaway
pub const frame_goaway = 7
Purpose
Public constant `frame_goaway`. Value `7`.
Parameters
none
const frame_window_update
pub const frame_window_update = 8
Purpose
Public constant `frame_window_update`. Value `8`.
Parameters
none
const frame_continuation
pub const frame_continuation = 9
Purpose
Public constant `frame_continuation`. Value `9`.
Parameters
none
const flag_ack
Purpose
HTTP/2 Flags Value `1`.
Parameters
none
const flag_end_stream
pub const flag_end_stream = 1
Purpose
Public constant `flag_end_stream`. Value `1`.
Parameters
none
const flag_padded
pub const flag_padded = 8
Purpose
Public constant `flag_padded`. Value `8`.
Parameters
none
const flag_priority
pub const flag_priority = 32
Purpose
Public constant `flag_priority`. Value `32`.
Parameters
none
struct H2Frame
pub struct H2Frame {
pub length int
pub frame_type int
pub flags int
pub stream_id int
pub payload string
}
Purpose
Public struct `H2Frame`.
Parameters
length int- field (int)
frame_type int- field (int)
flags int- field (int)
stream_id int- field (int)
payload string- field (string)
build_settings_frame
pub fn build_settings_frame(ack bool) string
Purpose
Build settings frame.
Parameters
ack bool- ack (bool)
Returns
string — result string
build_data_frame
pub fn build_data_frame(stream_id int, data string, end_stream bool) string
Purpose
Build data frame.
Parameters
stream_id int- stream_id (int)
data string- data (string)
end_stream bool- end_stream (bool)
Returns
string — result string
struct Pool
pub struct Pool {
pub client GrpcClient
pub idle chan int
pub max_idle int
}
Purpose
Public struct `Pool`.
Parameters
client GrpcClient- field (GrpcClient)
idle chan int- field (channel; type chan int)
max_idle int- field (int)
new_pool
pub fn new_pool(endpoint string, max_idle int) Pool
Purpose
Construct pool.
Parameters
endpoint string- endpoint (string)
max_idle int- max_idle (int)
Returns
Pool — a value of this type
open_pool
pub fn open_pool(endpoint string, max_idle int) Pool
Purpose
Open pool.
Parameters
endpoint string- endpoint (string)
max_idle int- max_idle (int)
Returns
Pool — a value of this type
(&Pool) get_conn
pub fn (p &Pool) get_conn() int
Purpose
Method on `&Pool`: read conn.
Parameters
p &Pool- receiver &Pool (borrow)
Returns
int — a value of this type
(&Pool) put_conn
pub fn (p &Pool) put_conn(fd int)
Purpose
Method on `&Pool`: put connection.
Parameters
p &Pool- receiver &Pool (borrow)
fd int- file descriptor (int)
(&Pool) call_unary
pub fn (p &Pool) call_unary(path string, req_bytes string) Response
Purpose
Method on `&Pool`: call unary. Throws on failure.
Parameters
p &Pool- receiver &Pool (borrow)
path string- filesystem path (string)
req_bytes string- req_bytes (string)
Returns
Response — a value of this type
(&Pool) close
Purpose
Method on `&Pool`: close the resource.
Parameters
p &Pool- receiver &Pool (borrow)
const wire_varint
pub const wire_varint = 0
Purpose
Protocol Buffers Wire Types Value `0`.
Parameters
none
const wire_fixed64
pub const wire_fixed64 = 1
Purpose
Public constant `wire_fixed64`. Value `1`.
Parameters
none
const wire_length_delimited
pub const wire_length_delimited = 2
Purpose
Public constant `wire_length_delimited`. Value `2`.
Parameters
none
const wire_fixed32
pub const wire_fixed32 = 5
Purpose
Public constant `wire_fixed32`. Value `5`.
Parameters
none
encode_varint
pub fn encode_varint(val int) string
Purpose
Encode.
Parameters
val int- value (int)
Returns
string — result string
struct VarintResult
pub struct VarintResult {
pub value int
pub bytes_read int
}
Purpose
Public struct `VarintResult`.
Parameters
value int- field (int)
bytes_read int- field (int)
decode_varint_full
pub fn decode_varint_full(buf &string, pos int) VarintResult
Purpose
Decode.
Parameters
buf &string- buffer (borrowed; caller keeps it; type &string)
pos int- pos (int)
Returns
VarintResult — a value of this type
decode_varint
pub fn decode_varint(buf &string, pos int) int
Purpose
Decode.
Parameters
buf &string- buffer (borrowed; caller keeps it; type &string)
pos int- pos (int)
Returns
int — a value of this type
encode_tag
pub fn encode_tag(field_num int, wire_type int) string
Purpose
Encode.
Parameters
field_num int- field_num (int)
wire_type int- wire_type (int)
Returns
string — result string
encode_string_field
pub fn encode_string_field(field_num int, val string) string
Purpose
Encode.
Parameters
field_num int- field_num (int)
val string- value (string)
Returns
string — result string
encode_int_field
pub fn encode_int_field(field_num int, val int) string
Purpose
Encode.
Parameters
field_num int- field_num (int)
val int- value (int)
Returns
string — result string
build_grpc_message
pub fn build_grpc_message(payload string) string
Purpose
Packages Protobuf payload into a 5-byte prefixed gRPC frame [1 byte compressed flag] + [4 bytes big-endian length] + [payload]
Parameters
payload string- payload (string)
Returns
string — result string
parse_grpc_message
pub fn parse_grpc_message(raw string) string
Purpose
Parses gRPC message frame and extracts raw protobuf payload
Parameters
raw string- raw (string)
Returns
string — result string
decode_grpc_message
pub fn decode_grpc_message(raw string) string
Purpose
Decode. Throws on failure.
Parameters
raw string- raw (string)
Returns
string — result string
get_string_field
pub fn get_string_field(payload string, target_field int) string
Purpose
Read string field.
Parameters
payload string- payload (string)
target_field int- target_field (int)
Returns
string — result string
get_int_field
pub fn get_int_field(payload string, target_field int) int
Purpose
Read int field.
Parameters
payload string- payload (string)
target_field int- target_field (int)
Returns
int — a value of this type