Table of Contents

Class DataWriter

Namespace
Yarhl.IO
Assembly
Yarhl.dll

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 Stream

Stream 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 byte

Byte 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

ch char

Char to write.

encoding Encoding

Optional text encoding to use.

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

chars char[]

Char array to write.

encoding Encoding

Optional text encoding to use.

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 double

Double precision floating point value.

Write(short)

Write the specified 16-bits signed value.

public void Write(short val)

Parameters

val short

16-bits signed value.

Write(int)

Write the specified 32-bits signed value.

public void Write(int val)

Parameters

val int

32-bits signed value.

Write(long)

Write the specified 64-bits signed value.

public void Write(long val)

Parameters

val long

64-bits signed value.

Write(sbyte)

Write the specified 8-bits signed byte value.

[CLSCompliant(false)]
public void Write(sbyte val)

Parameters

val sbyte

Signed byte value.

Write(float)

Write the specified 32-bits IEEE 754 single precision floating point value.

public void Write(float val)

Parameters

val float

Single 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 string

Text string to write.

nullTerminator bool

If set to true add null terminator.

encoding Encoding

Text encoding to use.

maxSize int

Maximum 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 string

Text string to write.

fixedSize int

Fixed size of the encoded string in bytes.

nullTerminator bool

If set to true add null terminator.

encoding Encoding

Text 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 string

Text string to write.

fixedSize int

Fixed size of the encoded string in bytes.

terminator string

Token to add as terminator. If null, then no token will be added.

encoding Encoding

Text 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 string

Text string to write.

terminator string

Token to add as terminator. If null, then no token will be added.

encoding Encoding

Text encoding to use.

maxSize int

Maximum 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 string

Text string to write.

sizeType Type

Type of the string size to write.

nullTerminator bool

If set to true add null terminator.

encoding Encoding

Text encoding to use.

maxSize int

Maximum 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 string

Text string to write.

sizeType Type

Type of the string size to write.

terminator string

Token to add as terminator. If null, then no token will be added.

encoding Encoding

Text encoding to use.

maxSize int

Maximum 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 ushort

16-bits unsigned value.

Write(uint)

Write the specified 32-bits unsigned value.

[CLSCompliant(false)]
public void Write(uint val)

Parameters

val uint

32-bits unsigned value.

Write(ulong)

Write the specified 64-bits unsigned value.

[CLSCompliant(false)]
public void Write(ulong val)

Parameters

val ulong

64-bits unsigned value.

WriteInt24(int)

Write the specified 24-bits value.

public void WriteInt24(int val)

Parameters

val int

24-bits value.

WriteOfType(Type, object)

Write the specified value converting to any supported type.

public void WriteOfType(Type type, object val)

Parameters

type Type

Type of the value.

val object

Value to write.

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 T

Value 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

val byte

Value to repeat.

padding int

Padding value.

WriteTimes(byte, long)

Writes the same byte the specified number of times.

public void WriteTimes(byte val, long times)

Parameters

val byte

Value to write.

times long

Number of times to write the byte.

WriteUntilLength(byte, long)

Writes the same byte until the given stream length is reached.

public void WriteUntilLength(byte val, long length)

Parameters

val byte

Value to repeat.

length long

Stream length to reach.