public override void Deserialize(byte[] data) { MyByteBuffer bf = new MyByteBuffer(data.Length, false); bf.put(data); framID = bf.readInt64(); actorServerID = bf.readInt32(); dir = new Int3(bf.readInt32(), bf.readInt32(), bf.readInt32()); speed = bf.readInt32(); }
public void copyFrom(MyByteBuffer other) { if (other.mBuffer.Size <= 0) { return; } byte[] bytes = new byte[other.mBuffer.Size]; other.readBytes(bytes); mBuffer.Put(bytes); }
private void onReceive(Socket sock, byte[] bytes, int len) { try { var clientInfo = clients[sock]; if (len > 0 && bytes != null) { if (len > clientInfo.mByteBuffer.canUse()) { MyByteBuffer byteBuffer = new MyByteBuffer(clientInfo.mByteBuffer.maxSize() * 2 + len, false); byteBuffer.copyFrom(clientInfo.mByteBuffer); clientInfo.mByteBuffer = byteBuffer; } clientInfo.mByteBuffer.put(bytes, len); do { if (clientInfo.mByteBuffer.remaining() < 4) { break; } int bufLen = clientInfo.mByteBuffer.readInt32(); if (bufLen > clientInfo.mByteBuffer.maxSize() || bufLen <= 0) { Logger.err("数据长度超过限制: " + bufLen); break; } if (clientInfo.mByteBuffer.remaining() < bufLen) { clientInfo.mByteBuffer.resetHead(4); //Log(EventId.Net_Error, "remaining 长度不够:" + bufLen); break; } int msgID = clientInfo.mByteBuffer.readInt32(); // byte[] content = null; if (bufLen - 4 > 0) { content = new byte[bufLen - 4]; clientInfo.mByteBuffer.readBytes(content); } if (msgID == FrameMsgID.FrameCMD) { var cmd = new MoveCMD(); cmd.Deserialize(content); lock (clientInfo.lockObj) { clientInfo.cmdList.AddLast(cmd); } } // Logger.err("收到客户端数据:" + BitConverter.ToInt32(content,0)); //////////MessageUtils.sendToGameLogic(msgId, content); }while (true); } } catch (Exception ex) { Logger.err(ex.ToString()); } }
private void onReceive(byte[] bytes, int len) { try { if (len > 0 && bytes != null) { if (len > mByteBuffer.canUse()) { MyByteBuffer byteBuffer = new MyByteBuffer(mByteBuffer.maxSize() * 2 + len, false); byteBuffer.copyFrom(mByteBuffer); mByteBuffer = byteBuffer; } mByteBuffer.put(bytes, len); do { if (mByteBuffer.remaining() < 4) { break; } int tmp = mByteBuffer.readInt32(); int bufLen = (tmp & 0x7FFFFF); if (bufLen > mByteBuffer.maxSize() || bufLen <= 0) { Debug.LogError("数据长度超过限制: " + bufLen); break; } if (mByteBuffer.remaining() < bufLen) { mByteBuffer.resetHead(4); //Log(EventId.Net_Error, "remaining 长度不够:" + bufLen); break; } int msgID = mByteBuffer.readInt32(); // byte[] content = null; if (bufLen - 4 > 0) { content = new byte[bufLen - 4]; mByteBuffer.readBytes(content); } lock (lockObj) { msgQueue.Enqueue(new MessageData { msgID = msgID, data = content }); } // Logger.err("收到服务器数据:" + BitConverter.ToInt32(content, 0)); //////////MessageUtils.sendToGameLogic(msgId, content); }while (true); } } catch (Exception ex) { Logger.err(ex.ToString()); } }
public virtual void Deserialize(byte[] data) { MyByteBuffer bf = new MyByteBuffer(data.Length, false); bf.put(data); }
public void WriteTo(Stream outs) { MyByteBuffer bb = new MyByteBuffer( this ); bb.Write((System.Int16) version); bb.Write((System.Byte) 0); bb.Write((System.Byte) 0); WriteAE(bb, calledAET); WriteAE(bb, callingAET); bb.Write(ZERO32); bb.Write((System.Byte) 0x10); bb.Write((System.Byte) 0); bb.Write((System.Int16) appCtxUID.Length); bb.Write(appCtxUID); for (IEnumerator enu = presCtxs.Values.GetEnumerator(); enu.MoveNext(); ) { ((PresContext) enu.Current).WriteTo(bb); } WriteUserInfo(bb); bb.WriteTo(type(), outs); }