gproto

package
v0.0.0-...-fcde4f0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2021 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CODE_SUCCESS                  = 0  // Success
	CODE_IGNORE                   = 1  // Ignore
	CODE_ERROR_NO_USER            = 2  // User Not Found
	CODE_ERROR_PASSWORD_ERROR     = 3  // Password Error
	CODE_ERROR_UNKNOWN            = 4  // Unknown Error
	CODE_ERROR_REPLACED           = 5  // Session Replaced
	CODE_ERROR_CLIENT             = 6  // Client Logci Error
	CODE_ERROR_SERVER             = 7  // Server Internal Error
	CODE_ERROR_DB                 = 8  // DB Ops Error
	CODE_ERROR_NOT_FOUND          = 9  // Not Found Error
	CODE_ERROR_AUTH_ERROR         = 10 // AUTH Error
	CODE_ERROR_UNSUPPORT_API      = 11 // UnSupport API
	CODE_ERROR_INVALID_JSON       = 12 // Invalid JSON Format
	CODE_ERROR_ALREADY_REGISTERED = 13 // Already Registered Error
	CODE_ERROR_NO_APP             = 14 // No App Error
	CODE_ERROR_ALREADY_EXIST      = 15 // Already Exist
)

全局错误码

View Source
const (
	MSG_PING_REQUEST               = 0x1001 // C -> S
	MSG_PING_RESPONSE              = 0x1002 // S -> C
	MSG_ECHO_REQUEST               = 0x1003 // C -> S
	MSG_ECHO_RESPONSE              = 0x1004 // S -> C
	MSG_KICKOFF_NOTIFY             = 0x1005 // S -> C
	MSG_AUTH_REQUEST               = 0x1006 // C -> S
	MSG_AUTH_RESPONSE              = 0x1007 // S -> C
	MSG_MESSAGE_REQUEST            = 0x100e // C -> S
	MSG_MESSAGE_RESPONSE           = 0x100f // S -> C
	MSG_MESSAGE_NOTIFY             = 0x1010 // S -> C
	MSG_MESSAGE_ACK                = 0x1011 // C -> S
	MSG_GET_CHATROOM_INFO_REQUEST  = 0x101d // C -> S
	MSG_GET_CHATROOM_INFO_RESPONSE = 0x101e // S -> S
	MSG_ENTER_CHATROOM_REQUEST     = 0x101f // C -> S
	MSG_ENTER_CHATROOM_RESPONSE    = 0x1020 // S -> C
	MSG_TOUCH_CHATROOM_REQUEST     = 0x1021 // C -> S
	MSG_TOUCH_CHATROOM_RESPONSE    = 0x1022 // S -> C
	MSG_ENTER_CHATROOM_NOTIFY      = 0x1023 // S -> C
	MSG_LEAVE_CHATROOM_REQUEST     = 0x1024 // C -> S
	MSG_LEAVE_CHATROOM_RESPONSE    = 0x1025 // S -> C
	MSG_LEAVE_CHATROOM_NOTIFY      = 0x1026 // S -> C
	MSG_CHATROOM_KICKOFF_NOTIFY    = 0x1027 // S -> C
)
View Source
const (
	OPTIONAL_TRUE  = 1 // 字段写入
	OPTIONAL_FALSE = 0 // 字段不写(忽略), 默认值
)

optional字段前缀

