decodeProtocolCell function
Converts binary cell data to a Dart value based on the protocol discriminant.
Implementation
Object? decodeProtocolCell(Uint8List data, int odbcType) {
final type = OdbcType.fromDiscriminant(odbcType);
if (type == OdbcType.binary) {
return data;
}
if (type == OdbcType.integer) {
if (data.length >= 4) {
return readInt32Le(data);
}
return decodeProtocolText(data);
}
if (type == OdbcType.bigInt) {
if (data.length >= 8) {
return readInt64Le(data);
}
return decodeProtocolText(data);
}
if (type == OdbcType.float || type == OdbcType.doublePrecision) {
// Dual-support: prefer ASCII float text (incl. "Infinity"/"NaN"), then
// 8-byte LE IEEE-754 from native cell_reader / block_fetch.
final parsed = tryParseAsciiFloat64(data);
if (parsed != null) {
return parsed;
}
if (data.length == 8) {
return ByteData.sublistView(data).getFloat64(0, Endian.little);
}
return decodeProtocolText(data);
}
if (type == OdbcType.boolean) {
// Dual-support: single 0/1 byte or ASCII bool text.
if (data.length == 1 && (data[0] == 0 || data[0] == 1)) {
return data[0] == 1;
}
final parsed = tryParseAsciiBool(data);
if (parsed != null) {
return parsed;
}
return decodeProtocolText(data);
}
if (type == OdbcType.smallInt) {
final parsed = tryParseAsciiInt(data);
if (parsed != null) {
return parsed;
}
return decodeProtocolText(data);
}
if (type == OdbcType.date ||
type == OdbcType.timestamp ||
type == OdbcType.timestampWithTz ||
type == OdbcType.datetimeOffset ||
type == OdbcType.time) {
final parsed = tryParseAsciiDateTime(data);
if (parsed != null) {
return parsed;
}
return decodeProtocolText(data);
}
return decodeProtocolText(data);
}