| | | 1 | | // Copyright (c) ZeroC, Inc. |
| | | 2 | | |
| | | 3 | | using IceRpc.Ice.Codec; |
| | | 4 | | |
| | | 5 | | namespace IceRpc.Internal; |
| | | 6 | | |
| | | 7 | | /// <summary>Provides extension methods for Ice facets.</summary> |
| | | 8 | | internal static class FacetExtensions |
| | | 9 | | { |
| | | 10 | | internal static void CheckFacetCount(this IList<string> facet) |
| | 1389 | 11 | | { |
| | 1389 | 12 | | if (facet.Count > 1) |
| | 0 | 13 | | { |
| | 0 | 14 | | throw new InvalidDataException("Received a Facet with too many sequence elements."); |
| | | 15 | | } |
| | 1389 | 16 | | } |
| | | 17 | | |
| | | 18 | | internal static void EncodeFragmentAsFacet(this ref IceEncoder encoder, string fragment) |
| | 51 | 19 | | { |
| | 51 | 20 | | if (fragment.Length == 0) |
| | 50 | 21 | | { |
| | 50 | 22 | | encoder.EncodeSize(0); |
| | 50 | 23 | | } |
| | | 24 | | else |
| | 1 | 25 | | { |
| | 1 | 26 | | encoder.EncodeSize(1); |
| | 1 | 27 | | encoder.EncodeString(Uri.UnescapeDataString(fragment)); |
| | 1 | 28 | | } |
| | 51 | 29 | | } |
| | | 30 | | |
| | | 31 | | internal static string[] DecodeFacet(this ref IceDecoder decoder) => |
| | 45 | 32 | | decoder.DecodeSequence((ref IceDecoder decoder) => decoder.DecodeString()); |
| | | 33 | | |
| | | 34 | | internal static string ToFragment(this IList<string> facet) => |
| | 1431 | 35 | | facet.Count switch |
| | 1431 | 36 | | { |
| | 1430 | 37 | | 0 => "", |
| | 1 | 38 | | 1 => Uri.EscapeDataString(facet[0]), |
| | 0 | 39 | | _ => throw new InvalidDataException("Received a Facet with too many sequence elements.") |
| | 1431 | 40 | | }; |
| | | 41 | | |
| | | 42 | | internal static IList<string> ToFacet(this string fragment) => |
| | 1409 | 43 | | fragment.Length == 0 ? [] : new List<string> { Uri.UnescapeDataString(fragment) }; |
| | | 44 | | } |