Documentation
¶
Overview ¶
Package protocol 保存 realtime.v1 的公共 protobuf 信封,不包含业务消息类型。 JSON 使用同语义的外层字段及内嵌 ProtoJSON;不能直接 protojson.Marshal 本信封代替 JSON 编码。
客户端构造 PB 请求示例,需导入 protocol、proto 和 wrapperspb:
body, err := proto.Marshal(wrapperspb.String("hello"))
if err != nil {
return err
}
wire, err := proto.Marshal(&protocol.Envelope{
Kind: protocol.Kind_REQUEST,
RequestId: "r1",
Scene: "home",
Action: "hello",
Body: &protocol.Envelope_Data{Data: body},
})
if err != nil {
return err
}
// 协商 pixiu.realtime.v1.protobuf 后将 wire 作为一条 Binary 消息发送。
请求通过 scene/action 路由;下行不设置这两个字段,响应、错误响应和事件均必填 Type。 Type 是业务约定的消息类型字符串,客户端据此选择处理器和正文解码类型。 响应回显 RequestId,事件不携带;data 即使为空 bytes,也需保留 oneof 存在性。 生成入口为 go generate ./biz/realtime,工具版本见该包的 generate.sh。
Index ¶
- Variables
- type Envelope
- func (*Envelope) Descriptor() ([]byte, []int)deprecated
- func (x *Envelope) GetAction() string
- func (x *Envelope) GetBody() isEnvelope_Body
- func (x *Envelope) GetData() []byte
- func (x *Envelope) GetError() *Error
- func (x *Envelope) GetKind() Kind
- func (x *Envelope) GetRequestId() string
- func (x *Envelope) GetScene() string
- func (x *Envelope) GetType() string
- func (*Envelope) ProtoMessage()
- func (x *Envelope) ProtoReflect() protoreflect.Message
- func (x *Envelope) Reset()
- func (x *Envelope) String() string
- type Envelope_Data
- type Envelope_Error
- type Error
- type Kind
Constants ¶
This section is empty.
Variables ¶
View Source
var ( Kind_name = map[int32]string{ 0: "KIND_UNSPECIFIED", 1: "REQUEST", 2: "RESPONSE", 3: "EVENT", } Kind_value = map[string]int32{ "KIND_UNSPECIFIED": 0, "REQUEST": 1, "RESPONSE": 2, "EVENT": 3, } )
Enum value maps for Kind.
View Source
var File_protocol_realtime_proto protoreflect.FileDescriptor
Functions ¶
This section is empty.
Types ¶
type Envelope ¶
type Envelope struct {
Kind Kind `protobuf:"varint,1,opt,name=kind,proto3,enum=pixiu.realtime.v1.Kind" json:"kind,omitempty"`
RequestId string `protobuf:"bytes,2,opt,name=request_id,json=requestId,proto3" json:"request_id,omitempty"`
// scene/action 只用于上行请求路由,下行不设置。
Scene string `protobuf:"bytes,3,opt,name=scene,proto3" json:"scene,omitempty"`
Action string `protobuf:"bytes,4,opt,name=action,proto3" json:"action,omitempty"`
// Types that are valid to be assigned to Body:
//
// *Envelope_Data
// *Envelope_Error
Body isEnvelope_Body `protobuf_oneof:"body"`
// type 只用于下行消息,由业务显式指定,响应、错误响应和事件均必填。
Type string `protobuf:"bytes,7,opt,name=type,proto3" json:"type,omitempty"`
// contains filtered or unexported fields
}
Envelope 是 PB 公共信封;JSON 的 data 直接使用业务 ProtoJSON 值。
func (*Envelope) Descriptor
deprecated
func (*Envelope) GetRequestId ¶
func (*Envelope) ProtoMessage ¶
func (*Envelope) ProtoMessage()
func (*Envelope) ProtoReflect ¶
func (x *Envelope) ProtoReflect() protoreflect.Message
type Envelope_Data ¶
type Envelope_Data struct {
Data []byte `protobuf:"bytes,5,opt,name=data,proto3,oneof"`
}
type Envelope_Error ¶
type Envelope_Error struct {
Error *Error `protobuf:"bytes,6,opt,name=error,proto3,oneof"`
}
type Error ¶
type Error struct {
Code string `protobuf:"bytes,1,opt,name=code,proto3" json:"code,omitempty"`
Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"`
// contains filtered or unexported fields
}
Error 仅承载业务显式允许公开的错误,不包含内部错误文本。
func (*Error) Descriptor
deprecated
func (*Error) GetMessage ¶
func (*Error) ProtoMessage ¶
func (*Error) ProtoMessage()
func (*Error) ProtoReflect ¶
func (x *Error) ProtoReflect() protoreflect.Message
type Kind ¶
type Kind int32
Kind 区分客户端请求、服务端响应和服务端主动事件。
func (Kind) Descriptor ¶
func (Kind) Descriptor() protoreflect.EnumDescriptor
func (Kind) EnumDescriptor
deprecated
func (Kind) Number ¶
func (x Kind) Number() protoreflect.EnumNumber
func (Kind) Type ¶
func (Kind) Type() protoreflect.EnumType
Click to show internal directories.
Click to hide internal directories.