Class DataWriter
BinaryWriter extension that adds methods for writing 32 and 64-bit integer values in a packed format.
Inherited Members
Namespace: Tangosol.IO
Assembly: Coherence.dll
Syntax
public class DataWriter : BinaryWriter, IAsyncDisposable, IDisposable
Remarks
The "packed" format includes a sign bit (0x40) and a continuation bit (0x80) in the first byte, followed by the least 6 significant bits of the int value. Subsequent bytes (each appearing only if the previous byte had its continuation bit set) include a continuation bit (0x80) and the next least 7 significant bits of the int value.
In this way, a 32-bit value is encoded into 1-5 bytes, and 64-bit value is encoded into 1-10 bytes, depending on the magnitude of the value being encoded.
Constructors
DataWriter(Stream)
Construct a new DataWriter that will write data to the specified Stream object.
Declaration
public DataWriter(Stream output)
Parameters
Type | Name | Description |
---|---|---|
Stream | output | The Stream object to write to; must not be |
Methods
Write(double)
Converts a Double value to its bits and writes an Int64 instance which stores the bits.
Declaration
public override void Write(double value)
Parameters
Type | Name | Description |
---|---|---|
double | value | A Double value to write. |
Overrides
Write(short)
Writes a two-byte signed integer to the current stream and advances the stream position by two bytes.
Declaration
public override void Write(short value)
Parameters
Type | Name | Description |
---|---|---|
short | value | The two-byte signed integer to write. |
Overrides
Remarks
Overrides BinaryWriter.Write(Int16) by changing endian of the value written to the stream.
Write(int)
Writes a four-byte signed integer to the current stream and advances the stream position by four bytes.
Declaration
public override void Write(int value)
Parameters
Type | Name | Description |
---|---|---|
int | value | The four-byte signed integer to write. |
Overrides
Remarks
Overrides BinaryWriter.Write(Int32) by changing endian of the value written to the stream.
Write(long)
Writes a eight-byte signed integer to the current stream and advances the stream position by eight bytes.
Declaration
public override void Write(long value)
Parameters
Type | Name | Description |
---|---|---|
long | value | The eight-byte signed integer to write. |
Overrides
Remarks
Overrides BinaryWriter.Write(Int64) by changing endian of the value written to the stream.
Write(float)
Converts a Single value to its bits and writes an Int32 instance which stores the bits.
Declaration
public override void Write(float value)
Parameters
Type | Name | Description |
---|---|---|
float | value | A Single value to write. |
Overrides
Write(string)
Writes string to the stream prefixed by its length in "packed" format.
Declaration
public override void Write(string text)
Parameters
Type | Name | Description |
---|---|---|
string | text | A string to write. |
Overrides
Write(ushort)
Writes a two-byte unsigned integer to the current stream and advances the stream position by two bytes.
Declaration
public override void Write(ushort value)
Parameters
Type | Name | Description |
---|---|---|
ushort | value | The two-byte unsigned integer to write. |
Overrides
Remarks
Overrides BinaryWriter.Write(UInt16) by changing endian of the value written to the stream.
Write(uint)
Writes a four-byte unsigned integer to the current stream and advances the stream position by four bytes.
Declaration
public override void Write(uint value)
Parameters
Type | Name | Description |
---|---|---|
uint | value | The four-byte unsigned integer to write. |
Overrides
Remarks
Overrides BinaryWriter.Write(UInt32) by changing endian of the value written to the stream.
Write(ulong)
Writes a eight-byte unsigned integer to the current stream and advances the stream position by eight bytes.
Declaration
public override void Write(ulong value)
Parameters
Type | Name | Description |
---|---|---|
ulong | value | The eight-byte unsigned integer to write. |
Overrides
Remarks
Overrides BinaryWriter.Write(UInt64) by changing endian of the value written to the stream.
WritePackedInt32(int)
Write an Int32 value using a variable-length storage format.
Declaration
public virtual void WritePackedInt32(int n)
Parameters
Type | Name | Description |
---|---|---|
int | n | An Int32 value to write. |
Remarks
The "packed" format includes a sign bit (0x40) and a continuation bit (0x80) in the first byte, followed by the least 6 significant bits of the int value. Subsequent bytes (each appearing only if the previous byte had its continuation bit set) include a continuation bit (0x80) and the next least 7 significant bits of the int value. In this way, a 32-bit value is encoded into 1-5 bytes, depending on the magnitude of the value being encoded.
Exceptions
Type | Condition |
---|---|
IOException | If an I/O error occurs. |
WritePackedInt64(long)
Write an Int64 value using a variable-length storage format.
Declaration
public virtual void WritePackedInt64(long l)
Parameters
Type | Name | Description |
---|---|---|
long | l | An Int64 value to write. |
Remarks
The "packed" format includes a sign bit (0x40) and a continuation bit (0x80) in the first byte, followed by the least 6 significant bits of the long value. Subsequent bytes (each appearing only if the previous byte had its continuation bit set) include a continuation bit (0x80) and the next least 7 significant bits of the long value. In this way, a 64-bit value is encoded into 1-10 bytes, depending on the magnitude of the value being encoded.
Exceptions
Type | Condition |
---|---|
IOException | If an I/O error occurs. |
WritePackedRawInt128(DataWriter, RawInt128)
Write a RawInt128 value to DataWriter.
Declaration
public virtual void WritePackedRawInt128(DataWriter writer, RawInt128 rawInt128)
Parameters
Type | Name | Description |
---|---|---|
DataWriter | writer | The DataWriter to write to. |
RawInt128 | rawInt128 | RawInt128 value. |
Remarks
RawInt128 value, which is represented as array of signed bytes.