struct Response
pub struct Response {
pub status int
pub message string
pub payload string
}用途
公开结构体 `Response`。
参数
statusint- 字段(int)
messagestring- 字段(string)
payloadstring- 字段(string)
API
#github.com/xulang-org/packages/grpc扩展包 `grpc #github.com/xulang-org/packages/grpc`,由模块 github.com/xulang-org/packages 提供。
github.com/xulang-org/packages · 0.1.1 · 安装与使用
struct Responsepub struct Response {
pub status int
pub message string
pub payload string
}公开结构体 `Response`。
status intmessage stringpayload stringstruct GrpcClientpub struct GrpcClient {
pub host string
pub port int
}公开结构体 `GrpcClient`。
host stringport intnew_clientpub fn new_client(endpoint string) GrpcClient构造 client。
endpoint stringGrpcClient — 该类型的值
(GrpcClient) read_h2_framepub fn (c GrpcClient) read_h2_frame(fd int) H2Frame`GrpcClient` 上的方法:读取h2frame。失败时 throw。
c GrpcClientfd intH2Frame — 该类型的值
(GrpcClient) connectpub fn (c GrpcClient) connect() int在 `GrpcClient` 上调用 `connect`。失败时 throw。
c GrpcClientint — 该类型的值
(GrpcClient) call_unarypub fn (c GrpcClient) call_unary(path string, req_bytes string) Response`GrpcClient` 上的方法:callunary。失败时 throw。
c GrpcClientpath stringreq_bytes stringResponse — 该类型的值
(GrpcClient) call_unary_on_fdpub fn (c GrpcClient) call_unary_on_fd(fd int, path string, req_bytes string, stream_id int) Response`GrpcClient` 上的方法:callunary于fd。失败时 throw。
c GrpcClientfd intpath stringreq_bytes stringstream_id intResponse — 该类型的值
const h2_client_prefacepub const h2_client_preface = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"公开常量 `h2_client_preface`。 值为 `"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"`
无
const frame_datapub const frame_data = 0公开常量 `frame_data`。 值为 `0`
无
const frame_headerspub const frame_headers = 1公开常量 `frame_headers`。 值为 `1`
无
const frame_prioritypub const frame_priority = 2公开常量 `frame_priority`。 值为 `2`
无
const frame_rst_streampub const frame_rst_stream = 3公开常量 `frame_rst_stream`。 值为 `3`
无
const frame_settingspub const frame_settings = 4公开常量 `frame_settings`。 值为 `4`
无
const frame_push_promisepub const frame_push_promise = 5公开常量 `frame_push_promise`。 值为 `5`
无
const frame_pingpub const frame_ping = 6公开常量 `frame_ping`。 值为 `6`
无
const frame_goawaypub const frame_goaway = 7公开常量 `frame_goaway`。 值为 `7`
无
const frame_window_updatepub const frame_window_update = 8公开常量 `frame_window_update`。 值为 `8`
无
const frame_continuationpub const frame_continuation = 9公开常量 `frame_continuation`。 值为 `9`
无
const flag_ackpub const flag_ack = 1公开常量 `flag_ack`。 值为 `1`
无
const flag_end_streampub const flag_end_stream = 1公开常量 `flag_end_stream`。 值为 `1`
无
const flag_end_headerspub const flag_end_headers = 4公开常量 `flag_end_headers`。 值为 `4`
无
const flag_paddedpub const flag_padded = 8公开常量 `flag_padded`。 值为 `8`
无
const flag_prioritypub const flag_priority = 32公开常量 `flag_priority`。 值为 `32`
无
struct H2Framepub struct H2Frame {
pub length int
pub frame_type int
pub flags int
pub stream_id int
pub payload string
}公开结构体 `H2Frame`。
length intframe_type intflags intstream_id intpayload stringencode_h2_headerpub fn encode_h2_header(len int, frame_type int, flags int, stream_id int) string编码。
len intframe_type intflags intstream_id intstring — 结果字符串
build_settings_framepub fn build_settings_frame(ack bool) stringbuildsettingsframe。
ack boolstring — 结果字符串
build_data_framepub fn build_data_frame(stream_id int, data string, end_stream bool) stringbuilddataframe。
stream_id intdata stringend_stream boolstring — 结果字符串
build_grpc_hpack_headerspub fn build_grpc_hpack_headers(path string) stringbuildgrpchpackheaders。
path stringstring — 结果字符串
build_headers_framepub fn build_headers_frame(stream_id int, path string, end_stream bool) stringbuildheadersframe。
stream_id intpath stringend_stream boolstring — 结果字符串
struct Poolpub struct Pool {
pub client GrpcClient
pub idle chan int
pub max_idle int
}公开结构体 `Pool`。
client GrpcClientidle chan intmax_idle intnew_poolpub fn new_pool(endpoint string, max_idle int) Pool构造 pool。
endpoint stringmax_idle intPool — 该类型的值
open_poolpub fn open_pool(endpoint string, max_idle int) Pool打开pool。
endpoint stringmax_idle intPool — 该类型的值
(&Pool) get_connpub fn (p &Pool) get_conn() int`&Pool` 上的方法:读取 conn。
p &Poolint — 该类型的值
(&Pool) put_connpub fn (p &Pool) put_conn(fd int)`&Pool` 上的方法:put连接。
p &Poolfd int(&Pool) call_unarypub fn (p &Pool) call_unary(path string, req_bytes string) Response`&Pool` 上的方法:callunary。失败时 throw。
p &Poolpath stringreq_bytes stringResponse — 该类型的值
(&Pool) closepub fn (p &Pool) close()`&Pool` 上的方法:关闭资源。
p &Poolconst wire_varintpub const wire_varint = 0公开常量 `wire_varint`。 值为 `0`
无
const wire_fixed64pub const wire_fixed64 = 1公开常量 `wire_fixed64`。 值为 `1`
无
const wire_length_delimitedpub const wire_length_delimited = 2公开常量 `wire_length_delimited`。 值为 `2`
无
const wire_fixed32pub const wire_fixed32 = 5公开常量 `wire_fixed32`。 值为 `5`
无
encode_varintpub fn encode_varint(val int) string编码。
val intstring — 结果字符串
struct VarintResultpub struct VarintResult {
pub value int
pub bytes_read int
}公开结构体 `VarintResult`。
value intbytes_read intdecode_varint_fullpub fn decode_varint_full(buf &string, pos int) VarintResult解码。
buf &stringpos intVarintResult — 该类型的值
decode_varintpub fn decode_varint(buf &string, pos int) int解码。
buf &stringpos intint — 该类型的值
encode_tagpub fn encode_tag(field_num int, wire_type int) string编码。
field_num intwire_type intstring — 结果字符串
encode_string_fieldpub fn encode_string_field(field_num int, val string) string编码。
field_num intval stringstring — 结果字符串
encode_int_fieldpub fn encode_int_field(field_num int, val int) string编码。
field_num intval intstring — 结果字符串
build_grpc_messagepub fn build_grpc_message(payload string) stringbuildgrpcmessage。
payload stringstring — 结果字符串
parse_grpc_messagepub fn parse_grpc_message(raw string) string解析为 grpc message。
raw stringstring — 结果字符串
decode_grpc_messagepub fn decode_grpc_message(raw string) string解码。失败时 throw。
raw stringstring — 结果字符串
get_string_fieldpub fn get_string_field(payload string, target_field int) string读取 string field。
payload stringtarget_field intstring — 结果字符串
get_int_fieldpub fn get_int_field(payload string, target_field int) int读取 int field。
payload stringtarget_field intint — 该类型的值