View Source
const (
	// 0 - 9
	MESSAGE_TYPE_PLAYER_TEXT              = 0
	MESSAGE_TYPE_PLAYER_IMAGE             = 1
	MESSAGE_TYPE_PLAYER_SHORT_VOICE       = 2
	MESSAGE_TYPE_PLAYER_SHORT_VEDEO       = 3
	MESSAGE_TYPE_PLAYER_CUSTOMIZE_ONLINE  = 4 // 自定义格式消息(不会离线存储)
	MESSAGE_TYPE_PLAYER_CUSTOMIZE_OFFLINE = 5 // 自定义格式消息(会离线存储)

	// 10 - 19
	MESSAGE_TYPE_GROUP_TEXT              = 10
	MESSAGE_TYPE_GROUP_IMAGE             = 11
	MESSAGE_TYPE_GROUP_SHORT_VOICE       = 12
	MESSAGE_TYPE_GROUP_SHORT_VEDEO       = 13
	MESSAGE_TYPE_GROUP_CUSTOMIZE_ONLINE  = 14 // 自定义格式消息(不会离线存储)
	MESSAGE_TYPE_GROUP_CUSTOMIZE_OFFLINE = 15 // 自定义格式消息(会离线存储)

	// 20 - 29
	MESSAGE_TYPE_CHATROOM_TEXT             = 20
	MESSAGE_TYPE_CHATROOM_IMAGE            = 21
	MESSAGE_TYPE_CHATROOM_SHORT_VOICE      = 22
	MESSAGE_TYPE_CHATROOM_SHORT_VEDEO      = 23
	MESSAGE_TYPE_CHATROOM_CUSTOMIZE_ONLINE = 24 // 自定义格式消息(不会离线存储)

	// 30 - 39
	MESSAGE_TYPE_BROADCAST_TEXT             = 30 // (不会离线存储)
	MESSAGE_TYPE_BROADCAST_IMAGE            = 31 // (不会离线存储)
	MESSAGE_TYPE_BROADCAST_SHORT_VOICE      = 32 // (不会离线存储)
	MESSAGE_TYPE_BROADCAST_SHORT_VIDEO      = 33 // (不会离线存储)
	MESSAGE_TYPE_BROADCAST_CUSTOMIZE_ONLINE = 34 // 自定义格式消息(不会离线存储)

)
View Source
const (
	MagicWord = 0x7fffffff // 4 bytes
)

Variables

View Source
var (
	InvalidDecodeBufferError = errors.New("invalid Decode Buffer")
	InvalidVersionError      = errors.New("invalid Version")
)

Functions

func CodeToMessage

func CodeToMessage(code int) string

Types

type Command

type Command uint16

Command

func (Command) String

func (cmd Command) String() string

type GBuffer

type GBuffer struct {
	Buffer *bytes.Buffer
}

func NewEmptyGBuffer

func NewEmptyGBuffer() *GBuffer

for encoder

func NewGBuffer

func NewGBuffer(buf []byte) *GBuffer

for decoder

func (*GBuffer) Bytes

func (gBuffer *GBuffer) Bytes() []byte

func (*GBuffer) Len

func (gBuffer *GBuffer) Len() int

func (*GBuffer) ReadArray

func (gBuffer *GBuffer) ReadArray(version uint16) ([]IMessage, error)

备注: 这只是一个Read Array的范例, 当前版本这个函数并不能使用

func (*GBuffer) ReadBytes

func (gBuffer *GBuffer) ReadBytes() ([]byte, error)

备注: 会自动分配内存

func (*GBuffer) ReadInt16

func (gBuffer *GBuffer) ReadInt16(v *int16) error

func (*GBuffer) ReadInt32

func (gBuffer *GBuffer) ReadInt32(v *int32) error

func (*GBuffer) ReadInt64

func (gBuffer *GBuffer) ReadInt64(v *int64) error

func (*GBuffer) ReadInt8

func (gBuffer *GBuffer) ReadInt8(v *int8) error

func (*GBuffer) ReadRawBytes

func (gBuffer *GBuffer) ReadRawBytes(l uint16) ([]byte, error)

func (*GBuffer) ReadString

func (gBuffer *GBuffer) ReadString() (string, error)

func (*GBuffer) ReadStruct

func (gBuffer *GBuffer) ReadStruct(version uint16, iMessage IMessage) error

func (*GBuffer) ReadUInt16

func (gBuffer *GBuffer) ReadUInt16(v *uint16) error

func (*GBuffer) ReadUInt32

func (gBuffer *GBuffer) ReadUInt32(v *uint32) error

func (*GBuffer) ReadUInt64

func (gBuffer *GBuffer) ReadUInt64(v *uint64) error

func (*GBuffer) ReadUInt8

func (gBuffer *GBuffer) ReadUInt8(v *uint8) error

func (*GBuffer) WriteArray

