SpanExtensions

Ecng.Serialization

Provides extension methods for reading from and writing to spans.

Métodos

ReadBoolean
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.

Devuelve: The boolean value read.

ReadByte
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.

Devuelve: The byte value read.

ReadChar
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.

Devuelve: The char value read.

ReadDecimal
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.

Devuelve: The decimal value read.

ReadDouble
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.

Devuelve: The double value read.

ReadGuid
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.

Devuelve: The GUID read.

ReadHalf
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.

Devuelve: The Half value read.

ReadInt16
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.

Devuelve: The 16-bit signed integer read.

ReadInt32
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.

Devuelve: The 32-bit signed integer read.

ReadInt64
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.

Devuelve: The 64-bit signed integer read.

ReadSByte
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.

Devuelve: The sbyte value read.

ReadSingle
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.

Devuelve: The float value read.

ReadStructArray``1
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.
ReadStruct``1
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.

Devuelve: The structure read from the span.

ReadUInt16
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.

Devuelve: The 16-bit unsigned integer read.

ReadUInt32
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.

Devuelve: The 32-bit unsigned integer read.

ReadUInt64
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.

Devuelve: The 64-bit unsigned integer read.

WriteBoolean
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.
WriteByte
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.
WriteChar
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.
WriteDecimal
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.
WriteDouble
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.
WriteGuid
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.
WriteHalf
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.
WriteInt16
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.
WriteInt32
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.
WriteInt64
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.
WriteSByte
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.
WriteSingle
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.
WriteStructArray``1
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.
WriteStruct``1
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.
WriteUInt16
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.
WriteUInt32
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.
WriteUInt64
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.