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
stream
StreamStream 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
val
byteByte value.
Write(byte[])
Write the specified byte buffer.
public void Write(byte[] buffer)
Parameters
buffer
byte[]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
val
doubleDouble precision floating point value.
Write(short)
Write the specified 16-bits signed value.
public void Write(short val)
Parameters
val
short16-bits signed value.
Write(int)
Write the specified 32-bits signed value.
public void Write(int val)
Parameters
val
int32-bits signed value.
Write(long)
Write the specified 64-bits signed value.
public void Write(long val)
Parameters
val
long64-bits signed value.
Write(sbyte)
Write the specified 8-bits signed byte value.
[CLSCompliant(false)]
public void Write(sbyte val)
Parameters
val
sbyteSigned byte value.
Write(float)
Write the specified 32-bits IEEE 754 single precision floating point value.
public void Write(float val)
Parameters
val
floatSingle 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
text
stringText string to write.
nullTerminator
boolIf set to true add null terminator.
encoding
EncodingText encoding to use.
maxSize
intMaximum 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
text
stringText string to write.
fixedSize
intFixed size of the encoded string in bytes.
nullTerminator
boolIf set to true add null terminator.
encoding
EncodingText 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
text
stringText string to write.
fixedSize
intFixed size of the encoded string in bytes.
terminator
stringToken to add as terminator.
If null, then no token will be added. encoding
EncodingText 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
text
stringText string to write.
terminator
stringToken to add as terminator.
If null, then no token will be added. encoding
EncodingText encoding to use.
maxSize
intMaximum 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
text
stringText string to write.
sizeType
TypeType of the string size to write.
nullTerminator
boolIf set to true add null terminator.
encoding
EncodingText encoding to use.
maxSize
intMaximum 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
text
stringText string to write.
sizeType
TypeType of the string size to write.
terminator
stringToken to add as terminator.
If null, then no token will be added. encoding
EncodingText encoding to use.
maxSize
intMaximum 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
val
ushort16-bits unsigned value.
Write(uint)
Write the specified 32-bits unsigned value.
[CLSCompliant(false)]
public void Write(uint val)
Parameters
val
uint32-bits unsigned value.
Write(ulong)
Write the specified 64-bits unsigned value.
[CLSCompliant(false)]
public void Write(ulong val)
Parameters
val
ulong64-bits unsigned value.
WriteInt24(int)
Write the specified 24-bits value.
public void WriteInt24(int val)
Parameters
val
int24-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
val
TValue to write.
Type Parameters
T
The 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)