func (gBuffer *GBuffer) WriteArray(version uint16, arr interface{}) error

<4> List uint16具体元素个数 + 具体元素

备注: arr必须是[]IMessage, 否则会Panic

func (*GBuffer) WriteBytes

func (gBuffer *GBuffer) WriteBytes(b []byte) error

<2> Bytes/String uint16长度 + 具体字节流

备注: 没有内容的时候只写入uint16长度

func (*GBuffer) WriteInt16

func (gBuffer *GBuffer) WriteInt16(v int16) error

func (*GBuffer) WriteInt32

func (gBuffer *GBuffer) WriteInt32(v int32) error

func (*GBuffer) WriteInt64

func (gBuffer *GBuffer) WriteInt64(v int64) error

func (*GBuffer) WriteInt8

func (gBuffer *GBuffer) WriteInt8(v int8) error

func (*GBuffer) WriteRawBytes

func (gBuffer *GBuffer) WriteRawBytes(b []byte) error

没有额外的长度信息

func (*GBuffer) WriteString

func (gBuffer *GBuffer) WriteString(str string) error

func (*GBuffer) WriteStruct

func (gBuffer *GBuffer) WriteStruct(version uint16, iMessage IMessage) error

<3> Struct虚拟的约束 uint16长度 + 具体字节流

func (*GBuffer) WriteUInt16

func (gBuffer *GBuffer) WriteUInt16(v uint16) error

func (*GBuffer) WriteUInt32

func (gBuffer *GBuffer) WriteUInt32(v uint32) error

func (*GBuffer) WriteUInt64

func (gBuffer *GBuffer) WriteUInt64(v uint64) error

func (*GBuffer) WriteUInt8

func (gBuffer *GBuffer) WriteUInt8(v uint8) error

type GProtoAuthRequest

type GProtoAuthRequest struct {
	Account       string
	Token         string
	Timestamp     uint64
	CustomVersion string
}

func (*GProtoAuthRequest) Decode

func (authRequest *GProtoAuthRequest) Decode(version uint16, buf []byte) error

func (*GProtoAuthRequest) Encode

func (authRequest *GProtoAuthRequest) Encode(version uint16) ([]byte, error)

type GProtoAuthResponse

type GProtoAuthResponse struct {
	Code    uint8
	Account string
}

func (*GProtoAuthResponse) Decode

func (authResponse *GProtoAuthResponse) Decode(version uint16, buf []byte) error

func (*GProtoAuthResponse) Encode

func (authResponse *GProtoAuthResponse) Encode(version uint16) ([]byte, error)

type GProtoBlacklist

type GProtoBlacklist struct {
	Account string
	Flag    uint8
}

func (*GProtoBlacklist) Decode

func (blacklist *GProtoBlacklist) Decode(version uint16, buf []byte) error

func (*GProtoBlacklist) Encode

func (blacklist *GProtoBlacklist) Encode(version uint16) ([]byte, error)

type GProtoChatRoomInfo

type GProtoChatRoomInfo struct {
	ChatRoomId       string
	Name             string
	Description      string
	OwnerAccount     string
	MaxUser          uint16
	CreatedTimestamp int64
}

func (*GProtoChatRoomInfo) Decode

func (chatRoomInfo *GProtoChatRoomInfo) Decode(version uint16, buf []byte) error

func (*GProtoChatRoomInfo) Encode

func (chatRoomInfo *GProtoChatRoomInfo) Encode(version uint16) ([]byte, error)

type GProtoChatRoomKickoffNotify

type GProtoChatRoomKickoffNotify struct {
	ChatRoomId string
	Account    string
}

//////////////////////////////////

message ChatRoomKickoffNotify {
    required string chatroom_id = 1;
    required string account = 2;
}

func (*GProtoChatRoomKickoffNotify) Decode

func (chatRoomKickoffNotify *GProtoChatRoomKickoffNotify) Decode(version uint16, buf []byte) error

func (*GProtoChatRoomKickoffNotify) Encode

func (chatRoomKickoffNotify *GProtoChatRoomKickoffNotify) Encode(version uint16) ([]byte, error)

type GProtoEchoRequest

