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
typeMessageTypeThe 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
disposingbooltrue 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
valueboolThe value to write
WriteByte(byte)
Writes a byte to the underlying memory stream
public void WriteByte(byte value)
Parameters
valuebyteThe 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
databyte[]The byte array to write.
offsetintThe zero-based byte offset in
dataat which to begin writing.lengthintThe number of bytes to write.
WriteDouble(double)
Writes a 32-bit signed double to the underlying memory stream.
public void WriteDouble(double value)
Parameters
valuedoubleThe value to write.
WriteFloat(float)
Writes a 32-bit signed float to the underlying memory stream.
public void WriteFloat(float value)
Parameters
valuefloatThe value to write.
WriteInt16(int)
Writes a 16-bit signed integer to the underlying memory stream.
public void WriteInt16(int value)
Parameters
valueintThe value to write.
WriteInt32(int)
Writes a 32-bit signed integer to the underlying memory stream.
public void WriteInt32(int value)
Parameters
valueintThe value to write.
WriteString(string)
Writes a string to the underlying memory stream.
public void WriteString(string value)
Parameters
valuestringThe string to write.
WriteUInt16(uint)
Writes a 16-bit unsigned integer to the underlying memory stream.
public void WriteUInt16(uint value)
Parameters
valueuintThe value to write.
WriteUInt32(uint)
Writes a 32-bit unsigned integer to the underlying memory stream.
public void WriteUInt32(uint value)
Parameters
valueuintThe value to write.