fromBuffer static method

String fromBuffer(
  1. Uint8List buffer
)

Implementation

static String fromBuffer(Uint8List buffer) {
  if (buffer.length != 16) {
    throw Exception(
        'Invalid buffer length. UUIDv4 buffers must be 16 bytes long.');
  }

  final List<String> hexBytes =
      buffer.map((byte) => byte.toRadixString(16).padLeft(2, '0')).toList();

  // Insert dashes at appropriate positions to form a UUIDv4 string
  return '${hexBytes.sublist(0, 4).join('')}-${hexBytes.sublist(4, 6).join('')}-${hexBytes.sublist(6, 8).join('')}-${hexBytes.sublist(8, 10).join('')}-${hexBytes.sublist(10).join('')}';
}