socks

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2024 License: MulanPSL-2.0 Imports: 14 Imported by: 0

Documentation

Overview

serialize

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyMemory

func CopyMemory(src, dst []byte) int

func GetLengthDataLen

func GetLengthDataLen(avLen uint32) uint32

func GetValueDataPtr

func GetValueDataPtr(v *reflect.Value) uintptr

func Move

func Move(src, dst uintptr, size uint32)

func ReadLength

func ReadLength(bits []byte) (lengthValue uint32, readLen uint32)

func ReadString

func ReadString(bits []byte) (str string, readLen uint32)

func WiriteLength

func WiriteLength(bits []byte, aLength uint32) (wirteLen uint32)

func WriteString

func WriteString(bits []byte, str string) (writeLen uint32)

Types

type BufferUtils

type BufferUtils struct {
	// contains filtered or unexported fields
}

func NewBufferUtils

func NewBufferUtils(buff []byte) *BufferUtils

func (*BufferUtils) GetDataLen

func (bw *BufferUtils) GetDataLen() int

func (*BufferUtils) GetPos

func (bw *BufferUtils) GetPos() int

func (*BufferUtils) GetRemainBuff

func (bw *BufferUtils) GetRemainBuff() []byte

获取剩余buff

func (*BufferUtils) GetRemainLen

func (bw *BufferUtils) GetRemainLen() int

获取剩余长度

func (*BufferUtils) Read added in v1.0.6

func (bw *BufferUtils) Read(buff []byte) (v int, err error)

支持 Io.reader 接口

func (*BufferUtils) ReadUint16

func (bw *BufferUtils) ReadUint16() (v uint16)

func (*BufferUtils) ReadUint32

func (bw *BufferUtils) ReadUint32() (v uint32)

func (*BufferUtils) ReadUint64

func (bw *BufferUtils) ReadUint64() (v uint64)

func (*BufferUtils) ReadUint8

func (bw *BufferUtils) ReadUint8() (v uint8)

func (*BufferUtils) Reset

func (bw *BufferUtils) Reset(buff []byte)

func (*BufferUtils) ResetBuffSize

func (bw *BufferUtils) ResetBuffSize(size int)

自己持有Buff

func (*BufferUtils) ResetPos

func (bw *BufferUtils) ResetPos(newPos int) (r bool)

重新设置指针位置

func (*BufferUtils) Seek

func (bw *BufferUtils) Seek(offset int) bool

从当前位置移动指针

func (*BufferUtils) Write

func (bw *BufferUtils) Write(a any) bool

type DefaultHeadHandler

type DefaultHeadHandler struct {
	// contains filtered or unexported fields
}

func NewDefaultHeadHandler

func NewDefaultHeadHandler(creater IHeaderCreator) *DefaultHeadHandler

func (*DefaultHeadHandler) ReadPack

func (d *DefaultHeadHandler) ReadPack(reader io.Reader, conn SocketConnection) (pack *PackData)

func (*DefaultHeadHandler) WritePack

func (d *DefaultHeadHandler) WritePack(writer io.Writer, datas []byte) bool

type DefaultMsgHead

type DefaultMsgHead struct {
	Cmd uint32
	// contains filtered or unexported fields
}

func (*DefaultMsgHead) CreateMsgHeader

func (d *DefaultMsgHead) CreateMsgHeader() IMsgHeader

func (*DefaultMsgHead) GetHeaderSize

func (d *DefaultMsgHead) GetHeaderSize() int

func (*DefaultMsgHead) ReadHeader

func (d *DefaultMsgHead) ReadHeader(br *BufferUtils) (isOk bool, bodyLen int)

func (*DefaultMsgHead) WriteHeader

func (d *DefaultMsgHead) WriteHeader(bw *BufferUtils, bodyLen int) bool

type FastLocker

type FastLocker struct {
	// contains filtered or unexported fields
}

func (*FastLocker) Lock

func (l *FastLocker) Lock()

func (*FastLocker) Unlock

func (l *FastLocker) Unlock()

type HashIdType

type HashIdType = int32 // =, 用别名,方便兼容

type IHeaderCreator

type IHeaderCreator interface {
	CreateMsgHeader() IMsgHeader
}

type IMsgHandler

type IMsgHandler interface {
	OnConnect(sock SocketConnection)
	OnDisconnect(sock SocketConnection)
	OnMessage(sock SocketConnection, msg *PackData)
}

type IMsgHeader

type IMsgHeader interface {
	GetHeaderSize() int
	ReadHeader(br *BufferUtils) (isOk bool, bodyLen int)
	WriteHeader(bw *BufferUtils, bodyLen int) bool
}

type IPackHeader

type IPackHeader interface {
	ReadPack(reader io.Reader, conn SocketConnection) (pack *PackData) // 不成功返回空
	WritePack(writer io.Writer, datas []byte) bool                     // 发送普通包的时候用到
}

type MsgBody

type MsgBody struct {
	MsgHead interface{}
	Datas   []byte
}

type PByteArray

type PByteArray (*[cMaxArrSize]byte)

type PStrArray

type PStrArray (*[cMaxArrSize]string)

type PackData

type PackData struct {
	Head interface{}
	Body []byte
}

type Serializer

type Serializer struct {
	// contains filtered or unexported fields
}

func New

func New(isLikeCStruct bool, hashTblSize int) *Serializer

方便线程和不同的模式使用 isLikeCStruct 主要是跟 c++、Delphi 类通讯

func (*Serializer) Decode

func (s *Serializer) Decode(bits []byte, ptr interface{}) bool

func (*Serializer) DecodeStruct

func (s *Serializer) DecodeStruct(id HashIdType, bits []byte) (obj interface{}, isOk bool)

func (*Serializer) Encode

func (s *Serializer) Encode(ptr interface{}) (result []byte, ok bool)

这里传指针,加快访问速度

func (*Serializer) NewStruct

func (s *Serializer) NewStruct(id HashIdType) interface{}

根据注册ID新建结构,方便外面使用

func (*Serializer) RegisterType

func (s *Serializer) RegisterType(id HashIdType, obj interface{}) bool

type SockOptions

type SockOptions struct {
	HeadHandler IPackHeader
	MsgHandler  IMsgHandler
}

type SocketClient

type SocketClient interface {
	Open()  // 开始连接,打开会会自动连接
	Close() // 关闭连接
	GetConnection() SocketConnection
	Connected() bool // 判断是否连接
}

func NewSocketClient

func NewSocketClient(addr string, avOpts SockOptions) SocketClient

type SocketConnection

type SocketConnection interface {
	SendData(avDatas []byte) bool //普通消息,需要组包,写入包头
	SendRawData(data []byte) bool // 发送原始消息,不需要组包,直接发送
	RemoteAddr() net.Addr
	GetId() int32
	Disconnect()
	GetData() interface{}
	SetData(usrData interface{})
}

type SocketServer

type SocketServer interface {
	Open(avPort uint16) bool                       // 开启服务
	Close()                                        // 关闭
	Foreach(f enum_callback)                       // 遍历连接
	SendRawData(SockId int32, avBytes []byte) bool // 根据id 发送消息
	SendData(SockId int32, Data []byte) bool       // 直接发送数据
	GetConnectCount() int32                        // 获取连接总数
}

func NewSocketServer

func NewSocketServer(avOpts SockOptions) SocketServer

Jump to

Keyboard shortcuts

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