| | | 1 | | // Copyright (c) ZeroC, Inc. |
| | | 2 | | |
| | | 3 | | using ZeroC.Slice.Codec; |
| | | 4 | | |
| | | 5 | | namespace IceRpc.Slice.Operations; |
| | | 6 | | |
| | | 7 | | /// <summary>Provides extension methods for <see cref="SliceDecoder" /> to decode proxies.</summary> |
| | | 8 | | public static class SliceProxySliceDecoderExtensions |
| | | 9 | | { |
| | | 10 | | /// <summary>Decodes a proxy struct.</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 struct.</returns> |
| | | 14 | | public static TProxy DecodeProxy<TProxy>(this ref SliceDecoder decoder) where TProxy : struct, ISliceProxy => |
| | 22 | 15 | | CreateProxy<TProxy>(decoder.DecodeServiceAddress(), decoder.DecodingContext); |
| | | 16 | | |
| | | 17 | | private static TProxy CreateProxy<TProxy>(ServiceAddress serviceAddress, object? decodingContext) |
| | | 18 | | where TProxy : struct, ISliceProxy |
| | 22 | 19 | | { |
| | 22 | 20 | | if (decodingContext is null) |
| | 19 | 21 | | { |
| | 19 | 22 | | return new TProxy { Invoker = InvalidInvoker.Instance, ServiceAddress = serviceAddress }; |
| | | 23 | | } |
| | | 24 | | else |
| | 3 | 25 | | { |
| | 3 | 26 | | var baseProxy = (ISliceProxy)decodingContext; |
| | 3 | 27 | | if (serviceAddress.Protocol is null && baseProxy.ServiceAddress is not null) |
| | 1 | 28 | | { |
| | | 29 | | // Convert the relative service address to an absolute service address: |
| | 1 | 30 | | serviceAddress = baseProxy.ServiceAddress with { Path = serviceAddress.Path }; |
| | 1 | 31 | | } |
| | | 32 | | |
| | 3 | 33 | | return new TProxy |
| | 3 | 34 | | { |
| | 3 | 35 | | EncodeOptions = baseProxy.EncodeOptions, |
| | 3 | 36 | | Invoker = baseProxy.Invoker, |
| | 3 | 37 | | ServiceAddress = serviceAddress |
| | 3 | 38 | | }; |
| | | 39 | | } |
| | 22 | 40 | | } |
| | | 41 | | } |