SpanWriter

Ecng.Serialization

Provides functionality for writing primitive data types to a span of bytes.

Construtores

SpanWriter
public SpanWriter(byte[] buffer, bool isBigEndian, bool allowNegativeShift)
spanWriter = SpanWriter(buffer, isBigEndian, allowNegativeShift)

Initializes a new instance of the SpanWriter struct.

buffer
The array to write data to.
isBigEndian
If true, reads in big-endian order; otherwise, little-endian.
allowNegativeShift
If true, allows negative Skip to move position backward.
SpanWriter
public SpanWriter(Memory<byte> memory, bool isBigEndian, bool allowNegativeShift)
spanWriter = SpanWriter(memory, isBigEndian, allowNegativeShift)

Initializes a new instance of the SpanWriter struct.

memory
The memory to write data to.
isBigEndian
If true, reads in big-endian order; otherwise, little-endian.
allowNegativeShift
If true, allows negative Skip to move position backward.
SpanWriter
public SpanWriter(Span<byte> span, bool isBigEndian, bool allowNegativeShift)
spanWriter = SpanWriter(span, isBigEndian, allowNegativeShift)

Initializes a new instance of the SpanWriter struct with the specified span.

span
The span to write data to.
isBigEndian
If true, writes in big-endian order; otherwise, little-endian.
allowNegativeShift
If true, allows negative Skip to move position backward.

Propriedades

IsFull
public bool IsFull { get; }
value = spanWriter.IsFull

Gets a value indicating whether the span is full and no more data can be written.

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

Gets the current position within the span.

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

Gets the number of bytes remaining in the span.

Métodos

GetWrittenSpan
public ReadOnlySpan<byte> GetWrittenSpan()
result = spanWriter.GetWrittenSpan()

Gets a ReadOnlySpan containing the data written so far.

Retorna: A ReadOnlySpan containing the written data.

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

Advances the position by the specified count without writing any data.

count
The number of bytes to skip.
WriteBoolean
public void WriteBoolean(bool value)
spanWriter.WriteBoolean(value)

Writes a boolean value to the span at the current position and advances the position.

value
The boolean value to write.
WriteByte
public void WriteByte(byte value)
spanWriter.WriteByte(value)

Writes a byte value to the span at the current position and advances the position.

value
The byte value to write.
WriteChar
public void WriteChar(char value)
spanWriter.WriteChar(value)

Writes a character value to the span at the current position and advances the position.

value
The character value to write.
WriteDateTime
public void WriteDateTime(DateTime value)
spanWriter.WriteDateTime(value)

Writes a DateTime value to the span at the current position and advances the position.

value
The DateTime value to write.
WriteDecimal
public void WriteDecimal(decimal value)
spanWriter.WriteDecimal(value)

Writes a decimal value to the span at the current position and advances the position.

value
The decimal value to write.
WriteDouble
public void WriteDouble(double value)
spanWriter.WriteDouble(value)

Writes a double-precision floating-point value to the span at the current position and advances the position.

value
The double-precision floating-point value to write.
WriteGuid
public void WriteGuid(Guid value)
spanWriter.WriteGuid(value)

Writes a GUID value to the span at the current position and advances the position.

value
The GUID value to write.
WriteHalf
public void WriteHalf(Half value)
spanWriter.WriteHalf(value)

Writes a Half value to the span at the current position and advances the position.

value
The Half value to write.
WriteInt16
public void WriteInt16(short value)
spanWriter.WriteInt16(value)

Writes a 16-bit integer value to the span at the current position and advances the position.

value
The 16-bit integer value to write.
WriteInt32
public void WriteInt32(int value)
spanWriter.WriteInt32(value)

Writes a 32-bit integer value to the span at the current position and advances the position.

value
The 32-bit integer value to write.
WriteInt64
public void WriteInt64(long value)
spanWriter.WriteInt64(value)

Writes a 64-bit integer value to the span at the current position and advances the position.

value
The 64-bit integer value to write.
WriteSByte
public void WriteSByte(sbyte value)
spanWriter.WriteSByte(value)

Writes a signed byte value to the span at the current position and advances the position.

value
The signed byte value to write.
WriteSingle
public void WriteSingle(float value)
spanWriter.WriteSingle(value)

Writes a single-precision floating-point value to the span at the current position and advances the position.

value
The single-precision floating-point value to write.
WriteSpan
public void WriteSpan(ReadOnlySpan<byte> source)
spanWriter.WriteSpan(source)

Copies the contents of the source span to the destination span at the current position and advances the position.

source
The source span containing the data to write.
WriteString
public void WriteString(string value, Encoding encoding)
spanWriter.WriteString(value, encoding)

Writes a string value to the span at the current position and advances the position.

value
The string value to write.
encoding
The encoding to use for the string. This parameter cannot be null.
WriteStructArray``1
public void WriteStructArray<T>(T[] array, int elementSize)
spanWriter.WriteStructArray(array, elementSize)

Writes an array of value type structures to the span at the current position and advances the position.

array
The array of structures to write.
elementSize
The structure size in bytes. This parameter is used to determine how many bytes to write.
WriteStruct``1
public void WriteStruct<T>(T value, int size)
spanWriter.WriteStruct(value, size)

Writes a value type structure to the span at the current position and advances the position.

value
The structure to write.
size
The structure size in bytes. This parameter is used to determine how many bytes to write.
WriteTimeSpan
public void WriteTimeSpan(TimeSpan value)
spanWriter.WriteTimeSpan(value)

Writes a TimeSpan value to the span at the current position and advances the position.

value
The TimeSpan value to write.
WriteUInt16
public void WriteUInt16(ushort value)
spanWriter.WriteUInt16(value)

Writes an unsigned 16-bit integer value to the span at the current position and advances the position.

value
The unsigned 16-bit integer value to write.
WriteUInt32
public void WriteUInt32(uint value)
spanWriter.WriteUInt32(value)

Writes an unsigned 32-bit integer value to the span at the current position and advances the position.

value
The unsigned 32-bit integer value to write.
WriteUInt64
public void WriteUInt64(ulong value)
spanWriter.WriteUInt64(value)

Writes an unsigned 64-bit integer value to the span at the current position and advances the position.

value
The unsigned 64-bit integer value to write.