protocol

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

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

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) Descriptor() ([]byte, []int)

Deprecated: Use Envelope.ProtoReflect.Descriptor instead.

func (*Envelope) GetAction

func (x *Envelope) GetAction() string

func (*Envelope) GetBody

func (x *Envelope) GetBody() isEnvelope_Body

func (*Envelope) GetData

func (x *Envelope) GetData() []byte

func (*Envelope) GetError

func (x *Envelope) GetError() *Error

func (*Envelope) GetKind

func (x *Envelope) GetKind() Kind

func (*Envelope) GetRequestId

func (x *Envelope) GetRequestId() string

func (*Envelope) GetScene

func (x *Envelope) GetScene() string

func (*Envelope) GetType

func (x *Envelope) GetType() string

func (*Envelope) ProtoMessage

func (*Envelope) ProtoMessage()

func (*Envelope) ProtoReflect

func (x *Envelope) ProtoReflect() protoreflect.Message

func (*Envelope) Reset

func (x *Envelope) Reset()

func (*Envelope) String

func (x *Envelope) String() string

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) Descriptor() ([]byte, []int)

Deprecated: Use Error.ProtoReflect.Descriptor instead.

func (*Error) GetCode

func (x *Error) GetCode() string

func (*Error) GetMessage

func (x *Error) GetMessage() string

func (*Error) ProtoMessage

func (*Error) ProtoMessage()

func (*Error) ProtoReflect

func (x *Error) ProtoReflect() protoreflect.Message

func (*Error) Reset

func (x *Error) Reset()

func (*Error) String

func (x *Error) String() string

type Kind

type Kind int32

Kind 区分客户端请求、服务端响应和服务端主动事件。

const (
	Kind_KIND_UNSPECIFIED Kind = 0
	Kind_REQUEST          Kind = 1
	Kind_RESPONSE         Kind = 2
	Kind_EVENT            Kind = 3
)

func (Kind) Descriptor

func (Kind) Descriptor() protoreflect.EnumDescriptor

func (Kind) Enum

func (x Kind) Enum() *Kind

func (Kind) EnumDescriptor deprecated

func (Kind) EnumDescriptor() ([]byte, []int)

Deprecated: Use Kind.Descriptor instead.

func (Kind) Number

func (x Kind) Number() protoreflect.EnumNumber

func (Kind) String

func (x Kind) String() string

func (Kind) Type

func (Kind) Type() protoreflect.EnumType

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL