Class TgoByteBuffer

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type TgoByteBuffer = class(TObject)

Description

Class representing a buffer of bytes, with methods to efficiently add data to the buffer.

Use this class to build up a buffer of bytes using (many) smaller appends. This is more efficient then concatenating multiple TBytes together.

Hierarchy

  • TObject
  • TgoByteBuffer

Overview

Methods

Public constructor Create(const ACapacity: Integer = 256; const ADelta: Integer = 256);
Public procedure Append(const AByte: Byte); overload;
Public procedure Append(const ABytes: TBytes); overload;
Public procedure Append(const ABytes: array of Byte); overload;
Public procedure Append(const ABytes: TBytes; const AIndex: Integer); overload;
Public procedure Append(const ABytes: array of Byte; const AIndex: Integer); overload;
Public procedure Append(const ABytes: TBytes; const AIndex, ASize: Integer); overload;
Public procedure Append(const ABytes: array of Byte; const AIndex, ASize: Integer); overload;
Public procedure AppendBuffer(const ABuffer; const ASize: Integer);
Public procedure Clear;
Public procedure TrimExcess;
Public function ToBytes: TBytes;

Properties

Public property Capacity: Integer read FCapacity;
Public property Size: Integer read FSize;
Public property Buffer: TBytes read FBuffer;

Description

Methods

Public constructor Create(const ACapacity: Integer = 256; const ADelta: Integer = 256);

Create a new byte buffer.

Parameters
ACapacity
(optional) initial capacity. Defaults to 256.
ADelta
(optional) number of bytes to increase capacity when buffer becomes to small. When ADelta is not a power of 2, it is adjusted to the next power of 2
Public procedure Append(const AByte: Byte); overload;

Appends a single byte.

Parameters
AByte
the byte to append.
Public procedure Append(const ABytes: TBytes); overload;

Appends an array of bytes.

Parameters
ABytes
the array of bytes to append.
Public procedure Append(const ABytes: array of Byte); overload;

Appends an array of bytes.

Parameters
ABytes
the array of bytes to append.
Public procedure Append(const ABytes: TBytes; const AIndex: Integer); overload;

Appends a segment of an array of bytes.

Parameters
ABytes
the array of bytes containing the segment to append.
AIndex
index into ABytes of the start of the segment. The segment runs until the end of the ABytes array. If the index is invalid, nothing happens.
Public procedure Append(const ABytes: array of Byte; const AIndex: Integer); overload;

Appends a segment of an array of bytes.

Parameters
ABytes
the array of bytes containing the segment to append.
AIndex
index into ABytes of the start of the segment. The segment runs until the end of the ABytes array. If the index is invalid, nothing happens.
Public procedure Append(const ABytes: TBytes; const AIndex, ASize: Integer); overload;

Appends a segment of an array of bytes.

Parameters
ABytes
the array of bytes containing the segment to append.
AIndex
index into ABytes of the start of the segment. If the index is invalid, nothing happens.
ASize
the number of bytes in the segment to append. If the size exceeds beyond the end of the ABytes array, then it will be adjust to fit.
Public procedure Append(const ABytes: array of Byte; const AIndex, ASize: Integer); overload;

Appends a segment of an array of bytes.

Parameters
ABytes
the array of bytes containing the segment to append.
AIndex
index into ABytes of the start of the segment. If the index is invalid, nothing happens.
ASize
the number of bytes in the segment to append. If the size exceeds beyond the end of the ABytes array, then it will be adjust to fit.
Public procedure AppendBuffer(const ABuffer; const ASize: Integer);

Appends an untyped memory buffer.

Parameters
ABuffer
untyped memory buffer with the data to append.
ASize
the number of bytes in buffer to append.
Public procedure Clear;

Clears the buffer. This does not free the memory for the buffer, so subsequent appends will use the already allocated memory.

To free the memory for the buffer, free the object or call TrimExcess after clearing the buffer.

Public procedure TrimExcess;

Sets the capacity to the used number of bytes, reducing memory to the minimum required. Call this after calling Clear to completely release all memory.

Public function ToBytes: TBytes;

Returns the buffer as a byte array.

For performance reasons, this method does not make a copy. Instead it calls TrimExcess and returns the internal buffer. This means that any changes you make to bytes in the returned buffer, will also affect this buffer object.

Properties

Public property Capacity: Integer read FCapacity;

Current capacity (number of reserved bytes)

Public property Size: Integer read FSize;

Current size of the buffer in bytes

Public property Buffer: TBytes read FBuffer;

Provides direct access to the buffer. Note that this value can change as you append to the buffer. So you should generally use ToBytes instead.


Generated by P2PasDoc 0.13.0 on 2017-04-25 12:54:26