type GProtoEchoRequest struct {
	Data string
}

func (*GProtoEchoRequest) Decode

func (echoRequest *GProtoEchoRequest) Decode(version uint16, buf []byte) error

func (*GProtoEchoRequest) Encode

func (echoRequest *GProtoEchoRequest) Encode(version uint16) ([]byte, error)

type GProtoEchoResponse

type GProtoEchoResponse struct {
	Code uint8
	Data string
}

func (*GProtoEchoResponse) Decode

func (echoResponse *GProtoEchoResponse) Decode(version uint16, buf []byte) error

func (*GProtoEchoResponse) Encode

func (echoResponse *GProtoEchoResponse) Encode(version uint16) ([]byte, error)

type GProtoEnterChatRoomNotify

type GProtoEnterChatRoomNotify struct {
	ChatRoomId string
	User       *GProtoOtherUser
}

func (*GProtoEnterChatRoomNotify) Decode

func (enterChatRoomNotify *GProtoEnterChatRoomNotify) Decode(version uint16, buf []byte) error

func (*GProtoEnterChatRoomNotify) Encode

func (enterChatRoomNotify *GProtoEnterChatRoomNotify) Encode(version uint16) ([]byte, error)

type GProtoEnterChatRoomRequest

type GProtoEnterChatRoomRequest struct {
	ChatRoomId string
}

func (*GProtoEnterChatRoomRequest) Decode

func (enterChatRoomRequest *GProtoEnterChatRoomRequest) Decode(version uint16, buf []byte) error

func (*GProtoEnterChatRoomRequest) Encode

func (enterChatRoomRequest *GProtoEnterChatRoomRequest) Encode(version uint16) ([]byte, error)

type GProtoEnterChatRoomResponse

type GProtoEnterChatRoomResponse struct {
	Code  uint8
	Users []*GProtoOtherUser
}

func (*GProtoEnterChatRoomResponse) Decode

func (enterChatRoomResponse *GProtoEnterChatRoomResponse) Decode(version uint16, buf []byte) error

func (*GProtoEnterChatRoomResponse) Encode

func (enterChatRoomResponse *GProtoEnterChatRoomResponse) Encode(version uint16) ([]byte, error)

type GProtoFriend

type GProtoFriend struct {
	Account      string
	Flag         uint8
	Markname     string
	MakrnameFlag uint8
}

func (*GProtoFriend) Decode

func (friend *GProtoFriend) Decode(version uint16, buf []byte) error

func (*GProtoFriend) Encode

func (friend *GProtoFriend) Encode(version uint16) ([]byte, error)

type GProtoGetChatRoomInfoRequest

type GProtoGetChatRoomInfoRequest struct {
	ChatRoomId string
}

func (*GProtoGetChatRoomInfoRequest) Decode

func (getChatRoomInfoRequest *GProtoGetChatRoomInfoRequest) Decode(version uint16, buf []byte) error

func (*GProtoGetChatRoomInfoRequest) Encode

func (getChatRoomInfoRequest *GProtoGetChatRoomInfoRequest) Encode(version uint16) ([]byte, error)

type GProtoGetChatRoomInfoResponse

type GProtoGetChatRoomInfoResponse struct {
	Code uint8
	Info *GProtoChatRoomInfo
}

func (*GProtoGetChatRoomInfoResponse) Decode

func (getChatRoomInfoResponse *GProtoGetChatRoomInfoResponse) Decode(version uint16, buf []byte) error

func (*GProtoGetChatRoomInfoResponse) Encode

func (getChatRoomInfoResponse *GProtoGetChatRoomInfoResponse) Encode(version uint16) ([]byte, error)

type GProtoGroupInfo

type GProtoGroupInfo struct {
	GroupId          string
	Name             string
	Avatar           string
	Description      string
	OwnerAccount     string
	MaxUser          uint16
	Flag             uint8
	CreatedTimestamp int64
	Users            []*GProtoOtherUser
	Marknames        []*GProtoGroupMarkname
}

func (*GProtoGroupInfo) Decode

func (groupInfo *GProtoGroupInfo) Decode(version uint16, buf []byte) error

