Class FinByteBuffer

Namespace
Subsembly.FinTS
Assembly
Subsembly.FinTS.Core.dll

Dynamically manages a sequence of bytes inside a byte array.

public class FinByteBuffer
Inheritance
FinByteBuffer
Derived
Inherited Members

Remarks

A byte buffer can be used to efficiently build a sequence of bytes, similar to the StringBuilder, which is used to build a sequence of characters. The FinByteBuffer provides various methods for appending bytes to its end.

A FinByteBuffer can also be used to simply hold a reference to a sequence of bytes inside an existing byte array that it does not own. This will be the case if the FinByteBuffer was created through the FinByteBuffer(byte[], int, int) constructor. Appending anything to such a FinByteBuffer will always allocate a new byte array and copy all data into the new array. The byte array that was passed to the constructor will never be changed.

Constructors

FinByteBuffer()

Creates a completely empty byte buffer that can be subsequently filled with byte data.

public FinByteBuffer()

FinByteBuffer(byte[])

Create a byte buffer with an initial content.

public FinByteBuffer(byte[] vbBytes)

Parameters

vbBytes byte[]

Byte array that holds the initial content.

Remarks

The FinByteBuffer only holds a reference to the given byte array and does not create a copy, yet. Thus any changes to the content of the provided byte array will be seen by the FinByteBuffer.

FinByteBuffer(byte[], int, int)

Create a byte buffer with an initial content.

public FinByteBuffer(byte[] vbBytes, int nOffset, int nLength)

Parameters

vbBytes byte[]

Byte array that holds the initial content.

nOffset int

Starting offset into the byte array where the content begins.

nLength int

Length of the content.

Remarks

The FinByteBuffer only holds a reference to the given byte array and does not create a copy, yet. Thus any changes to the content of the provided byte array will be seen by the FinByteBuffer.

FinByteBuffer(int)

Creates a completely empty byte buffer with a given initial capacity.

public FinByteBuffer(int nInitialCapacity)

Parameters

nInitialCapacity int

The initial capacity that shall be allocated for the new byte buffer. If this is zero, then nothing will be allocated now.

Properties

Bytes

Provides the byte array that is managed by this byte buffer.

public byte[] Bytes { get; }

Property Value

byte[]

Remarks

The actual significant data is just a portion of this array. The significant range of this array is defined through the Offset and Length properties.

Capacity

The current maximum capacity of this byte buffer that is available without causing a reallocation of the byte array.

public int Capacity { get; set; }

Property Value

int

Remarks

Reducing the capacity by setting this property is not possible and any attempt to do so will be ignored. Increasing the capacity will cause a reallocation any copy of the buffer byte array.

this[int]

Indexed access to the buffer bytes. The index always zero based, regardless of the actual Offset.

public byte this[int i] { get; set; }

Parameters

i int

Property Value

byte

Length

Provides or sets the count of significant bytes in this buffer.

public int Length { get; set; }

Property Value

int

The length may be zero but is never negative.

Remarks

It is possible to set the length in order to increase or decrease the amount of significant bytes in this buffer. Increasing the length will append zero bytes to the buffer.

Offset

Byte offset of the first significant byte in this buffer.

public int Offset { get; }

Property Value

int

Reserve

The amount of additional reserve capacity that allocated whenever the byte array has to be reallocated.

public int Reserve { get; set; }

Property Value

int

Methods

AppendByte(byte)

public void AppendByte(byte b)

Parameters

b byte

AppendByteArray(byte[])

Appends a sequence of bytes from a byte array to this byte buffer.

public void AppendByteArray(byte[] vbBytes)

Parameters

vbBytes byte[]

Byte array that holds the sequence of bytes to be appended to this byte buffer.

AppendByteArray(byte[], int, int)

Appends a sequence of bytes from a byte array to this byte buffer.

public void AppendByteArray(byte[] vbBytes, int nOffset, int nLength)

Parameters

vbBytes byte[]

Byte array that holds the sequence of bytes to be appended to this byte buffer.

nOffset int

Start offset of the sequence of bytes to be appened.

nLength int

Length of the sequence of bytes to be appened.

AppendByteBuffer(FinByteBuffer)

Appends another byte buffer to this byte buffer.

public void AppendByteBuffer(FinByteBuffer aByteBuffer)

Parameters

aByteBuffer FinByteBuffer

The byte buffer to be appended. Must not be null.

AppendByteStream(Stream, int)

Appends byte data from a byte stream to this byte buffer.

public int AppendByteStream(Stream aStream, int nLength)

Parameters

aStream Stream

Stream that provides the byte data to be appended to this byte buffer.

nLength int

Maximum number of bytes to read from the stream and append to this byte buffer. The byte buffer will be reallocated to have a capacity large enough to hold this amount. Thus it is not at all useful to pass Int32.MaxValue here.

Returns

int

Returns the actual number of bytes that have been read from the stream and appended to this byte buffer. This may be less than the requested nLength, if the stream was exhausted before nLength bytes could have been read. It may even be zero if the stream was exhausted from the very beginning.

AppendBytes(byte, int)

Fills with a given byte.

public void AppendBytes(byte b, int nCount)

Parameters

b byte
nCount int

AppendInteger(int, int)

Appends the binary representation of an integer.

public void AppendInteger(int i, int nLength)

Parameters

i int

The integer value to be appended.

nLength int

The number of bytes that shall be appended. This must be zero or a positove value.

Remarks

The bytes are always appended in little endian order, regardless of the plattform.

AppendString(string)

Appends the low order bytes of a string to this byte buffer.

public void AppendString(string s)

Parameters

s string

Clone()

Create a complete copy of this byte buffer.

public FinByteBuffer Clone()

Returns

FinByteBuffer

A new FinByteBuffer instance that is a complete copy of this buffer.

OpenRead()

Creates a read only stream over the content of this buffer.

public Stream OpenRead()

Returns

Stream

ToArray()

Creates a new byte array with a copy of the content of this byte buffer.

public byte[] ToArray()

Returns

byte[]

A newly allocated byte array with a copy of the content of this byte buffer. If this byte buffer is empty, then a zero sized byte array is returned.

ToString()

Converts the contents of this buffer to a String without any encoding.

public override string ToString()

Returns

string

Remarks

The returned string is created by simply casting each byte of the buffer to a character. This means that the upper byte of the returned Unicode string will always be zero.

ToString(Encoding)

Converts the contents of this buffer to a String using the given Encoding.

public string ToString(Encoding aEncoding)

Parameters

aEncoding Encoding

Returns

string