public Message Deserialize(byte[] bytes) { BitBuffer bitBuffer = new BitBuffer(bytes); switch ((MessageType)bitBuffer.DequeueEnum(MessageType.TOTAL)) { case MessageType.CLIENT: switch ((ClientMessageType)bitBuffer.DequeueEnum(ClientMessageType.TOTAL)) { case ClientMessageType.JOIN: return(new JoinMessage(bitBuffer)); case ClientMessageType.LEAVE: return(new LeaveMessage(bitBuffer)); case ClientMessageType.GAME: switch ((GameMessageType)bitBuffer.DequeueEnum(GameMessageType.TOTAL)) { case GameMessageType.MOVEMENT: return(new MovementMessage(bitBuffer)); } break; } break; case MessageType.SERVER: switch ((ServerMessageType)bitBuffer.DequeueEnum(ServerMessageType.TOTAL)) { case ServerMessageType.PLAYER_JOINED: return(new PlayerJoinedMessage(bitBuffer)); case ServerMessageType.PLAYER_LEFT: return(new PlayerLeftMessage(bitBuffer)); case ServerMessageType.SNAPSHOT: return(new SnapshotMessage(bitBuffer)); } break; } throw new Exception("Unknown object when deserializing!"); }