SpanWriter
Provides functionality for writing primitive data types to a span of bytes.
コンストラクター
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.
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.
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.
プロパティ
public bool IsFull { get; }
value = spanWriter.IsFull
Gets a value indicating whether the span is full and no more data can be written.
public int Position { get; }
value = spanWriter.Position
Gets the current position within the span.
public int Remaining { get; }
value = spanWriter.Remaining
Gets the number of bytes remaining in the span.
メソッド
public ReadOnlySpan<byte> GetWrittenSpan()
result = spanWriter.GetWrittenSpan()
Gets a ReadOnlySpan containing the data written so far.
戻り値: A ReadOnlySpan containing the written data.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.