ByteStreamclass

Write and read bytes to a stream. This aims to be as allocation free as possible while also being as fast as possible.

object→ByteStream
Namespace
Sandbox
Assembly
Sandbox.System
Declaration
public sealed struct Sandbox.ByteStream

Methods25

Showing 25 methods

public Sandbox.ByteStream Compress(System.IO.Compression.CompressionLevel compressionLevel = 0)PUBLIC

ParameterTypeDescription
compressionLevel = 0CompressionLevel—
Returns:ByteStream—

public static Sandbox.ByteStream Create(int size)PUBLICSTATIC

Create a writable byte stream

ParameterTypeDescription
sizeint—
Returns:ByteStream—

public static Sandbox.ByteStream CreateReader(System.ReadOnlySpan`1<byte> data)PUBLICSTATIC

ParameterTypeDescription
dataReadOnlySpan<byte>—
Returns:ByteStream—

public void Dispose()PUBLIC

Returns:void—

public void EnsureCanRead(int size)PUBLIC

Validates read bounds with overflow protection

ParameterTypeDescription
sizeint—
Returns:void—

public void EnsureCanWrite(int size)PUBLIC

Ensures buffer can accommodate write with overflow protection

ParameterTypeDescription
sizeint—
Returns:void—

public T[] ReadArray(int maxElements = 1073741823)PUBLIC

Returns an array of unmanaged types

ParameterTypeDescription
maxElements = 1073741823int—
Returns:T[]—

public object ReadObject(System.Type objectType)PUBLIC

ParameterTypeDescription
objectTypeType—
Returns:object—

public byte[] ToArray()PUBLIC

Get the data as an array of bytes

Returns:byte[]—

public bool TryRead(T v)PUBLIC

Try to read variable, return false if not enough data

ParameterTypeDescription
vT—
Returns:bool—

Properties4

Showing 4 properties

public int Sandbox.ByteStream.Length { get; set; }PUBLICGETSET

The total size of the data

Returns:int—

public int Sandbox.ByteStream.Position { get; set; }PUBLICGETSET

The current read or write position. Values are clamped to valid range.

Returns:int—

public int Sandbox.ByteStream.ReadRemaining { get; set; }PUBLICGETSET

Returns:int—

public bool Sandbox.ByteStream.Writable { get; set; }PUBLICGETSET

Is this stream writable?

Returns:bool—

On this page

Methodspublic Sandbox.ByteStream Compress(System.IO.Compression.CompressionLevel compressionLevel = 0)public static Sandbox.ByteStream Create(System.Int32 size)public static Sandbox.ByteStream CreateReader(System.ReadOnlySpan`1<System.Byte> data)public Sandbox.ByteStream Decompress()public System.Void Dispose()public System.Void EnsureCanRead(System.Int32 size)public System.Void EnsureCanWrite(System.Int32 size)public System.Int32 Read(System.Byte[] buffer, System.Int32 offset, System.Int32 count)public System.Int32 Read(System.Span`1<System.Byte> buffer)public T Read()public T Read(T defaultValue = null, System.Boolean unused = False)public System.String Read(System.String defaultValue)public T[] ReadArray(System.Int32 maxElements = 1073741823)public System.Object ReadObject(System.Type objectType)public System.Byte[] ToArray()public System.Boolean TryRead(T v)public System.Void Write(Sandbox.ByteStream stream, System.Int32 offset, System.Int32 maxSize)public System.Void Write(Sandbox.ByteStream stream)public System.Void Write(System.Byte[] rawData, System.Int32 offset, System.Int32 bytes)public System.Void Write(System.Byte[] rawData)public System.Void Write(System.String str)public System.Void Write(T data, System.Boolean unused = False)public System.Void Write(T value)public System.Void WriteArray(T[] arr, System.Boolean includeCount = True)public System.Void WriteArray(System.ReadOnlySpan`1<T> arr)Propertiespublic System.Int32 Sandbox.ByteStream.Length { get; set; }public System.Int32 Sandbox.ByteStream.Position { get; set; }public System.Int32 Sandbox.ByteStream.ReadRemaining { get; set; }public System.Boolean Sandbox.ByteStream.Writable { get; set; }Metadata