<PackageReference Include="System.Memory" Version="4.6.2" />

BinaryPrimitives

public static class BinaryPrimitives
Reads bytes as primitives with specific endianness
public static short ReadInt16BigEndian(ReadOnlySpan<byte> source)

Reads an Int16 out of a read-only span of bytes as big endian.

public static short ReadInt16LittleEndian(ReadOnlySpan<byte> source)

Reads an Int16 out of a read-only span of bytes as little endian.

public static int ReadInt32BigEndian(ReadOnlySpan<byte> source)

Reads an Int32 out of a read-only span of bytes as big endian.

public static int ReadInt32LittleEndian(ReadOnlySpan<byte> source)

Reads an Int32 out of a read-only span of bytes as little endian.

public static long ReadInt64BigEndian(ReadOnlySpan<byte> source)

Reads an Int64 out of a read-only span of bytes as big endian.

public static long ReadInt64LittleEndian(ReadOnlySpan<byte> source)

Reads an Int64 out of a read-only span of bytes as little endian.

public static ushort ReadUInt16BigEndian(ReadOnlySpan<byte> source)

Reads a UInt16 out of a read-only span of bytes as big endian.

public static ushort ReadUInt16LittleEndian(ReadOnlySpan<byte> source)

Reads a UInt16 out of a read-only span of bytes as little endian.

public static uint ReadUInt32BigEndian(ReadOnlySpan<byte> source)

Reads a UInt32 out of a read-only span of bytes as big endian.

public static uint ReadUInt32LittleEndian(ReadOnlySpan<byte> source)

Reads a UInt32 out of a read-only span of bytes as little endian.

public static ulong ReadUInt64BigEndian(ReadOnlySpan<byte> source)

Reads a UInt64 out of a read-only span of bytes as big endian.

public static ulong ReadUInt64LittleEndian(ReadOnlySpan<byte> source)

Reads a UInt64 out of a read-only span of bytes as little endian.

public static sbyte ReverseEndianness(sbyte value)

This is a no-op and added only for consistency. This allows the caller to read a struct of numeric primitives and reverse each field rather than having to skip sbyte fields.

public static short ReverseEndianness(short value)

Reverses a primitive value - performs an endianness swap

public static int ReverseEndianness(int value)

Reverses a primitive value - performs an endianness swap

public static long ReverseEndianness(long value)

Reverses a primitive value - performs an endianness swap

public static byte ReverseEndianness(byte value)

This is a no-op and added only for consistency. This allows the caller to read a struct of numeric primitives and reverse each field rather than having to skip byte fields.

public static ushort ReverseEndianness(ushort value)

Reverses a primitive value - performs an endianness swap

public static uint ReverseEndianness(uint value)

Reverses a primitive value - performs an endianness swap

public static ulong ReverseEndianness(ulong value)

Reverses a primitive value - performs an endianness swap

public static bool TryReadInt16BigEndian(ReadOnlySpan<byte> source, out short value)

Reads an Int16 out of a read-only span of bytes as big endian. If the span is too small to contain an Int16, return false.

public static bool TryReadInt16LittleEndian(ReadOnlySpan<byte> source, out short value)

Reads an Int16 out of a read-only span of bytes as little endian. If the span is too small to contain an Int16, return false.

public static bool TryReadInt32BigEndian(ReadOnlySpan<byte> source, out int value)

Reads an Int32 out of a read-only span of bytes as big endian. If the span is too small to contain an Int32, return false.

public static bool TryReadInt32LittleEndian(ReadOnlySpan<byte> source, out int value)

Reads an Int32 out of a read-only span of bytes as little endian. If the span is too small to contain an Int32, return false.

public static bool TryReadInt64BigEndian(ReadOnlySpan<byte> source, out long value)

Reads an Int64 out of a read-only span of bytes as big endian. If the span is too small to contain an Int64, return false.

public static bool TryReadInt64LittleEndian(ReadOnlySpan<byte> source, out long value)

Reads an Int64 out of a read-only span of bytes as little endian. If the span is too small to contain an Int64, return false.

public static bool TryReadUInt16BigEndian(ReadOnlySpan<byte> source, out ushort value)

Reads a UInt16 out of a read-only span of bytes as big endian. If the span is too small to contain a UInt16, return false.

public static bool TryReadUInt16LittleEndian(ReadOnlySpan<byte> source, out ushort value)

Reads a UInt16 out of a read-only span of bytes as little endian. If the span is too small to contain a UInt16, return false.

