private object DeserializeLoginPacket(UncompressedPacket packet) { var br = new SpanReader(packet.Data); object innerPacket; switch (packet.PacketId) { // Disconnect case 0x00: innerPacket = LoginDisconnect.Deserialize(ref br); break; // Login Success case 0x02: innerPacket = LoginSuccess.Deserialize(ref br); break; default: throw new InvalidDataException($"Unrecognizable packet id: 0x{packet.PacketId:X2}."); } if (!br.IsCosumed) { throw new InvalidDataException($"Packet data is not fully consumed."); } return(innerPacket); }