Skip to content

Instantly share code, notes, and snippets.

@Drawaes
Created February 17, 2018 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Drawaes/6a96db935edb4eb009d5064e8baf9442 to your computer and use it in GitHub Desktop.
Save Drawaes/6a96db935edb4eb009d5064e8baf9442 to your computer and use it in GitHub Desktop.
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