summaryrefslogtreecommitdiff
path: root/Impostor-dev/src/Impostor.Benchmarks/Extensions/SpanExtensions.cs
blob: 8fbceeb61b0caf5b865be156f9c1da69ae4beb8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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);
        }
    }
}