readBytesAsView method

Uint8List readBytesAsView()

Read a length-delimited field as a view of the CodedBufferReader's buffer. When storing the returned value directly (instead of e.g. parsing it as a UTF-8 string and copying) use readBytes instead to avoid holding on to the whole message, or copy the returned view.

Implementation

@pragma('vm:prefer-inline')
@pragma('wasm:prefer-inline')
Uint8List readBytesAsView() {
  final length = readInt32();
  _checkLimit(length);
  return Uint8List.view(
    _buffer.buffer,
    _buffer.offsetInBytes + _bufferPos - length,
    length,
  );
}