/
githubmirror
/
aspnetcore
Обзор
Документация
Войти
/
githubmirror
/
aspnetcore
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/SignalR/common/Shared/TextMessageParser.cs
53 строки
1 KB
Pranav K
Use file scoped namespaces (#38076)
06 ноя 2021, 03:52
Не верифицирован
06 ноя 2021, 03:52
a450cb6
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System; using System.Buffers; using System.Runtime.CompilerServices; namespace Microsoft.AspNetCore.Internal; internal static class TextMessageParser { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseMessage(ref ReadOnlySequence<byte> buffer, out ReadOnlySequence<byte> payload) { if (buffer.IsSingleSegment) { var span = buffer.First.Span; var index = span.IndexOf(TextMessageFormatter.RecordSeparator); if (index == -1) { payload = default; return false; } payload = buffer.Slice(0, index); buffer = buffer.Slice(index + 1); return true; } else { return TryParseMessageMultiSegment(ref buffer, out payload); } } private static bool TryParseMessageMultiSegment(ref ReadOnlySequence<byte> buffer, out ReadOnlySequence<byte> payload) { var position = buffer.PositionOf(TextMessageFormatter.RecordSeparator); if (position == null) { payload = default; return false; } payload = buffer.Slice(0, position.Value); // Skip record separator buffer = buffer.Slice(buffer.GetPosition(1, position.Value)); return true; } }