Class TgoByteBuffer
Unit
Grijjy.SysUtils
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
Overview
Methods
|
constructor Create(const ACapacity: Integer = 256; const ADelta: Integer = 256); |
|
procedure Append(const AByte: Byte); overload; |
|
procedure Append(const ABytes: TBytes); overload; |
|
procedure Append(const ABytes: array of Byte); overload; |
|
procedure Append(const ABytes: TBytes; const AIndex: Integer); overload; |
|
procedure Append(const ABytes: array of Byte; const AIndex: Integer); overload; |
|
procedure Append(const ABytes: TBytes; const AIndex, ASize: Integer); overload; |
|
procedure Append(const ABytes: array of Byte; const AIndex, ASize: Integer); overload; |
|
procedure AppendBuffer(const ABuffer; const ASize: Integer); |
|
procedure Clear; |
|
procedure TrimExcess; |
|
function ToBytes: TBytes; |
Properties
|
property Capacity: Integer read FCapacity; |
|
property Size: Integer read FSize; |
|
property Buffer: TBytes read FBuffer; |
Description
Methods
|
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
|
|
procedure Append(const AByte: Byte); overload; |
Appends a single byte.
Parameters
- AByte
- the byte to append.
|
|
procedure Append(const ABytes: TBytes); overload; |
Appends an array of bytes.
Parameters
- ABytes
- the array of bytes to append.
|
|
procedure Append(const ABytes: array of Byte); overload; |
Appends an array of bytes.
Parameters
- ABytes
- the array of bytes to append.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
property Capacity: Integer read FCapacity; |
Current capacity (number of reserved bytes)
|
|
property Size: Integer read FSize; |
Current size of the buffer in bytes
|
|
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
|