messageLengthFromHeader static method
Returns total message length (header + payload) from the message header.
Supports v1 row-major and v2 columnar headers. data must contain at
least the full header for the detected version.
Implementation
static int messageLengthFromHeader(Uint8List data) {
if (data.length < 6) {
throw const FormatException('Buffer too small for version');
}
final byteData = ByteData.sublistView(data);
final version = byteData.getUint16(4, _littleEndian);
if (version == protocolVersionRowMajor) {
if (data.length < headerSizeV1) {
throw const FormatException('Buffer too small for header');
}
final payloadSize = byteData.getUint32(12, _littleEndian);
return headerSizeV1 + payloadSize;
}
if (version == protocolVersionColumnarV2) {
if (data.length < headerSizeColumnarV2) {
throw const FormatException('Buffer too small for columnar v2 header');
}
final payloadSize = byteData.getUint32(15, _littleEndian);
return headerSizeColumnarV2 + payloadSize;
}
throw FormatException('Unsupported protocol version: $version');
}