[]
Provides a stream interface to a buffer located in unmanaged memory.
public class DataStream : Stream, IDisposable
Initializes a new instance of the DataStream class.
public DataStream(DataPointer dataPointer)
dataPointer
DataPointerThe data pointer.
Initializes a new instance of the DataStream class from a Blob buffer.
public DataStream(Blob buffer)
buffer
BlobThe buffer.
Initializes a new instance of the DataStream class, and allocates a new buffer to use as a backing store.
public DataStream(int sizeInBytes, bool canRead, bool canWrite)
sizeInBytes
intThe size of the buffer to be allocated, in bytes.
canRead
booltrue
if reading from the buffer should be allowed; otherwise, false
.
canWrite
booltrue
if writing to the buffer should be allowed; otherwise, false
.
Initializes a new instance of the DataStream class, using an unmanaged buffer as a backing store.
public DataStream(IntPtr userBuffer, long sizeInBytes, bool canRead, bool canWrite)
userBuffer
System.IntPtrA pointer to the buffer to be used as a backing store.
sizeInBytes
longThe size of the buffer provided, in bytes.
canRead
booltrue
if reading from the buffer should be allowed; otherwise, false
.
canWrite
booltrue
if writing to the buffer should be allowed; otherwise, false
.
Gets a value indicating whether the current stream supports reading.
public override bool CanRead { get; }
true
if the stream supports reading; otherwise, false
.
Gets a value indicating whether the current stream supports seeking.
public override bool CanSeek { get; }
Always true
.
Gets a value indicating whether the current stream supports writing.
public override bool CanWrite { get; }
true
if the stream supports writing; otherwise, false
.
Gets the internal pointer to the current stream's backing store.
public IntPtr DataPointer { get; }
An IntPtr to the buffer being used as a backing store.
Gets the length in bytes of the stream.
public override long Length { get; }
A long value representing the length of the stream in bytes.
Gets or sets the position within the current stream.
public override long Position { get; set; }
The current position within the stream.
Gets the position pointer.
public IntPtr PositionPointer { get; }
The position pointer.
Gets the length of the remaining.
public long RemainingLength { get; }
The length of the remaining.
Initializes a new instance of the DataStream class, using a managed buffer as a backing store.
public static DataStream Create<T>(T[] userBuffer, bool canRead, bool canWrite, int index = 0, bool pinBuffer = true) where T : struct
userBuffer
T[]A managed array to be used as a backing store.
canRead
booltrue
if reading from the buffer should be allowed; otherwise, false
.
canWrite
booltrue
if writing to the buffer should be allowed; otherwise, false
.
index
intIndex inside the buffer in terms of element count (not size in bytes).
pinBuffer
boolTrue to keep the managed buffer and pin it, false will allocate unmanaged memory and make a copy of it. Default is true.
T
Releases unmanaged and - optionally - managed resources
protected override void Dispose(bool disposing)
disposing
booltrue
to release both managed and unmanaged resources; false
to release only unmanaged resources.
Not supported.
public override void Flush()
Always thrown.
Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
public override int Read(byte[] buffer, int offset, int count)
buffer
byte[]An array of values to be read from the stream.
offset
intThe zero-based byte offset in buffer at which to begin storing the data read from the current stream.
count
intThe maximum number of bytes to be read from the current stream.
The number of bytes read from the stream.
In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.
This stream does not support reading.
Reads a sequence of bytes from the current stream and advances the current position within this stream by the number of bytes written.
public void Read(IntPtr buffer, int offset, int count)
buffer
System.IntPtrAn array of bytes. This method copies count
bytes from buffer
to the current stream.
offset
intThe zero-based byte offset in buffer
at which to begin copying bytes to the current stream.
count
intThe number of bytes to be written to the current stream.
Reads a single value from the current stream and advances the current position within this stream by the number of bytes read.
public T Read<T>() where T : struct
The value that was read.
T
The type of the value to be read from the stream.
In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.
This stream does not support reading.
Reads a bool.
public bool ReadBoolean()
an bool from the stream
In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.
public override int ReadByte()
Reads a ColorF.
public ColorF ReadColorF()
an Color4 from the stream
In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.
Reads a float.
public float ReadFloat()
a float from the stream
In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.
Reads a int.
public int ReadInt()
an int from the stream
In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.
Reads a Matrix.
public Matrix4x4 ReadMatrix4x4()
a Matrix from the stream
In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.
Reads a sequence of elements from the current stream into a target buffer and advances the position within the stream by the number of bytes read.
public int ReadRange<T>(T[] buffer, int offset, int count) where T : struct
buffer
T[]An array of values to be read from the stream.
offset
intThe zero-based byte offset in buffer at which to begin storing the data read from the current stream.
count
intThe number of values to be read from the current stream.
The number of bytes read from the stream.
T
In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.
This stream does not support reading.
Reads an array of values from the current stream, and advances the current position within this stream by the number of bytes written.
public T[] ReadRange<T>(int count) where T : struct
count
intAn array of values that was read from the current stream.
T
The type of the values to be read from the stream.
In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.
Reads a short.
public short ReadShort()
an short from the stream
In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.
Reads a Vector2.
public Vector2 ReadVector2()
an Vector2 from the stream
In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.
Reads a Vector3.
public Vector3 ReadVector3()
an Vector3 from the stream
In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.
Reads a Vector4.
public Vector4 ReadVector4()
an Vector4 from the stream
In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.
Sets the position within the current stream.
public override long Seek(long offset, SeekOrigin origin)
offset
longorigin
System.IO.SeekOriginAttempted to seek outside of the bounds of the stream.
Not supported.
public override void SetLength(long value)
value
longAlways ignored.
Always thrown.
Writes the specified value.
public void Write(ColorF value)
value
ColorFThe value.
In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.
Writes the specified value.
public void Write(Matrix4x4 value)
value
Matrix4x4The value.
In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.
Writes the specified value.
public void Write(Vector2 value)
value
Vector2The value.
In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.
Writes the specified value.
public void Write(Vector3 value)
value
Vector3The value.
In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.
Writes the specified value.
public void Write(Vector4 value)
value
Vector4The value.
In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.
Writes the specified value.
public void Write(bool value)
value
boolThe value.
In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.
Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
public override void Write(byte[] buffer, int offset, int count)
buffer
byte[]An array of bytes. This method copies count bytes from buffer to the current stream.
offset
intThe zero-based byte offset in buffer at which to begin copying bytes to the current stream.
count
intThe number of bytes to be written to the current stream.
In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.
This stream does not support writing.
Writes the specified value.
public void Write(short value)
value
shortThe value.
In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.
Writes the specified value.
public void Write(int value)
value
intThe value.
In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.
When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
public void Write(IntPtr buffer, int offset, int count)
buffer
System.IntPtrAn array of bytes. This method copies count
bytes from buffer
to the current stream.
offset
intThe zero-based byte offset in buffer
at which to begin copying bytes to the current stream.
count
intThe number of bytes to be written to the current stream.
Writes the specified value.
public void Write(float value)
value
floatThe value.
In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.
Writes a single value to the stream, and advances the current position within this stream by the number of bytes written.
public void Write<T>(T value) where T : struct
value
TThe value to write to the stream.
T
The type of the value to be written to the stream.
In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.
The stream does not support writing.
Writes a range of bytes to the current stream, and advances the current position within this stream by the number of bytes written.
public void WriteRange(IntPtr source, long count)
source
System.IntPtrA pointer to the location to start copying from.
count
longThe number of bytes to copy from source to the current stream.
In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.
This stream does not support writing.
Writes an array of values to the current stream, and advances the current position within this stream by the number of bytes written.
public void WriteRange<T>(T[] data, int offset, int count) where T : struct
data
T[]An array of values to be written to the stream.
offset
intThe zero-based offset in data at which to begin copying values to the current stream.
count
intThe number of values to be written to the current stream. If this is zero,
all of the contents data
will be written.
T
The type of the values to be written to the stream.
In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.
This stream does not support writing.
Writes an array of values to the current stream, and advances the current position within this stream by the number of bytes written.
public void WriteRange<T>(T[] data) where T : struct
data
T[]An array of values to be written to the current stream.
T
In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.
This stream does not support writing.
Performs an explicit conversion from DataStream to DataPointer.
public static implicit operator DataPointer(DataStream from)
from
DataStreamThe from value.
The result of the conversion.