sonet

package
v0.0.0-...-d9d0c30 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

* @Author: soso * @Date: 2022-01-26 10:56:33 * @LastEditTime: 2022-03-03 17:51:06 * @LastEditors: Please set LastEditors * @Description: sonet传输包 * @FilePath: /go-mesh-sync/go-utils/utils/sonet/command.go

* @Author: soso * @Date: 2022-01-26 10:56:33 * @LastEditTime: 2022-01-26 11:23:25 * @LastEditors: soso * @Description: 网络数据打包解包 * @FilePath: /go-mesh-sync/go-utils/utils/sonet/datapack.go

* @Author: soso * @Date: 2022-01-27 17:52:43 * @LastEditTime: 2022-02-16 15:30:36 * @LastEditors: Please set LastEditors * @Description: 发包,收包 * @FilePath: /sync-client/go-utils/utils/sonet/net.go

Index

Constants

View Source
const (
	RetryTimes = 3
)

Variables

This section is empty.

Functions

func Read

func Read(conn net.Conn) (uint32, []byte, error)

*

  • @description: 读取命令数据
  • @param {net.Conn} conn
  • @return {*}

func ReceiveLongData

func ReceiveLongData(conn net.Conn, callbackFunc func([]byte) bool) error

*

  • @description: 接收长数据
  • @param {net.Conn} conn
  • @param {func} callbackFunc
  • @return {error}

func SendFileData

func SendFileData(conn net.Conn, filePath string, offset, expectSize int64, cbFunc func(sentN int)) (int, error)

发送文件

func SendPack

func SendPack(conn net.Conn, msgId uint32, data []byte) (err error)

发送数据包

func TimeoutConn

func TimeoutConn(ip string, port int) (conn net.Conn, err error)

带超时的连接

func Write

func Write(conn net.Conn, command []byte) error

*

  • @description: 写入自拼写命令
  • @param {net.Conn} conn
  • @param {[]byte} command
  • @return {*}

Types

type DataPack

type DataPack struct{}

封包拆包类实例,暂时不需要成员

func NewDataPack

func NewDataPack() *DataPack

封包拆包实例初始化方法

func (*DataPack) GetHeadLen

func (dp *DataPack) GetHeadLen() uint32

获取包头长度方法

func (*DataPack) Pack

func (dp *DataPack) Pack(msg IMessage) ([]byte, error)

封包方法(压缩数据)

func (*DataPack) Unpack

func (dp *DataPack) Unpack(binaryData []byte) (IMessage, error)

拆包方法(解压数据)

type IDataPack

type IDataPack interface {
	GetHeadLen() uint32                //获取包头长度方法
	Pack(msg IMessage) ([]byte, error) //封包方法
	Unpack([]byte) (IMessage, error)   //拆包方法
}

type IMessage

type IMessage interface {
	GetDataLen() uint32 //获取消息数据段长度
	GetMsgId() uint32   //获取消息ID
	GetData() []byte    //获取消息内容

	SetMsgId(uint32)   //设计消息ID
	SetData([]byte)    //设计消息内容
	SetDataLen(uint32) //设置消息数据段长度
}

将请求的一个消息封装到message中,定义抽象层接口

type Message

type Message struct {
	Id      uint32 //消息的ID
	DataLen uint32 //消息的长度
	Data    []byte //消息的内容
}

func NewMsgPackage

func NewMsgPackage(id uint32, data []byte) *Message

创建一个Message消息包

func ReceivePack

func ReceivePack(conn net.Conn) (data *Message, err error)

接收数据包

func (*Message) GetData

func (msg *Message) GetData() []byte

获取消息内容

func (*Message) GetDataLen

func (msg *Message) GetDataLen() uint32

获取消息数据段长度

func (*Message) GetMsgId

func (msg *Message) GetMsgId() uint32

获取消息ID

func (*Message) SetData

func (msg *Message) SetData(data []byte)

设计消息内容

func (*Message) SetDataLen

func (msg *Message) SetDataLen(len uint32)

设置消息数据段长度

func (*Message) SetMsgId

func (msg *Message) SetMsgId(msgId uint32)

设计消息ID

type Pool

type Pool struct{}

Jump to

Keyboard shortcuts

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