ProtocolByteAccumulator class
Single reusable buffer for incremental protocol framing.
Incoming stream chunks are appended once. take transfers ownership of the frame bytes (zero-copy view of the prior backing store) so callers that retain the frame (including lazy UTF-8 string cells) keep a live buffer. The accumulator allocates a fresh backing for later adds, preferring a small free-list of fixed-capacity buffers to cut GC under sustained streaming.
Constructors
- ProtocolByteAccumulator({int initialCapacity = 64 * 1024})
Properties
- bytesCopied → int
-
Bytes copied when growing or detaching pending buffered data.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- length → int
-
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
add(
Uint8List chunk) → void -
copyPrefix(
int count) → Uint8List - Copies only a header prefix without exposing the accumulator backing.
-
drop(
int count) → void -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
peek(
int count) → Uint8List -
take(
int count) → Uint8List -
Returns a view of the leading
countbytes and releases them from this accumulator. The returned list keeps the previous backing store alive. -
takeAfterPrefix(
int prefix, int count) → Uint8List - Consumes a header and returns a stable view of the payload.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- allocatedBackingBytes → int
-
Cumulative newly allocated backing bytes, excluding reused pool buffers.
no setter
- pooledBackingCount → int
-
Number of buffers currently held in free-lists (for tests).
no setter
- pooledDefaultBackingCount → int
-
Number of 64 KiB buffers in the default free-list (for tests).
no setter
- pooledLargeBackingCount → int
-
Number of 1 MiB buffers in the large free-list (for tests).
no setter
Static Methods
-
clearPoolForTest(
) → void - Clears free-lists (for tests).
-
offerDefaultBacking(
Uint8List buffer) → void - Alias kept for callers/tests that recycle default-capacity frames.
-
offerPooledBacking(
Uint8List buffer) → void - Offers a fixed-capacity empty buffer back to the matching free-list.
-
protectBacking(
Uint8List slice) → void - Compatibility helper. Every exposed backing is already protected.
-
retainFrame(
Uint8List slice) → Uint8List? - Compatibility helper. Views now own their backing without recycling.