| | 1 | | // Copyright (c) ZeroC, Inc. |
| | 2 | |
|
| | 3 | | using System.Buffers; |
| | 4 | | using ZeroC.Slice; |
| | 5 | |
|
| | 6 | | namespace IceRpc.Internal; |
| | 7 | |
|
| | 8 | | /// <summary>Extension methods for <see cref="SliceEncoding" />.</summary> |
| | 9 | | internal static class SliceEncodingExtensions |
| | 10 | | { |
| | 11 | | /// <summary>Decodes a buffer.</summary> |
| | 12 | | /// <typeparam name="T">The decoded type.</typeparam> |
| | 13 | | /// <param name="encoding">The Slice encoding.</param> |
| | 14 | | /// <param name="buffer">The byte buffer.</param> |
| | 15 | | /// <param name="decodeFunc">The decode function for buffer.</param> |
| | 16 | | /// <returns>The decoded value.</returns> |
| | 17 | | /// <exception cref="InvalidDataException">Thrown when <paramref name="decodeFunc" /> finds invalid data. |
| | 18 | | /// </exception> |
| | 19 | | internal static T DecodeBuffer<T>( |
| | 20 | | this SliceEncoding encoding, |
| | 21 | | ReadOnlySequence<byte> buffer, |
| | 22 | | DecodeFunc<T> decodeFunc) |
| 18810 | 23 | | { |
| 18810 | 24 | | var decoder = new SliceDecoder(buffer, encoding); |
| 18810 | 25 | | T result = decodeFunc(ref decoder); |
| 18798 | 26 | | decoder.CheckEndOfBuffer(); |
| 18792 | 27 | | return result; |
| 18792 | 28 | | } |
| | 29 | | } |