< Summary

Information
Class: IceRpc.Protocol
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Protocol.cs
Tag: 1321_24790053727
Line coverage
100%
Covered lines: 42
Uncovered lines: 0
Coverable lines: 42
Total lines: 124
Line coverage: 100%
Branch coverage
80%
Covered branches: 8
Total branches: 10
Branch coverage: 80%
Method coverage
100%
Covered methods: 17
Fully covered methods: 17
Total methods: 17
Method coverage: 100%
Full method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Ice()100%11100%
get_IceRpc()100%11100%
get_DefaultPort()100%11100%
get_HasFields()100%11100%
get_Name()100%11100%
get_AlpnProtocol()100%11100%
get_ByteValue()100%11100%
get_HasFragment()100%11100%
get_HasPayloadContinuation()100%11100%
get_SupportsPayloadWriterInterceptors()100%11100%
Parse(...)50%22100%
TryParse(...)100%44100%
ToString()100%11100%
FromByteValue(...)75%44100%
CheckPath(...)100%11100%
CheckServiceAddressParams(...)100%11100%
.ctor(...)100%11100%

File(s)

/home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Protocol.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3using IceRpc.Internal;
 4using System.Collections.Immutable;
 5using System.Diagnostics.CodeAnalysis;
 6using System.Net.Security;
 7
 8namespace IceRpc;
 9
 10/// <summary>Represents an RPC protocol supported by IceRPC.</summary>
 11public class Protocol
 12{
 13    /// <summary>Gets the ice protocol.</summary>
 14    /// <value>The <see cref="Protocol" /> instance for the ice protocol.</value>
 562415    public static Protocol Ice => IceProtocol.Instance;
 16
 17    /// <summary>Gets the icerpc protocol.</summary>
 18    /// <value>The <see cref="Protocol" /> instance for the icerpc protocol.</value>
 595719    public static Protocol IceRpc => IceRpcProtocol.Instance;
 20
 21    /// <summary>Gets the default port for this protocol.</summary>
 22    /// <value>The default port value. Defaults to <c>4061</c> for the ice protocol and <c>4062</c> for the icerpc
 23    /// protocol.</value>
 107224    public ushort DefaultPort { get; }
 25
 26    /// <summary>Gets a value indicating whether or not this protocol supports arbitrary application-defined fields in
 27    /// request and response headers.</summary>
 28    /// <value><see langword="true" /> if the protocol supports arbitrary fields; otherwise, <see langword="false" />.
 29    /// </value>
 4730    public bool HasFields { get; }
 31
 32    /// <summary>Gets the name of this protocol.</summary>
 33    /// <value>The protocol name.</value>
 248234    public string Name { get; }
 35
 36    /// <summary>Gets the ALPN protocol identifier for this protocol.</summary>
 1537    internal SslApplicationProtocol AlpnProtocol { get; }
 38
 39    /// <summary>Gets the byte value for this protocol.</summary>
 40    /// <value>The protocol byte value. It's used as the "protocol major" with the Ice encoding.</value>
 11541    internal byte ByteValue { get; }
 42
 43    /// <summary>Gets a value indicating whether or not this protocol supports fragments in service addresses.</summary>
 44    /// <value><see langword="true" /> if the protocol supports fragments; otherwise, <see langword="false" />.</value>
 48245    internal bool HasFragment { get; }
 46
 47    /// <summary>Gets a value indicating whether or not this protocol supports payload continuations.</summary>
 48    /// <value><see langword="true" /> if the protocol supports payload continuations; otherwise,
 49    /// <see langword="false" />.</value>
 20050    internal bool HasPayloadContinuation { get; }
 51
 52    /// <summary>Gets a value indicating whether or not the implementation of the protocol connection supports payload
 53    /// writer interceptors.</summary>
 54    /// <value><see langword="true" /> if the implementation of the protocol connection supports payload writer
 55    /// interceptors; otherwise, <see langword="false" />.</value>
 1356    internal bool SupportsPayloadWriterInterceptors { get; }
 57
 58    /// <summary>Parses a string into a protocol.</summary>
 59    /// <param name="name">The name of the protocol.</param>
 60    /// <returns>A protocol with the given name in lowercase.</returns>
 61    /// <exception cref="FormatException">Thrown when <paramref name="name" /> is not ice or icerpc.</exception>
 62    public static Protocol Parse(string name) =>
 1963        TryParse(name, out Protocol? protocol) ? protocol : throw new FormatException($"unknown protocol '{name}'");
 64
 65    /// <summary>Tries to parse a string into a protocol.</summary>
 66    /// <param name="name">The name of the protocol.</param>
 67    /// <param name="protocol">The protocol parsed from the name.</param>
 68    /// <returns><see langword="true" /> when <paramref name="name" /> was successfully parsed into a protocol;
 69    /// otherwise, <see langword="false" />.</returns>
 70    public static bool TryParse(string name, [NotNullWhen(true)] out Protocol? protocol)
 136871    {
 136872        name = name.ToLowerInvariant();
 136873        protocol = name == IceRpc.Name ? IceRpc : (name == Ice.Name ? Ice : null);
 136874        return protocol is not null;
 136875    }
 76
 77    /// <summary>Converts this protocol into a string.</summary>
 78    /// <returns>The name of the protocol.</returns>
 20179    public override string ToString() => Name;
 80
 81    internal static Protocol FromByteValue(byte value) =>
 4482        value == Ice.ByteValue ? Ice :
 4483            (value == IceRpc.ByteValue ? IceRpc :
 4484                throw new NotSupportedException($"Cannot convert '{value}' into a protocol."));
 85
 86    /// <summary>Checks if a path is valid for this protocol.</summary>
 87    /// <param name="uriPath">The absolute path to check. The caller guarantees it's a valid URI absolute path.
 88    /// </param>
 89    /// <exception cref="FormatException">Thrown if the path is not valid.</exception>
 90    internal virtual void CheckPath(string uriPath)
 27091    {
 92        // by default, any URI absolute path is ok
 27093    }
 94
 95    /// <summary>Checks if these service address parameters are valid for this protocol.</summary>
 96    /// <param name="serviceAddressParams">The service address parameters to check.</param>
 97    /// <exception cref="FormatException">Thrown if the service address parameters are not valid.</exception>
 98    /// <remarks>This method does not and should not check if the parameter names and values are properly escaped;
 99    /// it does not check for the invalid empty and alt-server parameter names either.</remarks>
 100    internal virtual void CheckServiceAddressParams(ImmutableDictionary<string, string> serviceAddressParams)
 64101    {
 102        // by default, any dictionary is ok
 64103    }
 104
 105    /// <summary>Constructs a protocol.</summary>
 27106    private protected Protocol(
 27107        string name,
 27108        ushort defaultPort,
 27109        bool hasFields,
 27110        bool hasFragment,
 27111        bool hasPayloadContinuation,
 27112        bool supportsPayloadWriterInterceptors,
 27113        byte byteValue)
 27114    {
 27115        Name = name;
 27116        AlpnProtocol = new SslApplicationProtocol(name);
 27117        DefaultPort = defaultPort;
 27118        HasFields = hasFields;
 27119        HasFragment = hasFragment;
 27120        HasPayloadContinuation = hasPayloadContinuation;
 27121        SupportsPayloadWriterInterceptors = supportsPayloadWriterInterceptors;
 27122        ByteValue = byteValue;
 27123    }
 124}