Class EndianBinaryWriter
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
streamStreamStream 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
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
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
streamStreamStream to write data to
encodingEncodingEncoding to use when writing character data
leaveOpenboolLeave stream open on object dispose
Properties
BaseStream
Gets the underlying stream of the EndianBinaryWriter.
public Stream BaseStream { get; }
Property Value
BitPosition
Gets the current bit position within the current byte.
public int BitPosition { get; }
Property Value
Encoding
Gets the encoding used to write strings.
public Encoding Encoding { get; }
Property Value
Endianness
Gets or sets the current endianness for this writer.
public Endianness Endianness { get; set; }
Property Value
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
FullBitPosition
Gets the full bit position within the stream, calculated as byte position times 8 plus bit position.
public long FullBitPosition { get; }
Property Value
GlobalEndianness
Gets or sets the default endianness for all binary writers.
public static Endianness GlobalEndianness { get; set; }
Property Value
LeaveOpen
Gets a value indicating whether the underlying stream will be left open when this writer is disposed.
public bool LeaveOpen { get; }
Property Value
Length
Gets the length of the underlying stream in bytes.
public long Length { get; }
Property Value
Position
Gets the current position within the underlying stream.
public long Position { get; }
Property Value
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
Flush()
Flushes the underlying stream.
public void Flush()
Seek(long, SeekOrigin)
Seeks within the stream.
public void Seek(long offset, SeekOrigin origin)
Parameters
offsetlongOffset to seek to.
originSeekOriginOrigin of seek operation.
SeekBits(long, SeekOrigin)
Seeks within the stream.
public void SeekBits(long offset, SeekOrigin origin)
Parameters
offsetlongOffset to seek to.
originSeekOriginOrigin of seek operation.
Write(bool)
Writes a boolean value to the stream. 1 byte is written.
public void Write(bool value)
Parameters
valueboolThe value to write
Write(byte)
Writes a signed byte to the stream.
public void Write(byte value)
Parameters
valuebyteThe value to write
Write(byte[])
Writes an array of bytes to the stream.
public void Write(byte[] value)
Parameters
valuebyte[]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
valuebyte[]An array containing the bytes to write
offsetintThe index of the first byte to write within the array
countintThe 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
valuecharThe 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
valuechar[]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
valuedecimalThe 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
valuedoubleThe 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
valueshortThe 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
valueintThe 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
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
valueintThe value to write
byteCountintNumber of bytes to write
endiannessEndiannessEndianness 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
valuelongThe 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
Write(sbyte)
Writes an unsigned byte to the stream.
public void Write(sbyte value)
Parameters
valuesbyteThe 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
valuefloatThe value to write
Write(string)
Writes a string to the stream, using the encoding for this writer.
public void Write(string value)
Parameters
valuestringThe 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
valueushortThe 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
valueuintThe 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
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
valueulongThe 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
bufferVersatileBufferVersatileBuffer containing the bytes to write
offsetintThe index of the first byte to write within the buffer
countintThe 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
valueintThe 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
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
valuelongThe value to write bits from.
bitCountintThe number of bits to write (maximum 64).
endiannessEndiannessThe 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
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
valueulongThe value to write bits from.
bitCountintThe number of bits to write (maximum 64).
endiannessEndiannessThe 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
valueintThe 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
valueuintThe unsigned value to encode and write.