public static void ParsePayload(byte[] payload, out int playerId) { System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(payload); System.IO.BinaryReader binaryReader = new System.IO.BinaryReader(memoryStream); if ((binaryReader.ReadBoolean() == true)) { PlayerDataReqPayload.BinaryReader(binaryReader, out playerId); } else { playerId = 0; } binaryReader.Close(); memoryStream.Close(); }
public static byte[] CreatePayload(int playerId) { byte[] byteArray; System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(); System.IO.BinaryWriter binaryWriter = new System.IO.BinaryWriter(memoryStream); if ((playerId != 0)) { binaryWriter.Write(true); PlayerDataReqPayload.BinaryWriter(binaryWriter, playerId); } else { binaryWriter.Write(false); } byteArray = memoryStream.ToArray(); binaryWriter.Close(); memoryStream.Close(); return(byteArray); }