func (*GProtoGroupInfo) Encode

func (groupInfo *GProtoGroupInfo) Encode(version uint16) ([]byte, error)

type GProtoGroupMarkname

type GProtoGroupMarkname struct {
	Account  string
	Markname string
}

func (*GProtoGroupMarkname) Decode

func (groupMarkname *GProtoGroupMarkname) Decode(version uint16, buf []byte) error

func (*GProtoGroupMarkname) Encode

func (groupMarkname *GProtoGroupMarkname) Encode(version uint16) ([]byte, error)

type GProtoKickOffNotify

type GProtoKickOffNotify struct {
	Code uint8
}

func (*GProtoKickOffNotify) Decode

func (kickOffNotify *GProtoKickOffNotify) Decode(version uint16, buf []byte) error

func (*GProtoKickOffNotify) Encode

func (kickOffNotify *GProtoKickOffNotify) Encode(version uint16) ([]byte, error)

type GProtoLeaveChatRoomNotify

type GProtoLeaveChatRoomNotify struct {
	ChatRoomId string
	Account    string
}

func (*GProtoLeaveChatRoomNotify) Decode

func (leaveChatRoomNotify *GProtoLeaveChatRoomNotify) Decode(version uint16, buf []byte) error

func (*GProtoLeaveChatRoomNotify) Encode

func (leaveChatRoomNotify *GProtoLeaveChatRoomNotify) Encode(version uint16) ([]byte, error)

type GProtoLeaveChatRoomRequest

type GProtoLeaveChatRoomRequest struct {
	ChatRoomId string
}

func (*GProtoLeaveChatRoomRequest) Decode

func (leaveChatRoomRequest *GProtoLeaveChatRoomRequest) Decode(version uint16, buf []byte) error

func (*GProtoLeaveChatRoomRequest) Encode

func (leaveChatRoomRequest *GProtoLeaveChatRoomRequest) Encode(version uint16) ([]byte, error)

type GProtoLeaveChatRoomResponse

type GProtoLeaveChatRoomResponse struct {
	Code       uint8
	ChatRoomId string
}

func (*GProtoLeaveChatRoomResponse) Decode

func (leaveChatRoomResponse *GProtoLeaveChatRoomResponse) Decode(version uint16, buf []byte) error

func (*GProtoLeaveChatRoomResponse) Encode

func (leaveChatRoomResponse *GProtoLeaveChatRoomResponse) Encode(version uint16) ([]byte, error)

type GProtoMessageAck

type GProtoMessageAck struct {
	MsgId string
}

func (*GProtoMessageAck) Decode

func (messageAck *GProtoMessageAck) Decode(version uint16, buf []byte) error

func (*GProtoMessageAck) Encode

func (messageAck *GProtoMessageAck) Encode(version uint16) ([]byte, error)

type GProtoMessageNotify

type GProtoMessageNotify struct {
	MsgId       string
	MsgType     uint8
	Content     string
	RoomId      string
	From        string
	To          string
	SendTime    uint64
	SendTimeAck uint64
	Extend      string
}

func MessageRequestToMessageNotify

func MessageRequestToMessageNotify(gProtoMessageRequest *GProtoMessageRequest) *GProtoMessageNotify

func (*GProtoMessageNotify) Decode

func (messageNotify *GProtoMessageNotify) Decode(version uint16, buf []byte) error

func (*GProtoMessageNotify) Encode

func (messageNotify *GProtoMessageNotify) Encode(version uint16) ([]byte, error)

type GProtoMessageRequest

type GProtoMessageRequest struct {
	MsgId   string
	MsgType uint8
	Content string
	RoomId  string
	From    string
	To      string
	Extend  string
}

func (*GProtoMessageRequest) Decode

func (messageRequest *GProtoMessageRequest) Decode(version uint16, buf []byte) error

func (*GProtoMessageRequest) Encode

func (messageRequest *GProtoMessageRequest) Encode(version uint16) ([]byte, error)

type GProtoMessageResponse

type GProtoMessageResponse struct {
	Code    uint8
	MsgId   string
	MsgType uint8
	Content string
}

