public static JsonRpcUrl Parse(string packedUrlValue) { if (packedUrlValue == null) { throw new ArgumentNullException(nameof(packedUrlValue)); } string[] parts = packedUrlValue.Split('|'); if (parts.Length != 3 && parts.Length != 4) { throw new FormatException("Packed url value must contain 3 or 4 parts delimited by '|'"); } string url = parts[0]; if (!Uri.TryCreate(url, UriKind.Absolute, out Uri? uri) || (uri.Scheme != Uri.UriSchemeHttp && uri.Scheme != Uri.UriSchemeHttps) || uri.Segments.Count() > 1 || uri.Port == 0) { throw new FormatException("First part must be a valid url with the format: scheme://host:port"); } string[] endpointValues = parts[1].Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); if (endpointValues.Length == 0) { throw new FormatException("Second part must contain at least one valid endpoint value delimited by ';'"); } RpcEndpoint endpoint = RpcEndpoint.None; foreach (string endpointValue in endpointValues) { if (FastEnum.TryParse(endpointValue, ignoreCase: true, out RpcEndpoint parsedEndpoint) && (parsedEndpoint == RpcEndpoint.Http || parsedEndpoint == RpcEndpoint.Ws)) { endpoint |= parsedEndpoint; } } if (endpoint == RpcEndpoint.None) { throw new FormatException($"Second part must contain at least one valid endpoint value (http, https, ws, wss)"); } string[] enabledModules = parts[2].Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); if (enabledModules.Length == 0) { throw new FormatException("Third part must contain at least one module delimited by ';'"); } bool isAuthenticated = enabledModules.Any(m => m.ToLower() == "engine"); // Check if authentication disabled for this url if (parts.Length == 4) { if (parts[3] != "no-auth") { throw new FormatException("Fourth part should be \"no-auth\""); } isAuthenticated = false; } JsonRpcUrl result = new (uri.Scheme, uri.Host, uri.Port, endpoint, isAuthenticated, enabledModules); return(result); }
public void ParseIgnoreCase() => FluentActions.Invoking(() => FastEnum.Parse <TEnum>("ABCDE", true)).Should().Throw <ArgumentException>();
public void TryParseIgnoreCase() { FastEnum.TryParse <TEnum>("ABCDE", out var _).Should().BeFalse(); FastEnum.TryParse <TEnum>("", out var _).Should().BeFalse(); }
public void ContinuousContainsSameValue() => FastEnum.IsContinuous <ContinuousValueContainsSameValueEnum>().Should().Be(true);
public void IsEmpty() => FastEnum.IsEmpty <TEnum>().Should().BeTrue();
public void GetUnderlyingType() => FastEnum.GetUnderlyingType <TEnum>().Should().Be <TUnderlying>();
public void IsContinuous() => FastEnum.IsContinuous <TEnum>().Should().Be(false);
public void Setup() { _ = UniEnum.GetValues <IntEnum1>(); _ = FastEnum.GetValues <IntEnum1>(); _ = Enum.GetValues(typeof(IntEnum1)); }
public IReadOnlyList <IntEnum1> FastEnum_Values() { return(FastEnum.GetValues <IntEnum1>()); }
public bool FastEnum_Short_IsDefined() { return(FastEnum.IsDefined <ShortEnum1>((short)1000)); }
protected override void ChannelRead0(IChannelHandlerContext ctx, DatagramPacket packet) { IByteBuffer content = packet.Content; EndPoint address = packet.Sender; byte[] msgBytes = new byte[content.ReadableBytes]; content.ReadBytes(msgBytes); Interlocked.Add(ref Metrics.DiscoveryBytesReceived, msgBytes.Length); if (msgBytes.Length < 98) { if (_logger.IsDebug) { _logger.Debug($"Incorrect discovery message, length: {msgBytes.Length}, sender: {address}"); } return; } byte typeRaw = msgBytes[97]; if (!FastEnum.IsDefined <MsgType>((int)typeRaw)) { if (_logger.IsDebug) { _logger.Debug($"Unsupported message type: {typeRaw}, sender: {address}, message {msgBytes.ToHexString()}"); } return; } MsgType type = (MsgType)typeRaw; if (_logger.IsTrace) { _logger.Trace($"Received message: {type}"); } DiscoveryMsg msg; try { msg = Deserialize(type, msgBytes); msg.FarAddress = (IPEndPoint)address; } catch (Exception e) { if (_logger.IsDebug) { _logger.Debug($"Error during deserialization of the message, type: {type}, sender: {address}, msg: {msgBytes.ToHexString()}, {e.Message}"); } return; } try { ReportMsgByType(msg); if (!ValidateMsg(msg, type, address, ctx, packet)) { return; } _discoveryManager.OnIncomingMsg(msg); } catch (Exception e) { if (_logger.IsDebug) { _logger.Error($"DEBUG/ERROR Error while processing message, type: {type}, sender: {address}, message: {msg}", e); } } }
public void Setup() { UniEnum.IsDefined <ShortEnum1>((short)1000); FastEnum.IsDefined <ShortEnum1>((short)1000); }
internal sealed override TEnum?AssertValueType(object value) { var integer = value as long?; return(integer.HasValue ? FastEnum.ToEnum <TEnum>(integer.Value) : base.AssertValueType(value)); }
public void NotContinuous() => FastEnum.IsContinuous <NotContinuousValueEnum>().Should().Be(false);
internal sealed override TEnum?ReadValue(EmberReader reader, out ParameterType?parameterType) { parameterType = ParameterType.Enum; return(FastEnum.ToEnum <TEnum>(reader.AssertAndReadContentsAsInt64())); }
public void GetNames() => FastEnum.GetNames <TEnum>().Should().BeEmpty();
internal sealed override void WriteValue(EmberWriter writer, TEnum?value) => writer.WriteValue(GlowParameterContents.Value.OuterId, FastEnum.ToInt64(value.GetValueOrDefault()));
public void GetMembers() => FastEnum.GetMembers <TEnum>().Should().BeEmpty();
public void IsEmpty() => FastEnum.IsEmpty <TEnum>().Should().Be(false);
public void GetMaxValue() => FastEnum.GetMaxValue <TEnum>().Should().BeNull();
public void IsFlags() => FastEnum.IsFlags <TEnum>().Should().Be(false);
public void Continuous() => FastEnum.IsContinuous <ContinuousValueEnum>().Should().Be(true);