public override void SendPacket(BitWriter w, TPacket packet) { ushort seq = WriteHeader(w); packet.WritePacket(w); sentPackets[seq] = packet; doSendPacket(w.GetData()); }
/// <summary> /// Packages a packet into a buffer to send /// </summary> /// <returns>The packet.</returns> /// <param name="data">The packet data to send</param> private IO.Buffer PackagePacket(SendData data) { var w = new BitWriter(); w.Write(true); w.Write(data.packet.Id); data.packet.WritePacket(w); return(w.GetData()); }
private IO.Buffer PackageTokenPacket(TPacket packet) { BitWriter w = new BitWriter(); w.Write((int)0); // reserve size int space packet.WriteTokenPacket(w); var payload = w.GetData(); System.Buffer.BlockCopy(BitConverter.GetBytes(payload.size - 4), 0, payload.data, 0, 4); // insert size int to the start return(payload); }
public byte[] Serialize <T>(T value) { var factory = GetFactory(typeof(T)); // write header var w = new BitWriter(); for (int i = 0; i < headerLength; i++) { w.Write((byte)0); } factory.Write(w, value); return(w.GetData().data); }
/// <summary> /// Sends a packet to the remote /// </summary> /// <param name="packet">Packet.</param> private void SendPacket(UdpSendData data) { //Log.Write("Sending: " + data.packet.GetType().Name); lastSent = DateTime.Now; var w = new BitWriter(); WriteUdpHeader(w, data); if (!data.udp) { var channel = channels[data.packet.Id]; channel.SendPacket(w, (TPacket)data.packet); } else { data.packet.WritePacket(w); DoSendData(w.GetData()); } }
public byte[] GetData() => w.GetData();
public override void SendPacket(BitWriter w, TPacket packet) { packet.WritePacket(w); doSendPacket(w.GetData()); }