Table of Contents

Class EndianBinaryWriter

Namespace
VAST.Common
Assembly
VAST.Common.dll

Equivalent of System.IO.BinaryWriter, but with either endianness, depending on the EndianBitConverter it is constructed with.

public class EndianBinaryWriter : IDisposable
Inheritance
EndianBinaryWriter
Implements
Inherited Members

Constructors

EndianBinaryWriter(Stream)

Constructs a new binary writer with the given bit converter, writing to the given stream, using UTF-8 encoding.

public EndianBinaryWriter(Stream stream)

Parameters

stream Stream

Stream to write data to

EndianBinaryWriter(Stream, bool)

Constructs a new binary writer with the given stream with the option to leave stream open on object dispose.

public EndianBinaryWriter(Stream stream, bool leaveOpen)

Parameters

stream Stream

Stream to write data to

leaveOpen bool

Leave stream open on object dispose

EndianBinaryWriter(Stream, Encoding)

Constructs a new binary writer with the given bit converter, writing to the given stream, using the given encoding.

public EndianBinaryWriter(Stream stream, Encoding encoding)

Parameters

stream Stream

Stream to write data to

encoding Encoding

Encoding to use when writing character data

EndianBinaryWriter(Stream, Encoding, bool)

Constructs a new binary writer with the given stream, using the given encoding with the option to leave stream open on object dispose.

public EndianBinaryWriter(Stream stream, Encoding encoding, bool leaveOpen)

Parameters

stream Stream

Stream to write data to

encoding Encoding

Encoding to use when writing character data

leaveOpen bool

Leave stream open on object dispose

Properties

BaseStream

Gets the underlying stream of the EndianBinaryWriter.

public Stream BaseStream { get; }

Property Value

Stream

BitPosition

Gets the current bit position within the current byte.

public int BitPosition { get; }

Property Value

int

Encoding

Gets the encoding used to write strings.

public Encoding Encoding { get; }

Property Value

Encoding

Endianness

Gets or sets the current endianness for this writer.

public Endianness Endianness { get; set; }

Property Value

Endianness

Remarks

This property can be changed at any point during writing to switch between big-endian and little-endian byte orders.

FilePosition

Gets or sets the current file position for tracking purposes.

public long FilePosition { get; set; }

Property Value

long

FullBitPosition

Gets the full bit position within the stream, calculated as byte position times 8 plus bit position.

public long FullBitPosition { get; }

Property Value

long

GlobalEndianness

Gets or sets the default endianness for all binary writers.

public static Endianness GlobalEndianness { get; set; }

Property Value

Endianness

LeaveOpen

Gets a value indicating whether the underlying stream will be left open when this writer is disposed.

public bool LeaveOpen { get; }

Property Value

bool

Length

Gets the length of the underlying stream in bytes.

public long Length { get; }

Property Value

long

Position

Gets the current position within the underlying stream.

public long Position { get; }

Property Value

long

Methods

Close()

Closes the writer, including the underlying stream.

public void Close()

Dispose()

Disposes of the underlying stream.

public void Dispose()

Fill(byte, long)

Writes the specified byte value repeatedly for the specified count.

public void Fill(byte value, long count)

Parameters

value byte

The byte value to write.

count long

The number of times to write the value.

Flush()

Flushes the underlying stream.

public void Flush()

Seek(long, SeekOrigin)

Seeks within the stream.

public void Seek(long offset, SeekOrigin origin)

Parameters

offset long

Offset to seek to.

origin SeekOrigin

Origin of seek operation.

SeekBits(long, SeekOrigin)

Seeks within the stream.

public void SeekBits(long offset, SeekOrigin origin)

Parameters

offset long

Offset to seek to.

origin SeekOrigin

Origin of seek operation.

Write(bool)

Writes a boolean value to the stream. 1 byte is written.

public void Write(bool value)

Parameters

value bool

The value to write

Write(byte)

Writes a signed byte to the stream.

public void Write(byte value)

Parameters

value byte

The value to write

Write(byte[])

Writes an array of bytes to the stream.

public void Write(byte[] value)

Parameters

value byte[]

The values to write

Write(byte[], int, int)

Writes a portion of an array of bytes to the stream.

public void Write(byte[] value, int offset, int count)

Parameters

value byte[]

An array containing the bytes to write

offset int

The index of the first byte to write within the array

count int

The number of bytes to write

Write(char)

Writes a single character to the stream, using the encoding for this writer.

public void Write(char value)

Parameters

value char

The value to write

Write(char[])

Writes an array of characters to the stream, using the encoding for this writer.

public void Write(char[] value)

Parameters

value char[]

An array containing the characters to write

Write(decimal)

Writes a decimal value to the stream, using the bit converter for this writer. 16 bytes are written.

public void Write(decimal value)

Parameters

value decimal

The value to write

Write(double)

Writes a double-precision floating-point value to the stream, using the bit converter for this writer. 8 bytes are written.

