Created
February 17, 2018 21:46
-
-
Save Drawaes/6a96db935edb4eb009d5064e8baf9442 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static unsafe ushort ReadUShort(ref this ByteBufferReader reader) | |
{ | |
var firstSpan = reader.UnreadSegment; | |
ushort returnValue; | |
if (firstSpan.Length >= 2) | |
{ | |
returnValue = BinaryPrimitives.ReadUInt16BigEndian(firstSpan); | |
} | |
else | |
{ | |
var temp = (Span<byte>)stackalloc byte[2]; | |
BufferReader.Peek(reader, temp); | |
returnValue = BinaryPrimitives.ReadUInt16BigEndian(temp); | |
} | |
reader.Advance(2); | |
return returnValue; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment