private static byte[] CreatePacket(int pid, byte[] bytes) { return(HBuffer.NewBuffer(10 + bytes.Length).WithHead() // len:4+reqType:1+pid:5=10 .Write((byte)ReqType.OneWay) .Write(pid).Write(bytes) .UpdateHead().GetBytes()); }
private static byte[] CreatePacket(int pid, ulong seq, byte[] bytes) { return(HBuffer.NewBuffer(20 + bytes.Length).WithHead() // len:4+reqType:1+pid:5+seq:10 = 20 .Write((byte)ReqType.Call) .Write(pid).Write(seq).Write(bytes) .UpdateHead().GetBytes()); }
private void OnReadPacket(byte[] bytes) { var buf = HBuffer.NewBuffer(bytes); var respType = buf.ReadByte(); switch (respType) { case (byte)ReqType.Reply: var seq = buf.ReadUlong(); if (RemoveCall(seq, out var call)) { call.SetResp(buf.GetRestBytes()); } break; case (byte)ReqType.OneWay: _handlerReceivedOneWay(buf.ReadInt(), buf.GetRestBytes()); break; } }