public static bool TryReadUInt32BigEndian(ReadOnlySpan<byte> source, out uint value)

Reads a UInt32 out of a read-only span of bytes as big endian. If the span is too small to contain a UInt32, return false.

public static bool TryReadUInt32LittleEndian(ReadOnlySpan<byte> source, out uint value)

Reads a UInt32 out of a read-only span of bytes as little endian. If the span is too small to contain a UInt32, return false.

public static bool TryReadUInt64BigEndian(ReadOnlySpan<byte> source, out ulong value)

Reads a UInt64 out of a read-only span of bytes as big endian. If the span is too small to contain a UInt64, return false.

public static bool TryReadUInt64LittleEndian(ReadOnlySpan<byte> source, out ulong value)

Reads a UInt64 out of a read-only span of bytes as little endian. If the span is too small to contain a UInt64, return false.

public static bool TryWriteInt16BigEndian(Span<byte> destination, short value)

Writes an Int16 into a span of bytes as big endian. If the span is too small to contain the value, return false.

public static bool TryWriteInt16LittleEndian(Span<byte> destination, short value)

Writes an Int16 into a span of bytes as little endian. If the span is too small to contain the value, return false.

public static bool TryWriteInt32BigEndian(Span<byte> destination, int value)

Writes an Int32 into a span of bytes as big endian. If the span is too small to contain the value, return false.

public static bool TryWriteInt32LittleEndian(Span<byte> destination, int value)

Writes an Int32 into a span of bytes as little endian. If the span is too small to contain the value, return false.

public static bool TryWriteInt64BigEndian(Span<byte> destination, long value)

Writes an Int64 into a span of bytes as big endian. If the span is too small to contain the value, return false.

public static bool TryWriteInt64LittleEndian(Span<byte> destination, long value)

Writes an Int64 into a span of bytes as little endian. If the span is too small to contain the value, return false.

public static bool TryWriteUInt16BigEndian(Span<byte> destination, ushort value)

Write a UInt16 into a span of bytes as big endian. If the span is too small to contain the value, return false.

public static bool TryWriteUInt16LittleEndian(Span<byte> destination, ushort value)

Write a UInt16 into a span of bytes as little endian. If the span is too small to contain the value, return false.

public static bool TryWriteUInt32BigEndian(Span<byte> destination, uint value)

Write a UInt32 into a span of bytes as big endian. If the span is too small to contain the value, return false.

public static bool TryWriteUInt32LittleEndian(Span<byte> destination, uint value)

Write a UInt32 into a span of bytes as little endian. If the span is too small to contain the value, return false.

public static bool TryWriteUInt64BigEndian(Span<byte> destination, ulong value)

Write a UInt64 into a span of bytes as big endian. If the span is too small to contain the value, return false.

public static bool TryWriteUInt64LittleEndian(Span<byte> destination, ulong value)

Write a UInt64 into a span of bytes as little endian. If the span is too small to contain the value, return false.

public static void WriteInt16BigEndian(Span<byte> destination, short value)

Writes an Int16 into a span of bytes as big endian.

public static void WriteInt16LittleEndian(Span<byte> destination, short value)

Writes an Int16 into a span of bytes as little endian.

public static void WriteInt32BigEndian(Span<byte> destination, int value)

Writes an Int32 into a span of bytes as big endian.

public static void WriteInt32LittleEndian(Span<byte> destination, int value)

Writes an Int32 into a span of bytes as little endian.

public static void WriteInt64BigEndian(Span<byte> destination, long value)

Writes an Int64 into a span of bytes as big endian.

public static void WriteInt64LittleEndian(Span<byte> destination, long value)

Writes an Int64 into a span of bytes as little endian.

public static void WriteUInt16BigEndian(Span<byte> destination, ushort value)

Write a UInt16 into a span of bytes as big endian.

public static void WriteUInt16LittleEndian(Span<byte> destination, ushort value)

Write a UInt16 into a span of bytes as little endian.

public static void WriteUInt32BigEndian(Span<byte> destination, uint value)

Write a UInt32 into a span of bytes as big endian.

public static void WriteUInt32LittleEndian(Span<byte> destination, uint value)

Write a UInt32 into a span of bytes as little endian.

public static void WriteUInt64BigEndian(Span<byte> destination, ulong value)

Write a UInt64 into a span of bytes as big endian.

public static void WriteUInt64LittleEndian(Span<byte> destination, ulong value)

Write a UInt64 into a span of bytes as little endian.