func (*GProtoMessageResponse) Decode

func (messageResponse *GProtoMessageResponse) Decode(version uint16, buf []byte) error

func (*GProtoMessageResponse) Encode

func (messageResponse *GProtoMessageResponse) Encode(version uint16) ([]byte, error)

type GProtoOtherUser

type GProtoOtherUser struct {
	Account string
}

func EmptyGProtoOtherUser

func EmptyGProtoOtherUser(account string) *GProtoOtherUser

func (*GProtoOtherUser) Decode

func (otherUser *GProtoOtherUser) Decode(version uint16, buf []byte) error

func (*GProtoOtherUser) Encode

func (otherUser *GProtoOtherUser) Encode(version uint16) ([]byte, error)

func (*GProtoOtherUser) String

func (otherUser *GProtoOtherUser) String() string

type GProtoPingRequest

type GProtoPingRequest struct {
}

func (*GProtoPingRequest) Decode

func (pingRequest *GProtoPingRequest) Decode(version uint16, buf []byte) error

func (*GProtoPingRequest) Encode

func (pingRequest *GProtoPingRequest) Encode(version uint16) ([]byte, error)

type GProtoPingResponse

type GProtoPingResponse struct {
	Code uint8
}

func (*GProtoPingResponse) Decode

func (pingResponse *GProtoPingResponse) Decode(version uint16, buf []byte) error

func (*GProtoPingResponse) Encode

func (pingResponse *GProtoPingResponse) Encode(version uint16) ([]byte, error)

type GProtoSelfUser

type GProtoSelfUser struct {
	Account string
}

func EmptyGProtoSelfUser

func EmptyGProtoSelfUser(account string) *GProtoSelfUser

func (*GProtoSelfUser) Decode

func (selfUser *GProtoSelfUser) Decode(version uint16, buf []byte) error

func (*GProtoSelfUser) Encode

func (selfUser *GProtoSelfUser) Encode(version uint16) ([]byte, error)

func (*GProtoSelfUser) String

func (selfUser *GProtoSelfUser) String() string

type GProtoTouchChatRoomRequest

type GProtoTouchChatRoomRequest struct {
	ChatRoomId string
}

房间心跳

func (*GProtoTouchChatRoomRequest) Decode

func (touchChatRoomRequest *GProtoTouchChatRoomRequest) Decode(version uint16, buf []byte) error

func (*GProtoTouchChatRoomRequest) Encode

func (touchChatRoomRequest *GProtoTouchChatRoomRequest) Encode(version uint16) ([]byte, error)

type GProtoTouchChatRoomResponse

type GProtoTouchChatRoomResponse struct {
	Code uint8
}

func (*GProtoTouchChatRoomResponse) Decode

func (touchChatRoomResponse *GProtoTouchChatRoomResponse) Decode(version uint16, buf []byte) error

func (*GProtoTouchChatRoomResponse) Encode

func (touchChatRoomResponse *GProtoTouchChatRoomResponse) Encode(version uint16) ([]byte, error)

type IMessage

type IMessage interface {
	// 编码IMessage, 如果error=nil, 则编码成功
	Encode(version uint16) ([]byte, error)

	// 解码IMessage, 如果error=nil, 则解码成功
	Decode(version uint16, buf []byte) error
}

type Message

type Message struct {
	MagicWord     uint32
	Version       uint16
	Command       uint16
	PayloadLength uint32
	Body          interface{} // IMessage
}

func NewEmptyMessage

func NewEmptyMessage() *Message

func NewMessage

func NewMessage(version, command uint16, body interface{}) *Message

func (*Message) Decode

func (message *Message) Decode(buf []byte) error

解码Message.Body, 如果error=nil, 则解码成功

func (*Message) DecodeHead

func (message *Message) DecodeHead(buf []byte) error

func (*Message) Encode

func (message *Message) Encode() ([]byte, error)

编码Message.Body, 如果error=nil, 则编码成功

func (*Message) EncodeHead

func (message *Message) EncodeHead() ([]byte, error)

type MessageCreator

type MessageCreator func() IMessage

全局的Message Creators

Jump to

Keyboard shortcuts

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