Class MessageWriter
Represents a writer for creating binary messages.
public class MessageWriter : IDisposable
- Inheritance
-
MessageWriter
- Implements
- Inherited Members
Remarks
This class provides methods for writing various data types to a memory stream.
Constructors
MessageWriter(MessageType)
Initializes a new instance of the MessageWriter class with the specified message type.
public MessageWriter(MessageType type)
Parameters
type
MessageTypeThe message type.
Methods
Dispose()
Releases all resources used by the MessageWriter object.
public void Dispose()
Dispose(bool)
Releases the unmanaged resources used by the MessageWriter object and optionally releases the managed resources.
protected virtual void Dispose(bool disposing)
Parameters
disposing
booltrue to release both managed and unmanaged resources; false to release only unmanaged resources.
~MessageWriter()
Finalizes an instance of the MessageWriter class.
protected ~MessageWriter()
ToArray()
Returns the contents of the underlying memory stream as a byte array.
public byte[] ToArray()
Returns
- byte[]
A byte array containing the contents of the memory stream.
ToReader()
Creates a MessageReader instance from the current state of the underlying memory stream.
public MessageReader ToReader()
Returns
- MessageReader
A new MessageReader instance.
WriteBool(bool)
Writes a boolean to the underlying memory stream
public void WriteBool(bool value)
Parameters
value
boolThe value to write
WriteByte(byte)
Writes a byte to the underlying memory stream
public void WriteByte(byte value)
Parameters
value
byteThe value to write
WriteBytes(byte[], int, int)
Writes a byte array to the underlying memory stream.
public void WriteBytes(byte[] data, int offset, int length)
Parameters
data
byte[]The byte array to write.
offset
intThe zero-based byte offset in
data
at which to begin writing.length
intThe number of bytes to write.
WriteDouble(double)
Writes a 32-bit signed double to the underlying memory stream.
public void WriteDouble(double value)
Parameters
value
doubleThe value to write.
WriteFloat(float)
Writes a 32-bit signed float to the underlying memory stream.
public void WriteFloat(float value)
Parameters
value
floatThe value to write.
WriteInt16(int)
Writes a 16-bit signed integer to the underlying memory stream.
public void WriteInt16(int value)
Parameters
value
intThe value to write.
WriteInt32(int)
Writes a 32-bit signed integer to the underlying memory stream.
public void WriteInt32(int value)
Parameters
value
intThe value to write.
WriteString(string)
Writes a string to the underlying memory stream.
public void WriteString(string value)
Parameters
value
stringThe string to write.
WriteUInt16(uint)
Writes a 16-bit unsigned integer to the underlying memory stream.
public void WriteUInt16(uint value)
Parameters
value
uintThe value to write.
WriteUInt32(uint)
Writes a 32-bit unsigned integer to the underlying memory stream.
public void WriteUInt32(uint value)
Parameters
value
uintThe value to write.