diff options
author | chai <chaifix@163.com> | 2020-12-30 20:59:04 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2020-12-30 20:59:04 +0800 |
commit | e9ea621b93fbb58d9edfca8375918791637bbd52 (patch) | |
tree | 19ce3b1c1f2d51eda6878c9d0f2c9edc27f13650 /Impostor-dev/src/Impostor.Benchmarks/Extensions |
+init
Diffstat (limited to 'Impostor-dev/src/Impostor.Benchmarks/Extensions')
-rw-r--r-- | Impostor-dev/src/Impostor.Benchmarks/Extensions/SpanExtensions.cs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Impostor-dev/src/Impostor.Benchmarks/Extensions/SpanExtensions.cs b/Impostor-dev/src/Impostor.Benchmarks/Extensions/SpanExtensions.cs new file mode 100644 index 0000000..8fbceeb --- /dev/null +++ b/Impostor-dev/src/Impostor.Benchmarks/Extensions/SpanExtensions.cs @@ -0,0 +1,24 @@ +using System; +using System.Buffers.Binary; +using System.Runtime.CompilerServices; + +namespace Impostor.Benchmarks.Extensions +{ + public static class SpanExtensions + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Span<byte> ReadMessage(this Span<byte> input) + { + var length = BinaryPrimitives.ReadUInt16LittleEndian(input); + var tag = input[2]; + + return input.Slice(3, length); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int ReadUInt16(this ref ReadOnlySpan<byte> input) + { + return BinaryPrimitives.ReadUInt16LittleEndian(input); + } + } +} |