toBuffer static method

List<int> toBuffer(
  1. String uuidString, {
  2. bool validate = true,
})

Converts a UUID string to a binary buffer.

Parameters:

  • uuidString: The UUID string to convert to a binary buffer.

Implementation

static List<int> toBuffer(String uuidString, {bool validate = true}) {
  if (validate && !isValidUUIDv4(uuidString)) {
    throw ArgumentException.invalidOperationArguments(
      "toBuffer",
      name: "uuidString",
      reason: "Invalid UUID string.",
    );
  }
  final buffer = List<int>.filled(16, 0);

  /// Remove dashes and convert the hexadecimal string to bytes
  final cleanUuidString = uuidString.replaceAll('-', '');
  final bytes = BytesUtils.fromHexString(cleanUuidString);

  /// Copy the bytes into the buffer
  for (var i = 0; i < 16; i++) {
    buffer[i] = bytes[i];
  }

  return buffer;
}