bufferedBytes property

int get bufferedBytes

What this message weighs while it is held in a queue, in bytes.

One home for the rule, because every transport buffers these and each would otherwise repeat it — notably RpcBufferedBroadcastController.sizeOf.

A directPayload weighs nothing: it is a reference to an object this process already owns, so queuing it costs a pointer, not its contents.

METADATA COUNTS. "Small and bounded by the header limits" holds per frame and fails in aggregate — maxMetadataBytes defaults to 64 KiB, so a queue bounded on event count alone admits thousands of metadata-only frames that weigh nothing and retain hundreds of megabytes.

Implementation

int get bufferedBytes {
  var total = payload?.length ?? 0;
  final m = metadata;
  if (m != null) {
    // Characters alone are not what a header costs. `name.length +
    // value.length` is right for a few large headers and badly wrong for many
    // small ones -- ["h1","v1"] weighs 4 and retains about a hundred bytes --
    // and many small ones is the shape a hostile peer picks, so each header
    // carries a fixed retention charge on top of its text.
    for (final h in m.headers) {
      total += h.name.length + h.value.length + _perHeaderOverheadBytes;
    }
  }
  return total;
}