public static byte[] ToByteArray(this IMessageRider token) { if (token == null) { return(null); } if ((tempBytes == null) || (tempBytes.Length != (Core.Config.packetSize - 256))) { tempBytes = new byte[Core.Config.packetSize - 256]; } if (tempPacket == null) { tempPacket = new Packet(); } // clear data Array.Clear(tempBytes, 0, tempBytes.Length); // setup packet tempPacket.Position = 0; tempPacket.ByteBuffer = tempBytes; tempPacket.Size = tempBytes.Length << 3; tempPacket.WriteByte(Factory.GetTokenId(token)); // write token token.Write(tempPacket); return(tempPacket.DuplicateData()); }
public static void WriteToken(this Packet packet, IMessageRider token) { if (packet.WriteBool(token != null)) { // write header byte packet.WriteByte(Factory.GetTokenId(token)); // write token token.Write(packet); } }