< Summary

Information
Class: IceRpc.Slice.ProxySliceDecoderExtensions
Assembly: IceRpc.Slice
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc.Slice/ProxySliceDecoderExtensions.cs
Tag: 275_13775359185
Line coverage
100%
Covered lines: 23
Uncovered lines: 0
Coverable lines: 23
Total lines: 52
Line coverage: 100%
Branch coverage
100%
Covered branches: 12
Total branches: 12
Branch coverage: 100%
Method coverage
100%
Covered methods: 3
Total methods: 3
Method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
DecodeNullableProxy(...)100%22100%
DecodeProxy(...)100%44100%
CreateProxy(...)100%66100%

File(s)

/home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc.Slice/ProxySliceDecoderExtensions.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3using ZeroC.Slice;
 4
 5namespace IceRpc.Slice;
 6
 7/// <summary>Provides extension methods for <see cref="SliceDecoder" /> to decode proxies.</summary>
 8public static class ProxySliceDecoderExtensions
 9{
 10    /// <summary>Decodes a nullable proxy struct (Slice1 only).</summary>
 11    /// <typeparam name="TProxy">The type of the proxy struct to decode.</typeparam>
 12    /// <param name="decoder">The Slice decoder.</param>
 13    /// <returns>The decoded proxy, or <see langword="null" />.</returns>
 14    public static TProxy? DecodeNullableProxy<TProxy>(this ref SliceDecoder decoder) where TProxy : struct, IProxy =>
 3815        decoder.DecodeNullableServiceAddress() is ServiceAddress serviceAddress ?
 3816            CreateProxy<TProxy>(serviceAddress, decoder.DecodingContext) : null;
 17
 18    /// <summary>Decodes a proxy struct.</summary>
 19    /// <typeparam name="TProxy">The type of the proxy struct to decode.</typeparam>
 20    /// <param name="decoder">The Slice decoder.</param>
 21    /// <returns>The decoded proxy struct.</returns>
 22    public static TProxy DecodeProxy<TProxy>(this ref SliceDecoder decoder) where TProxy : struct, IProxy =>
 4223        decoder.Encoding == SliceEncoding.Slice1 ?
 4224            decoder.DecodeNullableProxy<TProxy>() ??
 4225                throw new InvalidDataException("Decoded null for a non-nullable proxy.") :
 4226           CreateProxy<TProxy>(decoder.DecodeServiceAddress(), decoder.DecodingContext);
 27
 28    private static TProxy CreateProxy<TProxy>(ServiceAddress serviceAddress, object? decodingContext)
 29        where TProxy : struct, IProxy
 5230    {
 5231        if (decodingContext is null)
 4132        {
 4133            return new TProxy { Invoker = InvalidInvoker.Instance, ServiceAddress = serviceAddress };
 34        }
 35        else
 1136        {
 1137            var baseProxy = (IProxy)decodingContext;
 1138            if (serviceAddress.Protocol is null && baseProxy.ServiceAddress is not null)
 139            {
 40                // Convert the relative service address to an absolute service address:
 141                serviceAddress = baseProxy.ServiceAddress with { Path = serviceAddress.Path };
 142            }
 43
 1144            return new TProxy
 1145            {
 1146                EncodeOptions = baseProxy.EncodeOptions,
 1147                Invoker = baseProxy.Invoker,
 1148                ServiceAddress = serviceAddress
 1149            };
 50        }
 5251    }
 52}