Click or drag to resize
WriteBuffer Class
Provides a thin wrapper for a buffer that is emptied by calling the provided callback.
Inheritance Hierarchy

Namespace: Lawo.IO
Assembly: Lawo (in Lawo.dll) Version: 1.4.1707.27006
Syntax
C#
public sealed class WriteBuffer : Buffer

The WriteBuffer type exposes the following members.

Constructors
  NameDescription
Public methodWriteBuffer(WriteAsyncCallback, Int32)
Initializes a new instance of the WriteBuffer class.
Public methodWriteBuffer(WriteCallback, Int32)
Initializes a new instance of the WriteBuffer class.
Top
Properties
  NameDescription
Public propertyCapacity
Gets the number of bytes the buffer can contain.
(Inherited from Buffer.)
Public propertyCount
Gets or sets the number of bytes actually contained in the buffer.
Public propertyItem
Gets or sets the byte in the buffer at index.
(Inherited from Buffer.)
Top
Methods
  NameDescription
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodFlush
Empties the contents of the buffer by calling the callback specified at construction.
Public methodFlushAsync
Asynchronously empties the contents of the buffer by calling the callback specified at construction.
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodReserve
Ensures that size <= (Capacity - Count).
Public methodReserveAsync
Asynchronously ensures that size <= (Capacity - Count).
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodWrite
Writes the array segment identified by buffer, offset and count to the buffer.
Public methodWriteAsUtf8
Writes the UTF-8 representation of value to the buffer.
Public methodWriteAsync
Asynchronously writes the array segment identified by buffer, offset and count to the buffer.
Top
Remarks

The fields in this class and its base are not encapsulated properly for performance reasons. See ReadBuffer for more information.

A frequent use case for this class is when a not previously known number of bytes need to be written to a stream one by one. In this case the following code tends to be much faster than calling WriteByte(Byte) for each byte:

void WriteToStream(Stream stream)
{
    var writeBuffer = new WriteBuffer(stream.Write, 1024);
    bool done = false;

    while (!done && ((writeBuffer.Count < writeBuffer.Capacity) || writeBuffer.Flush()))
    {
        // ..
        byte theByte = 0x00; // Calculate the byte to append to the buffer
        writeBuffer[writeBuffer.Count++] = theByte;

        // Set done to true as soon as we're done...
    }
}

Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also