Class DataWriter
Binary writer for DataStreams.
public class DataWriter
- Inheritance
-
DataWriter
- Inherited Members
Constructors
DataWriter(Stream)
Initializes a new instance of the DataWriter class.
public DataWriter(Stream stream)
Parameters
streamStreamStream to write to.
Remarks
By default the endianess is LittleEndian and the encoding is UTF-8.
Properties
DefaultEncoding
Gets or sets the default encoding.
public Encoding DefaultEncoding { get; set; }
Property Value
- Encoding
The default encoding.
Endianness
Gets or sets the endianness.
public EndiannessMode Endianness { get; set; }
Property Value
- EndiannessMode
The endianness.
Stream
Gets the stream.
public DataStream Stream { get; }
Property Value
- DataStream
The stream.
Methods
Write(byte)
Write the specified 8-bits byte value.
public void Write(byte val)
Parameters
valbyteByte value.
Write(byte[])
Write the specified byte buffer.
public void Write(byte[] buffer)
Parameters
bufferbyte[]Byte buffer.
Write(char, Encoding?)
Write the specified char using a text encoding.
public void Write(char ch, Encoding? encoding = null)
Parameters
Remarks
If the encoding is null, it will use the default encoding.
Write(char[], Encoding?)
Write the specified chars using a text encoding.
public void Write(char[] chars, Encoding? encoding = null)
Parameters
Remarks
If the encoding is null, it will use the default encoding.
Write(double)
Write the specified 64-bits IEEE 754 double precision floating point value.
public void Write(double val)
Parameters
valdoubleDouble precision floating point value.
Write(short)
Write the specified 16-bits signed value.
public void Write(short val)
Parameters
valshort16-bits signed value.
Write(int)
Write the specified 32-bits signed value.
public void Write(int val)
Parameters
valint32-bits signed value.
Write(long)
Write the specified 64-bits signed value.
public void Write(long val)
Parameters
vallong64-bits signed value.
Write(sbyte)
Write the specified 8-bits signed byte value.
[CLSCompliant(false)]
public void Write(sbyte val)
Parameters
valsbyteSigned byte value.
Write(float)
Write the specified 32-bits IEEE 754 single precision floating point value.
public void Write(float val)
Parameters
valfloatSingle precision floating point value.
Write(string, bool, Encoding?, int)
Write a text string.
public void Write(string text, bool nullTerminator = true, Encoding? encoding = null, int maxSize = -1)
Parameters
textstringText string to write.
nullTerminatorboolIf set to true add null terminator.
encodingEncodingText encoding to use.
maxSizeintMaximum size of the encoded string in bytes.
Remarks
If the encoding is null, it will use the default encoding.
Write(string, int, bool, Encoding?)
Write a text string with a fixed size.
public void Write(string text, int fixedSize, bool nullTerminator = true, Encoding? encoding = null)
Parameters
textstringText string to write.
fixedSizeintFixed size of the encoded string in bytes.
nullTerminatorboolIf set to true add null terminator.
encodingEncodingText encoding to use.
Remarks
If the encoding is null, it will use the default encoding.
Write(string, int, string?, Encoding?)
Write a text string with a fixed size and a custom terminator.
public void Write(string text, int fixedSize, string? terminator, Encoding? encoding = null)
Parameters
textstringText string to write.
fixedSizeintFixed size of the encoded string in bytes.
terminatorstringToken to add as terminator.
If null, then no token will be added. encodingEncodingText encoding to use.
Remarks
If the encoding is null, it will use the default encoding.
Write(string, string?, Encoding?, int)
Write a text string using a custom terminator.
public void Write(string text, string? terminator, Encoding? encoding = null, int maxSize = -1)
Parameters
textstringText string to write.
terminatorstringToken to add as terminator.
If null, then no token will be added. encodingEncodingText encoding to use.
maxSizeintMaximum size of the encoded string in bytes.
Remarks
If the encoding is null, it will use the default encoding.
Write(string, Type, bool, Encoding?, int)
Write a text string and its size.
public void Write(string text, Type sizeType, bool nullTerminator = false, Encoding? encoding = null, int maxSize = -1)
Parameters
textstringText string to write.
sizeTypeTypeType of the string size to write.
nullTerminatorboolIf set to true add null terminator.
encodingEncodingText encoding to use.
maxSizeintMaximum size of the encoded string in bytes.
Remarks
If the encoding is null, it will use the default encoding.
Write(string, Type, string?, Encoding?, int)
Write a text string and its size.
public void Write(string text, Type sizeType, string? terminator, Encoding? encoding = null, int maxSize = -1)
Parameters
textstringText string to write.
sizeTypeTypeType of the string size to write.
terminatorstringToken to add as terminator.
If null, then no token will be added. encodingEncodingText encoding to use.
maxSizeintMaximum size of the encoded string in bytes.
Remarks
If the encoding is null, it will use the default encoding.
Write(ushort)
Write the specified 16-bits unsigned value.
[CLSCompliant(false)]
public void Write(ushort val)
Parameters
valushort16-bits unsigned value.
Write(uint)
Write the specified 32-bits unsigned value.
[CLSCompliant(false)]
public void Write(uint val)
Parameters
valuint32-bits unsigned value.
Write(ulong)
Write the specified 64-bits unsigned value.
[CLSCompliant(false)]
public void Write(ulong val)
Parameters
valulong64-bits unsigned value.
WriteInt24(int)
Write the specified 24-bits value.
public void WriteInt24(int val)
Parameters
valint24-bits value.
WriteOfType(Type, object)
Write the specified value converting to any supported type.
public void WriteOfType(Type type, object val)
Parameters
Remarks
The supported types are: long, ulong, int, uint, short, ushort, byte, sbyte, char and string.
WriteOfType<T>(T)
Write the specified value forcing the type in the generic.
public void WriteOfType<T>(T val)
Parameters
valTValue to write.
Type Parameters
TThe type of the value.
WritePadding(byte, int)
Write the same byte to pad the stream.
public void WritePadding(byte val, int padding)
Parameters
WriteTimes(byte, long)
Writes the same byte the specified number of times.
public void WriteTimes(byte val, long times)
Parameters
WriteUntilLength(byte, long)
Writes the same byte until the given stream length is reached.
public void WriteUntilLength(byte val, long length)