SpanExtensions
Provides extension methods for reading from and writing to spans.
Métodos
public static bool ReadBoolean(ReadOnlySpan<byte> span, int position)
result = SpanExtensions.ReadBoolean(span, position)
Reads a boolean value from the specified read-only span at the current position.
- span
- The read-only span of bytes.
- position
- The position to read from; will be advanced by the size of a boolean.
Retorna: The boolean value read.
public static byte ReadByte(ReadOnlySpan<byte> span, int position)
result = SpanExtensions.ReadByte(span, position)
Reads a byte from the specified read-only span at the current position.
- span
- The read-only span of bytes.
- position
- The position to read from; will be advanced by 1.
Retorna: The byte value read.
public static char ReadChar(ReadOnlySpan<byte> span, int position)
result = SpanExtensions.ReadChar(span, position)
Reads a Unicode character from the specified read-only span at the current position.
- span
- The read-only span of bytes.
- position
- The position to read from; will be advanced by the size of a char.
Retorna: The char value read.
public static decimal ReadDecimal(ReadOnlySpan<byte> span, bool isBigEndian, int position)
result = SpanExtensions.ReadDecimal(span, isBigEndian, position)
Reads a decimal value from the specified read-only span at the current position.
- span
- The read-only span of bytes.
- isBigEndian
- If true, reads in big-endian order; otherwise, little-endian.
- position
- The position to read from; will be advanced by 16 bytes.
Retorna: The decimal value read.
public static double ReadDouble(ReadOnlySpan<byte> span, bool isBigEndian, int position)
result = SpanExtensions.ReadDouble(span, isBigEndian, position)
Reads a double-precision floating-point number from the specified read-only span at the current position.
- span
- The read-only span of bytes.
- isBigEndian
- If true, reads in big-endian order; otherwise, little-endian.
- position
- The position to read from; will be advanced by the size of a double.
Retorna: The double value read.
public static Guid ReadGuid(ReadOnlySpan<byte> span, int position)
result = SpanExtensions.ReadGuid(span, position)
Reads a GUID from the specified read-only span at the current position.
- span
- The read-only span of bytes.
- position
- The position to read from; will be advanced by 16 bytes.
Retorna: The GUID read.
public static Half ReadHalf(ReadOnlySpan<byte> span, bool isBigEndian, int position)
result = SpanExtensions.ReadHalf(span, isBigEndian, position)
Reads a half-precision floating-point number from the specified read-only span at the current position.
- span
- The read-only span of bytes.
- isBigEndian
- If true, reads in big-endian order; otherwise, little-endian.
- position
- The position to read from; will be advanced by the size of a Half.
Retorna: The Half value read.
public static short ReadInt16(ReadOnlySpan<byte> span, bool isBigEndian, int position)
result = SpanExtensions.ReadInt16(span, isBigEndian, position)
Reads a 16-bit signed integer from the specified read-only span at the current position.
- span
- The read-only span of bytes.
- isBigEndian
- If true, reads in big-endian order; otherwise, little-endian.
- position
- The position to read from; will be advanced by 2.
Retorna: The 16-bit signed integer read.
public static int ReadInt32(ReadOnlySpan<byte> span, bool isBigEndian, int position)
result = SpanExtensions.ReadInt32(span, isBigEndian, position)
Reads a 32-bit signed integer from the specified read-only span at the current position.
- span
- The read-only span of bytes.
- isBigEndian
- If true, reads in big-endian order; otherwise, little-endian.
- position
- The position to read from; will be advanced by 4.
Retorna: The 32-bit signed integer read.
public static long ReadInt64(ReadOnlySpan<byte> span, bool isBigEndian, int position)
result = SpanExtensions.ReadInt64(span, isBigEndian, position)
Reads a 64-bit signed integer from the specified read-only span at the current position.
- span
- The read-only span of bytes.
- isBigEndian
- If true, reads in big-endian order; otherwise, little-endian.
- position
- The position to read from; will be advanced by 8.
Retorna: The 64-bit signed integer read.
public static sbyte ReadSByte(ReadOnlySpan<byte> span, int position)
result = SpanExtensions.ReadSByte(span, position)
Reads a signed byte from the specified read-only span at the current position.
- span
- The read-only span of bytes.
- position
- The position to read from; will be advanced by 1.
Retorna: The sbyte value read.
public static float ReadSingle(ReadOnlySpan<byte> span, bool isBigEndian, int position)
result = SpanExtensions.ReadSingle(span, isBigEndian, position)
Reads a single-precision floating-point number from the specified read-only span at the current position.
- span
- The read-only span of bytes.
- isBigEndian
- If true, reads in big-endian order; otherwise, little-endian.
- position
- The position to read from; will be advanced by the size of a float.
Retorna: The float value read.
public static void ReadStructArray<T>(ReadOnlySpan<byte> span, T[] array, int elementSize, int count, int position)
SpanExtensions.ReadStructArray(span, array, elementSize, count, position)
Reads an array of structures of type from the specified read-only span at the current position.
- span
- The read-only span of bytes.
- array
- An array of structures read from the span.
- elementSize
- The size of each structure in bytes.
- count
- The number of elements to read.
- position
- The position to read from; will be advanced by the total size of the array.
public static T ReadStruct<T>(ReadOnlySpan<byte> span, int size, int position)
result = SpanExtensions.ReadStruct(span, size, position)
Reads a structure of type from the specified read-only span at the current position.
- span
- The read-only span of bytes.
- size
- The size of the structure in bytes. This parameter is used to determine how many bytes to read.
- position
- The position to read from; will be advanced by the size of the structure.
Retorna: The structure read from the span.
public static ushort ReadUInt16(ReadOnlySpan<byte> span, bool isBigEndian, int position)
result = SpanExtensions.ReadUInt16(span, isBigEndian, position)
Reads a 16-bit unsigned integer from the specified read-only span at the current position.
- span
- The read-only span of bytes.
- isBigEndian
- If true, reads in big-endian order; otherwise, little-endian.
- position
- The position to read from; will be advanced by 2.
Retorna: The 16-bit unsigned integer read.
public static uint ReadUInt32(ReadOnlySpan<byte> span, bool isBigEndian, int position)
result = SpanExtensions.ReadUInt32(span, isBigEndian, position)
Reads a 32-bit unsigned integer from the specified read-only span at the current position.
- span
- The read-only span of bytes.
- isBigEndian
- If true, reads in big-endian order; otherwise, little-endian.
- position
- The position to read from; will be advanced by 4.
Retorna: The 32-bit unsigned integer read.
public static ulong ReadUInt64(ReadOnlySpan<byte> span, bool isBigEndian, int position)
result = SpanExtensions.ReadUInt64(span, isBigEndian, position)
Reads a 64-bit unsigned integer from the specified read-only span at the current position.
- span
- The read-only span of bytes.
- isBigEndian
- If true, reads in big-endian order; otherwise, little-endian.
- position
- The position to read from; will be advanced by 8.
Retorna: The 64-bit unsigned integer read.
public static void WriteBoolean(Span<byte> span, bool value, int position)
SpanExtensions.WriteBoolean(span, value, position)
Writes a boolean value to the specified span at the current position.
- span
- The span of bytes.
- value
- The boolean value to write.
- position
- The position to write to; will be advanced by the size of a boolean.
public static void WriteByte(Span<byte> span, byte value, int position)
SpanExtensions.WriteByte(span, value, position)
Writes a byte to the specified span at the current position.
- span
- The span of bytes.
- value
- The byte value to write.
- position
- The position to write to; will be advanced by 1.
public static void WriteChar(Span<byte> span, char value, int position)
SpanExtensions.WriteChar(span, value, position)
Writes a Unicode character to the specified span at the current position.
- span
- The span of bytes.
- value
- The char value to write.
- position
- The position to write to; will be advanced by the size of a char.
public static void WriteDecimal(Span<byte> span, decimal value, bool isBigEndian, int position)
SpanExtensions.WriteDecimal(span, value, isBigEndian, position)
Writes a decimal value to the specified span at the current position.
- span
- The span of bytes.
- value
- The decimal value to write.
- isBigEndian
- If true, writes in big-endian order; otherwise, little-endian.
- position
- The position to write to; will be advanced by 16 bytes.
public static void WriteDouble(Span<byte> span, double value, bool isBigEndian, int position)
SpanExtensions.WriteDouble(span, value, isBigEndian, position)
Writes a double-precision floating-point number to the specified span at the current position.
- span
- The span of bytes.
- value
- The double value to write.
- isBigEndian
- If true, writes in big-endian order; otherwise, little-endian.
- position
- The position to write to; will be advanced by the size of a double.
public static void WriteGuid(Span<byte> span, Guid value, int position)
SpanExtensions.WriteGuid(span, value, position)
Writes a GUID to the specified span at the current position.
- span
- The span of bytes.
- value
- The GUID value to write.
- position
- The position to write to; will be advanced by 16 bytes.
public static void WriteHalf(Span<byte> span, Half value, bool isBigEndian, int position)
SpanExtensions.WriteHalf(span, value, isBigEndian, position)
Writes a half-precision floating-point number to the specified span at the current position.
- span
- The span of bytes.
- value
- The Half value to write.
- isBigEndian
- If true, writes in big-endian order; otherwise, little-endian.
- position
- The position to write to; will be advanced by the size of a Half.
public static void WriteInt16(Span<byte> span, short value, bool isBigEndian, int position)
SpanExtensions.WriteInt16(span, value, isBigEndian, position)
Writes a 16-bit signed integer to the specified span at the current position.
- span
- The span of bytes.
- value
- The 16-bit signed integer value to write.
- isBigEndian
- If true, writes in big-endian order; otherwise, little-endian.
- position
- The position to write to; will be advanced by 2.
public static void WriteInt32(Span<byte> span, int value, bool isBigEndian, int position)
SpanExtensions.WriteInt32(span, value, isBigEndian, position)
Writes a 32-bit signed integer to the specified span at the current position.
- span
- The span of bytes.
- value
- The 32-bit signed integer value to write.
- isBigEndian
- If true, writes in big-endian order; otherwise, little-endian.
- position
- The position to write to; will be advanced by 4.
public static void WriteInt64(Span<byte> span, long value, bool isBigEndian, int position)
SpanExtensions.WriteInt64(span, value, isBigEndian, position)
Writes a 64-bit signed integer to the specified span at the current position.
- span
- The span of bytes.
- value
- The 64-bit signed integer value to write.
- isBigEndian
- If true, writes in big-endian order; otherwise, little-endian.
- position
- The position to write to; will be advanced by 8.
public static void WriteSByte(Span<byte> span, sbyte value, int position)
SpanExtensions.WriteSByte(span, value, position)
Writes a signed byte to the specified span at the current position.
- span
- The span of bytes.
- value
- The sbyte value to write.
- position
- The position to write to; will be advanced by 1.
public static void WriteSingle(Span<byte> span, float value, bool isBigEndian, int position)
SpanExtensions.WriteSingle(span, value, isBigEndian, position)
Writes a single-precision floating-point number to the specified span at the current position.
- span
- The span of bytes.
- value
- The float value to write.
- isBigEndian
- If true, writes in big-endian order; otherwise, little-endian.
- position
- The position to write to; will be advanced by the size of a float.
public static void WriteStructArray<T>(Span<byte> span, T[] array, int elementSize, int position)
SpanExtensions.WriteStructArray(span, array, elementSize, position)
Writes an array of structures of type to the specified span at the current position.
- span
- The span of bytes.
- array
- The array of structures to write.
- elementSize
- The structure size in bytes. This parameter is used to determine how many bytes to write.
- position
- The position to write to; will be advanced by the total size of the array.
public static void WriteStruct<T>(Span<byte> span, T value, int size, int position)
SpanExtensions.WriteStruct(span, value, size, position)
Writes a structure of type to the specified span at the current position.
- span
- The span of bytes.
- value
- The structure value to write.
- size
- The structure size in bytes. This parameter is used to determine how many bytes to write.
- position
- The position to write to; will be advanced by the size of the structure.
public static void WriteUInt16(Span<byte> span, ushort value, bool isBigEndian, int position)
SpanExtensions.WriteUInt16(span, value, isBigEndian, position)
Writes a 16-bit unsigned integer to the specified span at the current position.
- span
- The span of bytes.
- value
- The 16-bit unsigned integer value to write.
- isBigEndian
- If true, writes in big-endian order; otherwise, little-endian.
- position
- The position to write to; will be advanced by 2.
public static void WriteUInt32(Span<byte> span, uint value, bool isBigEndian, int position)
SpanExtensions.WriteUInt32(span, value, isBigEndian, position)
Writes a 32-bit unsigned integer to the specified span at the current position.
- span
- The span of bytes.
- value
- The 32-bit unsigned integer value to write.
- isBigEndian
- If true, writes in big-endian order; otherwise, little-endian.
- position
- The position to write to; will be advanced by 4.
public static void WriteUInt64(Span<byte> span, ulong value, bool isBigEndian, int position)
SpanExtensions.WriteUInt64(span, value, isBigEndian, position)
Writes a 64-bit unsigned integer to the specified span at the current position.
- span
- The span of bytes.
- value
- The 64-bit unsigned integer value to write.
- isBigEndian
- If true, writes in big-endian order; otherwise, little-endian.
- position
- The position to write to; will be advanced by 8.