| | | 1 | | // Copyright (c) ZeroC, Inc. |
| | | 2 | | |
| | | 3 | | using ZeroC.Slice.Codec; |
| | | 4 | | |
| | | 5 | | namespace IceRpc.Slice; |
| | | 6 | | |
| | | 7 | | /// <summary>Provides extension methods for <see cref="SliceDecoder" /> to decode service addresses.</summary> |
| | | 8 | | public static class ServiceAddressSliceDecoderExtensions |
| | | 9 | | { |
| | | 10 | | /// <summary>Decodes a service address.</summary> |
| | | 11 | | /// <param name="decoder">The Slice decoder.</param> |
| | | 12 | | /// <returns>The decoded service address.</returns> |
| | | 13 | | public static ServiceAddress DecodeServiceAddress(this ref SliceDecoder decoder) |
| | 23 | 14 | | { |
| | 23 | 15 | | string serviceAddressString = decoder.DecodeString(); |
| | | 16 | | try |
| | 23 | 17 | | { |
| | 23 | 18 | | if (serviceAddressString.StartsWith('/')) |
| | 3 | 19 | | { |
| | | 20 | | // relative service address |
| | 3 | 21 | | return new ServiceAddress { Path = serviceAddressString }; |
| | | 22 | | } |
| | | 23 | | else |
| | 20 | 24 | | { |
| | 20 | 25 | | return new ServiceAddress(new Uri(serviceAddressString, UriKind.Absolute)); |
| | | 26 | | } |
| | | 27 | | } |
| | 0 | 28 | | catch (Exception exception) |
| | 0 | 29 | | { |
| | 0 | 30 | | throw new InvalidDataException("Received an invalid service address.", exception); |
| | | 31 | | } |
| | 23 | 32 | | } |
| | | 33 | | } |