| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | // See the LICENSE file in the project root for more information. |
| | | 4 | | |
| | | 5 | | using System.Buffers; |
| | | 6 | | |
| | | 7 | | namespace System.Runtime.InteropServices |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// Provides a collection of methods for interoperating with <see cref="ReadOnlySequence{T}"/> |
| | | 11 | | /// </summary> |
| | | 12 | | public static partial class SequenceMarshal |
| | | 13 | | { |
| | | 14 | | /// <summary> |
| | | 15 | | /// Get <see cref="ReadOnlySequenceSegment{T}"/> from the underlying <see cref="ReadOnlySequence{T}"/>. |
| | | 16 | | /// If unable to get the <see cref="ReadOnlySequenceSegment{T}"/>, return false. |
| | | 17 | | /// </summary> |
| | | 18 | | public static bool TryGetReadOnlySequenceSegment<T>(ReadOnlySequence<T> sequence, |
| | | 19 | | out ReadOnlySequenceSegment<T> startSegment, |
| | | 20 | | out int startIndex, |
| | | 21 | | out ReadOnlySequenceSegment<T> endSegment, |
| | | 22 | | out int endIndex) |
| | 1 | 23 | | { |
| | 1 | 24 | | return sequence.TryGetReadOnlySequenceSegment(out startSegment, out startIndex, out endSegment, out endIndex |
| | 1 | 25 | | } |
| | | 26 | | |
| | | 27 | | /// <summary> |
| | | 28 | | /// Get an array segment from the underlying <see cref="ReadOnlySequence{T}"/>. |
| | | 29 | | /// If unable to get the array segment, return false with a default array segment. |
| | | 30 | | /// </summary> |
| | | 31 | | public static bool TryGetArray<T>(ReadOnlySequence<T> sequence, out ArraySegment<T> arraySegment) |
| | 1 | 32 | | { |
| | 1 | 33 | | return sequence.TryGetArray(out arraySegment); |
| | 1 | 34 | | } |
| | | 35 | | |
| | | 36 | | /// <summary> |
| | | 37 | | /// Get <see cref="OwnedMemory{T}"/> from the underlying <see cref="ReadOnlySequence{T}"/>. |
| | | 38 | | /// If unable to get the <see cref="OwnedMemory{T}"/>, return false. |
| | | 39 | | /// </summary> |
| | | 40 | | public static bool TryGetOwnedMemory<T>(ReadOnlySequence<T> sequence, out OwnedMemory<T> ownedMemory, out int st |
| | 1 | 41 | | { |
| | 1 | 42 | | return sequence.TryGetOwnedMemory(out ownedMemory, out start, out length); |
| | 1 | 43 | | } |
| | | 44 | | |
| | | 45 | | /// <summary> |
| | | 46 | | /// Get <see cref="ReadOnlyMemory{T}"/> from the underlying <see cref="ReadOnlySequence{T}"/>. |
| | | 47 | | /// If unable to get the <see cref="ReadOnlyMemory{T}"/>, return false. |
| | | 48 | | /// </summary> |
| | | 49 | | public static bool TryGetReadOnlyMemory<T>(ReadOnlySequence<T> sequence, out ReadOnlyMemory<T> readOnlyMemory) |
| | 1 | 50 | | { |
| | 1 | 51 | | return sequence.TryGetReadOnlyMemory(out readOnlyMemory); |
| | 1 | 52 | | } |
| | | 53 | | |
| | | 54 | | /// <summary> |
| | | 55 | | /// Get <see cref="string"/> from the underlying <see cref="ReadOnlySequence{T}"/>. |
| | | 56 | | /// If unable to get the <see cref="string"/>, return false. |
| | | 57 | | /// </summary> |
| | | 58 | | internal static bool TryGetString(ReadOnlySequence<char> sequence, out string text, out int start, out int lengt |
| | | 59 | | { |
| | | 60 | | return sequence.TryGetString(out text, out start, out length); |
| | | 61 | | } |
| | | 62 | | } |
| | | 63 | | } |