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{} Context interface{} Entry q5.ListHead } type NetMsgHandler[T any] struct { MsgId int HandlerId int ParseCb func([]byte) interface{} Cb func(*MsgHdr, T) } 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 *MsgHdr) GetSocket() WspCliConn{ socket := WspCliConn{} socket.Conn = this.Conn socket.SocketHandle = this.SocketHandle return socket } 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]) this.IpSaddr = uint64(q5.MkInt64( int32(q5.MkUInt32(data[offset + 16], data[offset + 17], data[offset + 18], data[offset + 17])), int32(q5.MkUInt32(data[offset + 20], data[offset + 21], data[offset + 22], data[offset + 23])), )) } 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) }