Class DataBuffer
Operates as a data buffer for network and file output.
Inherited Members
Namespace: MBNCSUtil
Assembly: MBNCSUtil.dll
Syntax
public class DataBuffer
Remarks
This class does not read data in any manner; for reading or receiving data, use the DataReader or derived classes.
This class always uses little-endian byte ordering.
This class no longer supports operator overloading in C# via the binary addition (+) operator.
Constructors
| Improve this Doc View SourceDataBuffer()
Creates a new DataBuffer.
Declaration
public DataBuffer()
Properties
| Improve this Doc View SourceCount
Gets the length of data in the buffer.
Declaration
public virtual int Count { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
| Improve this Doc View SourceGetData()
Gets the data currently contained in the buffer.
Declaration
public virtual byte[] GetData()
Returns
Type | Description |
---|---|
System.Byte[] | A byte array representing the data in the buffer. |
Insert(Boolean)
Inserts the specified Boolean value into the buffer.
Declaration
public void Insert(bool b)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | b | The value to insert. |
Remarks
This method inserts a 32-bit value of 1 or 0 based on the value of the parameter: 1 if the value is true, or otherwise 0.
Insert(Byte)
Inserts the specified value into the buffer.
Declaration
public void Insert(byte b)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | b | The value to insert. |
Insert(Byte[])
Inserts the specified byte array into the buffer.
Declaration
public void Insert(byte[] b)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | b | The value to insert. |
Insert(Int16)
Inserts the specified value into the buffer.
Declaration
public void Insert(short s)
Parameters
Type | Name | Description |
---|---|---|
System.Int16 | s | The value to insert. |
Insert(Int16[])
Inserts the specified 16-bit data array into the buffer.
Declaration
public void Insert(short[] s)
Parameters
Type | Name | Description |
---|---|---|
System.Int16[] | s | The value to insert. |
Insert(Int32)
Inserts the specified value into the buffer.
Declaration
public void Insert(int i)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i | The value to insert. |
Insert(Int32[])
Inserts the specified 32-bit data array into the buffer.
Declaration
public void Insert(int[] i)
Parameters
Type | Name | Description |
---|---|---|
System.Int32[] | i | The value to insert. |
Insert(Int64)
Inserts the specified value into the buffer.
Declaration
public void Insert(long l)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | l | The value to insert. |
Insert(Int64[])
Inserts the specified 64-bit data array into the buffer.
Declaration
public void Insert(long[] l)
Parameters
Type | Name | Description |
---|---|---|
System.Int64[] | l | The value to insert. |
Insert(SByte)
Inserts the specified value into the buffer.
Declaration
[CLSCompliant(false)]
public void Insert(sbyte b)
Parameters
Type | Name | Description |
---|---|---|
System.SByte | b | The value to insert. |
Remarks
This method is not CLS-compliant.
Insert(SByte[])
Inserts the specified byte array into the buffer.
Declaration
[CLSCompliant(false)]
public void Insert(sbyte[] b)
Parameters
Type | Name | Description |
---|---|---|
System.SByte[] | b | The value to insert. |
Remarks
This method is not CLS-compliant.
Insert(UInt16)
Inserts the specified value into the buffer.
Declaration
[CLSCompliant(false)]
public void Insert(ushort s)
Parameters
Type | Name | Description |
---|---|---|
System.UInt16 | s | The value to insert. |
Remarks
This method is not CLS-compliant.
Insert(UInt16[])
Inserts the specified 16-bit data array into the buffer.
Declaration
[CLSCompliant(false)]
public void Insert(ushort[] s)
Parameters
Type | Name | Description |
---|---|---|
System.UInt16[] | s | The value to insert. |
Remarks
This method is not CLS-compliant.
Insert(UInt32)
Inserts the specified value into the buffer.
Declaration
[CLSCompliant(false)]
public void Insert(uint i)
Parameters
Type | Name | Description |
---|---|---|
System.UInt32 | i | The value to insert. |
Remarks
This method is not CLS-compliant.
Insert(UInt32[])
Inserts the specified 32-bit data array into the buffer.
Declaration
[CLSCompliant(false)]
public void Insert(uint[] i)
Parameters
Type | Name | Description |
---|---|---|
System.UInt32[] | i | The value to insert. |
Remarks
This method is not CLS-compliant.
Insert(UInt64)
Inserts the specified value into the buffer.
Declaration
[CLSCompliant(false)]
public void Insert(ulong l)
Parameters
Type | Name | Description |
---|---|---|
System.UInt64 | l | The value to insert. |
Remarks
This method is not CLS-compliant.
Insert(UInt64[])
Inserts the specified 64-bit data array into the buffer.
Declaration
[CLSCompliant(false)]
public void Insert(ulong[] l)
Parameters
Type | Name | Description |
---|---|---|
System.UInt64[] | l | The value to insert. |
Remarks
This method is not CLS-compliant.
InsertBoolean(Boolean)
Inserts the specified Boolean value into the buffer.
Declaration
public void InsertBoolean(bool b)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | b | The value to insert. |
Remarks
This method inserts a 32-bit value of 1 or 0 based on the value of the parameter: 1 if the value is true, or otherwise 0.
InsertByte(Byte)
Inserts the specified value into the buffer.
Declaration
public void InsertByte(byte b)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | b | The value to insert. |
InsertByteArray(Byte[])
Inserts the specified byte array into the buffer.
Declaration
public void InsertByteArray(byte[] b)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | b | The value to insert. |
InsertCString(String)
Inserts the specified value into the buffer as a C-style null-terminated ASCII string.
Declaration
public void InsertCString(string str)
Parameters
Type | Name | Description |
---|---|---|
System.String | str | The string value to insert. |
Remarks
This method inserts a string terminated by a single null (0) byte.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Either |
InsertCString(String, Encoding)
Inserts the specified value into the buffer as a C-style null-terminated string using the specified encoding.
Declaration
public void InsertCString(string str, Encoding enc)
Parameters
Type | Name | Description |
---|---|---|
System.String | str | The string value to insert. |
System.Text.Encoding | enc | The byte encoding to use. |
Remarks
This method inserts a string terminated by a null character. For 8-bit character encodings such as ASCII, this null character is also 8 bits. For 16-bit character encodings such as Unicode, this null character is also 16 bits.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Either |
InsertDwordString(String)
Inserts the specified value into the buffer as a 32-bit-style string using null bytes as the default padding.
Declaration
public void InsertDwordString(string str)
Parameters
Type | Name | Description |
---|---|---|
System.String | str | The string which may be at most 4 characters. |
Remarks
This method inserts a string with the maximum length of 4 into the buffer, reversed. This mimics the C-style declarations of 4-character integer literals:
unsigned long int star_product = 'STAR';
which results in RATS
being in memory.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The |
System.ArgumentException | The length of |
InsertDwordString(String, Byte)
Inserts the specified value into the buffer as a 32-bit-style string using the specified byte as padding.
Declaration
public void InsertDwordString(string str, byte padding)
Parameters
Type | Name | Description |
---|---|---|
System.String | str | The string which may be at most 4 characters. |
System.Byte | padding | The byte which shall be used to pad the string if it is less than 4 characters long. |
Remarks
This method inserts a string with the maximum length of 4 into the buffer, reversed. This mimics the C-style declarations of 4-character integer literals:
unsigned long int star_product = 'STAR';
which results in RATS
being in memory.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The |
System.ArgumentException | The length of |
InsertInt16(Int16)
Inserts the specified value into the buffer.
Declaration
public void InsertInt16(short s)
Parameters
Type | Name | Description |
---|---|---|
System.Int16 | s | The value to insert. |
InsertInt16Array(Int16[])
Inserts the specified 16-bit data array into the buffer.
Declaration
public void InsertInt16Array(short[] s)
Parameters
Type | Name | Description |
---|---|---|
System.Int16[] | s | The value to insert. |
InsertInt32(Int32)
Inserts the specified value into the buffer.
Declaration
public void InsertInt32(int i)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i | The value to insert. |
InsertInt32Array(Int32[])
Inserts the specified 32-bit data array into the buffer.
Declaration
public void InsertInt32Array(int[] i)
Parameters
Type | Name | Description |
---|---|---|
System.Int32[] | i | The value to insert. |
InsertInt64(Int64)
Inserts the specified value into the buffer.
Declaration
public void InsertInt64(long l)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | l | The value to insert. |
InsertInt64Array(Int64[])
Inserts the specified 64-bit data array into the buffer.
Declaration
public void InsertInt64Array(long[] l)
Parameters
Type | Name | Description |
---|---|---|
System.Int64[] | l | The value to insert. |
InsertNonNullString(String)
Inserts the specified value into the buffer as a C-style null-terminated ASCII string.
Declaration
public void InsertNonNullString(string str)
Parameters
Type | Name | Description |
---|---|---|
System.String | str | The string value to insert. |
Remarks
This method inserts a string terminated by a single null (0) byte.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Either |
InsertNonNullString(String, Encoding)
Inserts the specified value into the buffer as a C-style null-terminated string using the specified encoding.
Declaration
public void InsertNonNullString(string str, Encoding enc)
Parameters
Type | Name | Description |
---|---|---|
System.String | str | The string value to insert. |
System.Text.Encoding | enc | The byte encoding to use. |
Remarks
This method inserts a string terminated by a null character. For 8-bit character encodings such as ASCII, this null character is also 8 bits. For 16-bit character encodings such as Unicode, this null character is also 16 bits.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Either |
InsertPascalString(String)
Inserts the specified value into the buffer as a pascal-style ASCII string.
Declaration
public void InsertPascalString(string str)
Parameters
Type | Name | Description |
---|---|---|
System.String | str | The string value to insert. |
Remarks
This method inserts a string prefixed by the total number of characters in the string. At most a string may be 255 characters.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Either |
System.ArgumentException | The length of |
InsertPascalString(String, Encoding)
Inserts the specified value into the buffer as a pascal-style string using the specified encoding.
Declaration
public void InsertPascalString(string str, Encoding enc)
Parameters
Type | Name | Description |
---|---|---|
System.String | str | The string value to insert. |
System.Text.Encoding | enc | The encoding to use. |
Remarks
This method inserts a string prefixed by the total number of characters in the string. At most a string may be 255 characters.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Either |
System.ArgumentException | The length of |
InsertSByte(SByte)
Inserts the specified value into the buffer.
Declaration
[CLSCompliant(false)]
public void InsertSByte(sbyte b)
Parameters
Type | Name | Description |
---|---|---|
System.SByte | b | The value to insert. |
Remarks
This method is not CLS-compliant.
InsertSByteArray(SByte[])
Inserts the specified byte array into the buffer.
Declaration
[CLSCompliant(false)]
public void InsertSByteArray(sbyte[] b)
Parameters
Type | Name | Description |
---|---|---|
System.SByte[] | b | The value to insert. |
Remarks
This method is not CLS-compliant.
InsertUInt16(UInt16)
Inserts the specified value into the buffer.
Declaration
[CLSCompliant(false)]
public void InsertUInt16(ushort s)
Parameters
Type | Name | Description |
---|---|---|
System.UInt16 | s | The value to insert. |
Remarks
This method is not CLS-compliant.
InsertUInt16Array(UInt16[])
Inserts the specified 16-bit data array into the buffer.
Declaration
[CLSCompliant(false)]
public void InsertUInt16Array(ushort[] s)
Parameters
Type | Name | Description |
---|---|---|
System.UInt16[] | s | The value to insert. |
Remarks
This method is not CLS-compliant.
InsertUInt32(UInt32)
Inserts the specified value into the buffer.
Declaration
[CLSCompliant(false)]
public void InsertUInt32(uint i)
Parameters
Type | Name | Description |
---|---|---|
System.UInt32 | i | The value to insert. |
Remarks
This method is not CLS-compliant.
InsertUInt32Array(UInt32[])
Inserts the specified 32-bit data array into the buffer.
Declaration
[CLSCompliant(false)]
public void InsertUInt32Array(uint[] i)
Parameters
Type | Name | Description |
---|---|---|
System.UInt32[] | i | The value to insert. |
Remarks
This method is not CLS-compliant.
InsertUInt64(UInt64)
Inserts the specified value into the buffer.
Declaration
[CLSCompliant(false)]
public void InsertUInt64(ulong l)
Parameters
Type | Name | Description |
---|---|---|
System.UInt64 | l | The value to insert. |
Remarks
This method is not CLS-compliant.
InsertUInt64Array(UInt64[])
Inserts the specified 64-bit data array into the buffer.
Declaration
[CLSCompliant(false)]
public void InsertUInt64Array(ulong[] l)
Parameters
Type | Name | Description |
---|---|---|
System.UInt64[] | l | The value to insert. |
Remarks
This method is not CLS-compliant.
InsertWidePascalString(String)
Inserts the specified value into the buffer as a wide-pascal-style ASCII string.
Declaration
public void InsertWidePascalString(string str)
Parameters
Type | Name | Description |
---|---|---|
System.String | str | The string value to insert. |
Remarks
This method inserts a string prefixed by the total number of characters in the string. At most a string may be 65,535 characters.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Either |
System.ArgumentException | The length of |
InsertWidePascalString(String, Encoding)
Inserts the specified value into the buffer as a wide-pascal-style string using the specified encoding.
Declaration
public void InsertWidePascalString(string str, Encoding enc)
Parameters
Type | Name | Description |
---|---|---|
System.String | str | The string value to insert. |
System.Text.Encoding | enc | The encoding to use. |
Remarks
This method inserts a string prefixed by the total number of characters in the string. At most a string may be 65,535 characters.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Either |
System.ArgumentException | The length of |
ToString()
Gets a hex representation of this buffer.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | A string representing this buffer's contents in hexadecimal notation. |
Overrides
WriteToOutputStream(Stream)
Writes the data currently contained in the buffer to the specified stream.
Declaration
public virtual int WriteToOutputStream(Stream str)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | str | The stream to which to write the data. |
Returns
Type | Description |
---|---|
System.Int32 | The number of bytes written to the stream. |