/
dev-npgsql
/
npgsql
Обзор
Документация
Войти
/
dev-npgsql
/
npgsql
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
v4.1.14
src/Npgsql/Util/PGUtil.cs
97 строк
3 KB
Shay Rojansky
Various changes to reestablish 4.0 backwards compat
30 сен 2019, 18:26
30 сен 2019, 18:26
8c563a7
Код
Авторство
О чём код?
using System; using System.Collections.Generic; using System.Globalization; using System.Runtime.CompilerServices; using System.Text; using System.Threading; using System.Threading.Tasks; namespace Npgsql.Util { static class Statics { [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static T Expect<T>(IBackendMessage msg, NpgsqlConnector connector) { if (msg is T asT) return asT; connector.Break(); throw new NpgsqlException($"Received backend message {msg.Code} while expecting {typeof(T).Name}. Please file a bug."); } } // ReSharper disable once InconsistentNaming static class PGUtil { internal static readonly UTF8Encoding UTF8Encoding = new UTF8Encoding(false, true); internal static readonly UTF8Encoding RelaxedUTF8Encoding = new UTF8Encoding(false, false); internal const int BitsInInt = sizeof(int) * 8; internal static void ValidateBackendMessageCode(BackendMessageCode code) { switch (code) { case BackendMessageCode.AuthenticationRequest: case BackendMessageCode.BackendKeyData: case BackendMessageCode.BindComplete: case BackendMessageCode.CloseComplete: case BackendMessageCode.CompletedResponse: case BackendMessageCode.CopyData: case BackendMessageCode.CopyDone: case BackendMessageCode.CopyBothResponse: case BackendMessageCode.CopyInResponse: case BackendMessageCode.CopyOutResponse: case BackendMessageCode.DataRow: case BackendMessageCode.EmptyQueryResponse: case BackendMessageCode.ErrorResponse: case BackendMessageCode.FunctionCall: case BackendMessageCode.FunctionCallResponse: case BackendMessageCode.NoData: case BackendMessageCode.NoticeResponse: case BackendMessageCode.NotificationResponse: case BackendMessageCode.ParameterDescription: case BackendMessageCode.ParameterStatus: case BackendMessageCode.ParseComplete: case BackendMessageCode.PasswordPacket: case BackendMessageCode.PortalSuspended: case BackendMessageCode.ReadyForQuery: case BackendMessageCode.RowDescription: return; default: throw new NpgsqlException("Unknown message code: " + code); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static int RotateShift(int val, int shift) => (val << shift) | (val >> (BitsInInt - shift)); internal static readonly Task<bool> TrueTask = Task.FromResult(true); internal static readonly Task<bool> FalseTask = Task.FromResult(false); internal static StringComparer InvariantCaseIgnoringStringComparer => StringComparer.InvariantCultureIgnoreCase; internal static bool IsWindows => #if NET461 Environment.OSVersion.Platform == PlatformID.Win32NT; #else System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows); #endif } enum FormatCode : short { Text = 0, Binary = 1 } static class EnumerableExtensions { internal static string Join(this IEnumerable<string> values, string separator) { return string.Join(separator, values); } } }