fillColumnarRowsIntoRowBuffer function

void fillColumnarRowsIntoRowBuffer({
  1. required int odbcType,
  2. required Uint8List raw,
  3. required int columnIndex,
  4. required List<List> rows,
})

Implementation

void fillColumnarRowsIntoRowBuffer({
  required int odbcType,
  required Uint8List raw,
  required int columnIndex,
  required List<List<dynamic>> rows,
}) {
  final odbc = OdbcType.fromDiscriminant(odbcType);
  final bd = ByteData.sublistView(raw);
  var p = 0;
  final rowCount = rows.length;
  for (var i = 0; i < rowCount; i++) {
    if (p >= raw.length) {
      throw const FormatException('Columnar v2: row cells truncated');
    }
    if (odbc == OdbcType.integer) {
      final n = raw[p++];
      if (n == 1) {
        rows[i][columnIndex] = null;
      } else {
        if (p + 4 > raw.length) {
          throw const FormatException('Columnar v2: int cell truncated');
        }
        rows[i][columnIndex] = bd.getInt32(p, _littleEndian);
        p += 4;
      }
    } else if (odbc == OdbcType.bigInt) {
      final n = raw[p++];
      if (n == 1) {
        rows[i][columnIndex] = null;
      } else {
        if (p + 8 > raw.length) {
          throw const FormatException('Columnar v2: bigint cell truncated');
        }
        rows[i][columnIndex] = bd.getInt64(p, _littleEndian);
        p += 8;
      }
    } else {
      final n = raw[p++];
      if (n == 1) {
        rows[i][columnIndex] = null;
      } else {
        if (p + 4 > raw.length) {
          throw const FormatException('Columnar v2: varchar len truncated');
        }
        final bl = bd.getUint32(p, _littleEndian);
        p += 4;
        if (p + bl > raw.length) {
          throw const FormatException('Columnar v2: varchar data truncated');
        }
        final bytes = Uint8List.sublistView(raw, p, p + bl);
        p += bl;
        rows[i][columnIndex] = decodeProtocolCell(bytes, odbcType);
      }
    }
  }
  if (p != raw.length) {
    throw const FormatException('Columnar v2: raw not fully consumed');
  }
}