Class DataWriter
BinaryWriter extension that adds methods for writing 32 and 64-bit integer values in a packed format.
Inheritance
Implements
Inherited Members
Namespace: Tangosol.IO
Assembly: Coherence.Core.dll
Syntax
public class DataWriter : BinaryWriter, 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
| Improve this Doc View SourceDataWriter(Stream)
Construct a new DataWriter that will write data to the specified Stream object.
Declaration
public DataWriter(Stream output)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | output | The Stream object to write to; must not be |
Fields
| Improve this Doc View SourceCHAR_BUF_MASK
Bitmask used against a raw offset to determine the offset within the temporary character buffer.
Declaration
protected const int CHAR_BUF_MASK = 255
Field Value
Type | Description |
---|---|
System.Int32 |
CHAR_BUF_SIZE
Size of the temporary character buffer. Must be a power of 2. Size is: 256 characters (.25 KB).
Declaration
protected const int CHAR_BUF_SIZE = 256
Field Value
Type | Description |
---|---|
System.Int32 |
m_achBuf
A lazily instantiated temp buffer used to avoid allocations from and repeated calls to String functions.
Declaration
protected char[] m_achBuf
Field Value
Type | Description |
---|---|
System.Char[] |
Properties
| Improve this Doc View SourceCharBuf
Obtain a temp buffer used to avoid allocations from repeated calls to String APIs.
Declaration
protected char[] CharBuf { get; }
Property Value
Type | Description |
---|---|
System.Char[] |
Methods
| Improve this Doc View SourceCalcUTF(String)
Figure out how many bytes it will take to hold the passed String.
Declaration
protected int CalcUTF(string s)
Parameters
Type | Name | Description |
---|---|---|
System.String | s | the String |
Returns
Type | Description |
---|---|
System.Int32 |
Remarks
This method is tightly bound to formatUTF.
FormatUTF(Byte[], Int32, Char[], Int32)
Format the passed characters as UTF into the passed byte array.
Declaration
protected int FormatUTF(byte[] ab, int ofb, char[] ach, int cch)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | ab | The byte array to format into. |
System.Int32 | ofb | The offset into the byte array to write the first byte. |
System.Char[] | ach | The array of characters to format. |
System.Int32 | cch | The number of characters to format. |
Returns
Type | Description |
---|---|
System.Int32 |
FormatUTF(String)
Format the passed String as UTF into the passed byte array.
Declaration
public byte[] FormatUTF(string s)
Parameters
Type | Name | Description |
---|---|---|
System.String | s | the string. |
Returns
Type | Description |
---|---|
System.Byte[] | The formated UTF byte array. |
Remarks
This method is tightly bound to calcUTF.
Tmpbuf(Int32)
Get a buffer for formating data to bytes. Note that the resulting buffer may be shorter than the requested size.
Declaration
protected byte[] Tmpbuf(int cb)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | cb | the requested size for the buffer |
Returns
Type | Description |
---|---|
System.Byte[] |
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 |
---|---|---|
System.Double | value | A Double value to write. |
Overrides
Write(Int16)
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 |
---|---|---|
System.Int16 | 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(Int32)
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 |
---|---|---|
System.Int32 | 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(Int64)
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 |
---|---|---|
System.Int64 | 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(Single)
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 |
---|---|---|
System.Single | 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 |
---|---|---|
System.String | text | A string to write. |
Overrides
Write(UInt16)
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 |
---|---|---|
System.UInt16 | 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(UInt32)
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 |
---|---|---|
System.UInt32 | 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(UInt64)
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 |
---|---|---|
System.UInt64 | 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(Int32)
Write an Int32 value using a variable-length storage format.
Declaration
public virtual void WritePackedInt32(int n)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | 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 |
---|---|
System.IO.IOException | If an I/O error occurs. |
WritePackedInt64(Int64)
Write an Int64 value using a variable-length storage format.
Declaration
public virtual void WritePackedInt64(long l)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | 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 |
---|---|
System.IO.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.