f5/prototils.go
aozhiwei 3aa17f7c07 1
2023-08-14 13:29:05 +08:00

104 lines
2.0 KiB
Go

package f5
import (
"q5"
"net"
)
type WspCliConn struct {
Conn net.Conn
SocketHandle uint16
}
type MsgHdr struct {
MsgId uint16
SeqId uint32
SocketHandle uint16
IpSaddr uint32
Conn net.Conn
Data []byte
Msg interface{}
Entry q5.ListHead
}
type NetMsg interface {
GetNetMsgId() uint16
}
/*
struct WSProxyPackHead_C
{
unsigned short packlen;
unsigned short msgid;
unsigned int seqid;
unsigned short magic_code;
unsigned short socket_handle;
unsigned long ip_saddr;
};
*/
type WSProxyPackHead_C struct {
PackLen uint16
MsgId uint16
SeqId uint32
MagicCode uint16
SocketHandle uint16
IpSaddr uint64
}
/*
struct WSProxyPackHead_S
{
unsigned short packlen;
unsigned short msgid;
unsigned int seqid;
unsigned short magic_code;
unsigned short rpc_error_code;
unsigned short socket_handle;
unsigned short ext_len;
};
*/
type WSProxyPackHead_S struct {
PackLen uint16
MsgId uint16
SeqId uint32
MagicCode uint16
RpcErrCode uint16
SocketHandle uint16
ExtLen uint16
}
func (this *WspCliConn) IsValid() bool {
return this.Conn == nil || this.SocketHandle == 0
}
func (this *WspCliConn) Reset() {
this.Conn = nil
this.SocketHandle = 0
}
func (this *WSProxyPackHead_C) Read(data []byte, offset int) {
this.PackLen = q5.MkUInt16(data[offset + 0], data[offset + 1])
this.MsgId = q5.MkUInt16(data[offset + 2], data[offset + 3])
this.SeqId = q5.MkUInt32(data[offset + 4], data[offset + 5],
data[offset + 6], data[offset + 7])
this.MagicCode = q5.MkUInt16(data[offset + 8], data[offset + 9])
this.SocketHandle = q5.MkUInt16(data[offset + 10], data[offset + 11])
}
func (this *WSProxyPackHead_S) Write(data []byte, offset int) {
data[offset + 0] = byte(this.PackLen & 0xFF)
data[offset + 1] = byte(this.PackLen >> 8)
data[offset + 2] = byte(this.MsgId & 0xFF)
data[offset + 3] = byte(this.MsgId >> 8)
data[offset + 8] = byte('K')
data[offset + 9] = byte('S')
data[offset + 12] = byte(this.SocketHandle & 0xFF)
data[offset + 13] = byte(this.SocketHandle >> 8)
}