parseRc1TrailerIfPresent function

int parseRc1TrailerIfPresent({
  1. required Uint8List data,
  2. required int start,
  3. required List<ParsedRowBuffer> out,
})

Implementation

int parseRc1TrailerIfPresent({
  required Uint8List data,
  required int start,
  required List<ParsedRowBuffer> out,
}) {
  if (data.length < start + 8) {
    return start;
  }
  final m = ByteData.sublistView(
    data,
    start,
    start + 4,
  ).getUint32(0, Endian.little);
  if (m != BinaryProtocolConstants.refCursorFooterMagic) {
    return start;
  }
  var p = start + 4;
  final nCursors =
      ByteData.sublistView(data, p, p + 4).getUint32(0, Endian.little);
  p += 4;
  for (var i = 0; i < nCursors; i++) {
    if (p + 4 > data.length) {
      throw const FormatException('RC1: truncated length prefix');
    }
    final bl = ByteData.sublistView(data, p, p + 4).getUint32(0, Endian.little);
    p += 4;
    if (p + bl > data.length) {
      throw const FormatException('RC1: truncated embedded message');
    }
    final inner = Uint8List.sublistView(data, p, p + bl);
    p += bl;
    out.add(parseRowMajorV1(inner));
  }
  return p;
}