public void Write(double value)

Parameters

value double

The value to write

Write(short)

Writes a 16-bit signed integer to the stream, using the bit converter for this writer. 2 bytes are written.

public void Write(short value)

Parameters

value short

The value to write

Write(int)

Writes a 32-bit signed integer to the stream, using the bit converter for this writer. 4 bytes are written.

public void Write(int value)

Parameters

value int

The value to write

Write(int, int)

Writes a 32-bit signed integer to the stream, using the bit converter for this writer. byteCount bytes are written.

public void Write(int value, int byteCount)

Parameters

value int

The value to write

byteCount int

Number of bytes to write

Write(int, int, Endianness)

Writes a 32-bit signed integer to the stream, using the bit converter for this writer. byteCount bytes are written with specified endianness

public void Write(int value, int byteCount, Endianness endianness)

Parameters

value int

The value to write

byteCount int

Number of bytes to write

endianness Endianness

Endianness to use for this particular write only. It doesn't change the value of Endianness property.

Write(long)

Writes a 64-bit signed integer to the stream, using the bit converter for this writer. 8 bytes are written.

public void Write(long value)

Parameters

value long

The value to write

Write(long, int)

Writes a 64-bit signed integer to the stream, using the bit converter for this writer. byteCount bytes are written.

public void Write(long value, int byteCount)

Parameters

value long

The value to write

byteCount int

Number of bytes to write

Write(sbyte)

Writes an unsigned byte to the stream.

public void Write(sbyte value)

Parameters

value sbyte

The value to write

Write(float)

Writes a single-precision floating-point value to the stream, using the bit converter for this writer. 4 bytes are written.

public void Write(float value)

Parameters

value float

The value to write

Write(string)

Writes a string to the stream, using the encoding for this writer.

public void Write(string value)

Parameters

value string

The value to write. Must not be null.

Exceptions

ArgumentNullException

value is null

Write(ushort)

Writes a 16-bit unsigned integer to the stream, using the bit converter for this writer. 2 bytes are written.

public void Write(ushort value)

Parameters

value ushort

The value to write

Write(uint)

Writes a 32-bit unsigned integer to the stream, using the bit converter for this writer. 4 bytes are written.

public void Write(uint value)

Parameters

value uint

The value to write

Write(uint, int)

Writes a 32-bit unsigned integer to the stream, using the bit converter for this writer. byteCount bytes are written.

public void Write(uint value, int byteCount)

Parameters

value uint

The value to write

byteCount int

Number of bytes to write

Write(ulong)

Writes a 64-bit unsigned integer to the stream, using the bit converter for this writer. 8 bytes are written.

public void Write(ulong value)

Parameters

value ulong

The value to write

Write(VersatileBuffer, int, int)

Writes a portion of VersatileBuffer to the stream.

public void Write(VersatileBuffer buffer, int offset, int count)

Parameters

buffer VersatileBuffer

VersatileBuffer containing the bytes to write

offset int

The index of the first byte to write within the buffer

count int

The number of bytes to write

Write7BitEncodedInt(int)

Writes a 7-bit encoded integer from the stream. This is stored with the least significant information first, with 7 bits of information per byte of value, and the top bit as a continuation flag.

public void Write7BitEncodedInt(int value)

Parameters

value int

The 7-bit encoded integer to write to the stream

WriteBits(long, int)

Writes the specified number of bits from a signed value to the stream using the current endianness.

public void WriteBits(long value, int bitCount)

Parameters

value long

The value to write bits from.

bitCount int

The number of bits to write (maximum 64).

WriteBits(long, int, Endianness)

Writes the specified number of bits from a signed value to the stream using the specified endianness.

public void WriteBits(long value, int bitCount, Endianness endianness)

Parameters

value long

The value to write bits from.

bitCount int

The number of bits to write (maximum 64).

endianness Endianness

The endianness to use for the conversion.

WriteBits(ulong, int)

Writes the specified number of bits from an unsigned value to the stream using the current endianness.

public void WriteBits(ulong value, int bitCount)

Parameters

value ulong

The value to write bits from.

bitCount int

The number of bits to write (maximum 64).

WriteBits(ulong, int, Endianness)

Writes the specified number of bits from an unsigned value to the stream using the specified endianness.

public void WriteBits(ulong value, int bitCount, Endianness endianness)

Parameters

value ulong

The value to write bits from.

bitCount int

The number of bits to write (maximum 64).

endianness Endianness

The endianness to use for the conversion.

WriteSignedExpGolomb(int)

Writes a signed value using Exponential-Golomb coding to the stream.

public void WriteSignedExpGolomb(int value)

Parameters

value int

The signed value to encode and write.

WriteUnsignedExpGolomb(uint)

Writes an unsigned value using Exponential-Golomb coding to the stream.

public void WriteUnsignedExpGolomb(uint value)

Parameters

value uint

The unsigned value to encode and write.