public static NetworkMessage Deserialize(byte[] bytes) { BinaryReader reader = new BinaryReader(new MemoryStream(bytes)); NetworkMessage output = new NetworkMessage(); output.data_type = (DataMessage_Type)reader.ReadInt32(); switch (output.data_type) { case DataMessage_Type.GAME_STATE: output.data = GameStateMessage.Deserialize(ref reader); break; case DataMessage_Type.PLAYER_UPDATE: output.data = PlayerUpdateMessage.Deserialize(ref reader); break; case DataMessage_Type.PLAYER_INPUT: output.data = PlayerInputMessage.Deserialize(ref reader); break; default: Debug.Assert(false, "INVALID DATA TYPE"); break; } return(output); }
public static NetworkMessage Deserialize(byte[] bytes) { BinaryReader reader = new BinaryReader(new MemoryStream(bytes)); NetworkMessage output = new NetworkMessage(); output.data_type = (DataMessage_Type)reader.ReadInt32(); switch (output.data_type) { case DataMessage_Type.GAME_STATE: output.data = GameStateMessage.Deserialize(ref reader); break; case DataMessage_Type.PLAYER_UPDATE: output.data = PlayerUpdateMessage.Deserialize(ref reader); break; case DataMessage_Type.MISSLE_MINE: output.data = MissileMineMessage.Deserialize(ref reader); break; case DataMessage_Type.ROTATION: output.data = RotationMessage.Deserialize(ref reader); break; case DataMessage_Type.FENCE_HIT: output.data = FenceHitMessage.Deserialize(ref reader); break; case DataMessage_Type.MISSILEUPDATE: output.data = MissileUpdateMessage.Deserialize(ref reader); break; case DataMessage_Type.GAME_OVER: output.data = GAMEOVERMESSAGE.Deserialize(ref reader); break; default: Debug.Assert(false, "INVALID DATA TYPE"); break; } return(output); }