SpanReader

Ecng.Serialization

A ref struct that reads primitive types from a span of bytes.

构造函数

SpanReader
public SpanReader(ReadOnlySpan<byte> span, bool isBigEndian, bool allowNegativeShift)
spanReader = SpanReader(span, isBigEndian, allowNegativeShift)

Initializes a new instance of the SpanReader struct.

span
The span of bytes to read from.
isBigEndian
If true, reads in big-endian order; otherwise, little-endian.
allowNegativeShift
If true, allows negative Skip to move position backward.
SpanReader
public SpanReader(Memory<byte> memory, bool isBigEndian, bool allowNegativeShift)
spanReader = SpanReader(memory, isBigEndian, allowNegativeShift)

Initializes a new instance of the SpanReader struct.

memory
The memory of bytes to read from.
isBigEndian
If true, reads in big-endian order; otherwise, little-endian.
allowNegativeShift
If true, allows negative Skip to move position backward.
SpanReader
public SpanReader(byte[] buffer, bool isBigEndian, bool allowNegativeShift)
spanReader = SpanReader(buffer, isBigEndian, allowNegativeShift)

Initializes a new instance of the SpanReader struct.

buffer
The array of bytes to read from.
isBigEndian
If true, reads in big-endian order; otherwise, little-endian.
allowNegativeShift
If true, allows negative Skip to move position backward.

属性

End
public bool End { get; }
value = spanReader.End

Gets a value indicating whether the reader has reached the end of the span.

Position
public int Position { get; }
value = spanReader.Position

Gets the current position in the span.

Remaining
public int Remaining { get; }
value = spanReader.Remaining

Gets the number of bytes remaining to be read.

方法

ReadBoolean
public bool ReadBoolean()
result = spanReader.ReadBoolean()

Reads a boolean value from the current position and advances the position by 1 byte.

返回值: The boolean value at the current position.

ReadByte
public byte ReadByte()
result = spanReader.ReadByte()

Reads a byte from the current position and advances the position by 1 byte.

返回值: The byte at the current position.

ReadChar
public char ReadChar()
result = spanReader.ReadChar()

Reads a character from the current position and advances the position.

返回值: The character at the current position.

ReadDateTime
public DateTime ReadDateTime()
result = spanReader.ReadDateTime()

Reads a DateTime value from the current position and advances the position.

返回值: The DateTime value at the current position.

ReadDecimal
public decimal ReadDecimal()
result = spanReader.ReadDecimal()

Reads a decimal value from the current position and advances the position by 16 bytes.

返回值: The decimal value at the current position.

ReadDouble
public double ReadDouble()
result = spanReader.ReadDouble()

Reads a double-precision floating-point value from the current position and advances the position by 8 bytes.

返回值: The double-precision floating-point value at the current position.

ReadGuid
public Guid ReadGuid()
result = spanReader.ReadGuid()

Reads a GUID value from the current position and advances the position by 16 bytes.

返回值: The GUID value at the current position.

ReadHalf
public Half ReadHalf()
result = spanReader.ReadHalf()

Reads a half-precision floating-point value from the current position and advances the position by 2 bytes.

返回值: The half-precision floating-point value at the current position.

ReadInt16
public short ReadInt16()
result = spanReader.ReadInt16()

Reads a 16-bit integer from the current position and advances the position by 2 bytes.

返回值: The 16-bit integer at the current position.

ReadInt32
public int ReadInt32()
result = spanReader.ReadInt32()

Reads a 32-bit integer from the current position and advances the position by 4 bytes.

返回值: The 32-bit integer at the current position.

ReadInt64
public long ReadInt64()
result = spanReader.ReadInt64()

Reads a 64-bit integer from the current position and advances the position by 8 bytes.

返回值: The 64-bit integer at the current position.

ReadSByte
public sbyte ReadSByte()
result = spanReader.ReadSByte()

Reads a signed byte from the current position and advances the position by 1 byte.

返回值: The signed byte at the current position.

ReadSingle
public float ReadSingle()
result = spanReader.ReadSingle()

Reads a single-precision floating-point value from the current position and advances the position by 4 bytes.

返回值: The single-precision floating-point value at the current position.

ReadSpan
public ReadOnlySpan<byte> ReadSpan(int length)
result = spanReader.ReadSpan(length)

Reads a span of bytes of the specified length from the current position and advances the position.

length
The number of bytes to read.

返回值: A span containing the bytes read from the current position.

ReadString
public string ReadString(int length, Encoding encoding)
result = spanReader.ReadString(length, encoding)

Reads a string from the current position and advances the position.

length
The length of the string in bytes. The length must be a multiple of the character size.
encoding
The encoding to use for the string. This parameter cannot be null.

返回值: The string at the current position.

ReadStructArray``1
public void ReadStructArray<T>(T[] array, int elementSize, int count)
spanReader.ReadStructArray(array, elementSize, count)

Reads an array of structures of type from the current position and advances the position.

array
An array containing the structures of type read from the current position.
elementSize
The size of each structure in bytes.
count
The number of structures to read.
ReadStruct``1
public T ReadStruct<T>(int size)
result = spanReader.ReadStruct(size)

Reads a structure of type from the current position and advances the position by the size of T.

返回值: The structure of type at the current position.

ReadTimeSpan
public TimeSpan ReadTimeSpan()
result = spanReader.ReadTimeSpan()

Reads a TimeSpan value from the current position and advances the position.

返回值: The TimeSpan value at the current position.

ReadUInt16
public ushort ReadUInt16()
result = spanReader.ReadUInt16()

Reads an unsigned 16-bit integer from the current position and advances the position by 2 bytes.

返回值: The unsigned 16-bit integer at the current position.

ReadUInt32
public uint ReadUInt32()
result = spanReader.ReadUInt32()

Reads an unsigned 32-bit integer from the current position and advances the position by 4 bytes.

返回值: The unsigned 32-bit integer at the current position.

ReadUInt64
public ulong ReadUInt64()
result = spanReader.ReadUInt64()

Reads an unsigned 64-bit integer from the current position and advances the position by 8 bytes.

返回值: The unsigned 64-bit integer at the current position.

Skip
public void Skip(int count)
spanReader.Skip(count)

Skips a specified number of bytes from the current position.

count
The number of bytes to skip. Must be non-negative.