public static IGatewayMessage GetMessage(MessageReceivedEventArgs e) { GatewayPacketHeader header = GatewayPacketHeader.GetMessage(e); // 映射包的结构体 GatewayPacketBody body = GatewayPacketBody.GetMessage(ref header, e); return(new GatewayPacketMessage(header, body, e.RemoteEP, e.LocalEP, e.LinqNo)); }
public static GatewayPacketBody GetMessage(ref GatewayPacketHeader header, MessageReceivedEventArgs args) { byte[] message = args.Buffer; int offset = sizeof(GatewayPacketHeader); // 位于包头的偏移 if (offset > message.Length) { return(null); } GatewayPacketBody body = new GatewayPacketBody(); if (body.qclinkNo == null) { body.qclinkNo = new List <int>(); } for (int i = 0; i < header.qdLinkCount; i++) { fixed(byte *ptrs = &args.Buffer[offset]) { int linkno = *((int *)ptrs); body.qclinkNo.Add(linkno); offset += sizeof(int); } } body.szBuffer = message; // 客户端发过来的数据(客户端数据+网关包头) body.dwBufferOfs = offset; // 客户端数据开始索引 body.szBufferLen = message.Length - offset; // 客户端数据长度 return(body); }
private GatewayPacketMessage(GatewayPacketHeader header, GatewayPacketBody body, EndPoint remote, EndPoint local, long linkNo) { pBody = body; pRemoteEP = remote; pLocalEP = local; pHeader = header; pLinkNo = linkNo; }