deserialize static method

StructuredError? deserialize(
  1. List<int> data
)

Deserializes a StructuredError from binary data.

The data must contain at least 13 bytes: 5 bytes for SQLSTATE, 4 bytes for native code, 4 bytes for message length, followed by the UTF-8 encoded message.

Returns null if the data is invalid or too short.

Implementation

static StructuredError? deserialize(List<int> data) {
  if (data.length < 13) {
    return null;
  }

  final sqlState = data.sublist(0, 5);

  final byteData = ByteData.sublistView(Uint8List.fromList(data));
  final nativeCode = byteData.getInt32(5, Endian.little);
  final msgLen = byteData.getUint32(9, Endian.little);

  if (data.length < 13 + msgLen) {
    return null;
  }

  final message = utf8.decode(data.sublist(13, 13 + msgLen));

  return StructuredError(
    sqlState: sqlState,
    nativeCode: nativeCode,
    message: message,
  );
}