public static string ReadString(this IReadablePacket packet) { if (!packet.HasString()) { throw new PacketException("Cannot read string."); } var data = packet.ReadByteArray(); return(data == null ? null : Encoding.UTF8.GetString(data)); }