struct
ByteStream
public sealed struct ByteStream Write and read bytes to a stream. This aims to be as allocation free as possible while also being as fast as possible.
Properties
| Name | Type | Description |
|---|---|---|
Writable | Boolean | Is this stream writable? |
Position | Int32 | The current read or write position. Values are clamped to valid range. |
Length | Int32 | The total size of the data |
ReadRemaining | Int32 |
Methods
static ByteStream Create(Int32 size) Create a writable byte stream
static ByteStream CreateReader(ReadOnlySpan<Byte> data) Void Dispose() Void EnsureCanWrite(Int32 size) Ensures buffer can accommodate write with overflow protection
Void EnsureCanRead(Int32 size) Validates read bounds with overflow protection
Void WriteArray(ReadOnlySpan<T> arr) Void WriteArray(T[] arr, Boolean includeCount = True) Writes an array of unmanaged types
Void Write(ByteStream stream) Void Write(Byte[] rawData) Void Write(Byte[] rawData, Int32 offset, Int32 bytes) Void Write(ByteStream stream, Int32 offset, Int32 maxSize) Void Write(String str) Writes a string
Byte[] ToArray() Get the data as an array of bytes
Void Write(T value) Writes an unmanaged type
T Read() Reads an unmanaged type
Boolean TryRead(T v) Try to read variable, return false if not enough data
T[] ReadArray(Int32 maxElements = 1073741823) Returns an array of unmanaged types
String Read(String defaultValue = ) Void Write(T data, Boolean unused = False) T Read(T defaultValue = null, Boolean unused = False) Object ReadObject(Type objectType) Int32 Read(Byte[] buffer, Int32 offset, Int32 count) Int32 Read(Span<Byte> buffer) ByteStream Compress(CompressionLevel compressionLevel = 0) ByteStream Decompress()