< Summary

Information
Class: IceRpc.Protocol
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Protocol.cs
Tag: 1986_28452893481
Line coverage
100%
Covered lines: 39
Uncovered lines: 0
Coverable lines: 39
Total lines: 119
Line coverage: 100%
Branch coverage
83%
Covered branches: 5
Total branches: 6
Branch coverage: 83.3%
Method coverage
100%
Covered methods: 16
Fully covered methods: 16
Total methods: 16
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%
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>
 573515    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>
 610819    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>
 113924    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>
 260634    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>
 13541    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>
 50445    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>
 23450    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) =>
 2163        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)
 143271    {
 143272        name = name.ToLowerInvariant();
 143273        protocol = name == IceRpc.Name ? IceRpc : (name == Ice.Name ? Ice : null);
 143274        return protocol is not null;
 143275    }
 76
 77    /// <summary>Converts this protocol into a string.</summary>
 78    /// <returns>The name of the protocol.</returns>
 20879    public override string ToString() => Name;
 80
 81    /// <summary>Checks if a path is valid for this protocol.</summary>
 82    /// <param name="uriPath">The absolute path to check. The caller guarantees it's a valid URI absolute path.
 83    /// </param>
 84    /// <exception cref="FormatException">Thrown if the path is not valid.</exception>
 85    internal virtual void CheckPath(string uriPath)
 28086    {
 87        // by default, any URI absolute path is ok
 28088    }
 89
 90    /// <summary>Checks if these service address parameters are valid for this protocol.</summary>
 91    /// <param name="serviceAddressParams">The service address parameters to check.</param>
 92    /// <exception cref="FormatException">Thrown if the service address parameters are not valid.</exception>
 93    /// <remarks>This method does not and should not check if the parameter names and values are properly escaped;
 94    /// it does not check for the invalid empty and alt-server parameter names either.</remarks>
 95    internal virtual void CheckServiceAddressParams(ImmutableDictionary<string, string> serviceAddressParams)
 6696    {
 97        // by default, any dictionary is ok
 6698    }
 99
 100    /// <summary>Constructs a protocol.</summary>
 32101    private protected Protocol(
 32102        string name,
 32103        ushort defaultPort,
 32104        bool hasFields,
 32105        bool hasFragment,
 32106        bool hasPayloadContinuation,
 32107        bool supportsPayloadWriterInterceptors,
 32108        byte byteValue)
 32109    {
 32110        Name = name;
 32111        AlpnProtocol = new SslApplicationProtocol(name);
 32112        DefaultPort = defaultPort;
 32113        HasFields = hasFields;
 32114        HasFragment = hasFragment;
 32115        HasPayloadContinuation = hasPayloadContinuation;
 32116        SupportsPayloadWriterInterceptors = supportsPayloadWriterInterceptors;
 32117        ByteValue = byteValue;
 32118    }
 119}