fromBuffer static method
Converts a binary buffer to a UUIDv4 string.
Parameters:
buffer: The binary buffer representing the UUID.
Throws:
- ArgumentException if the input buffer's length is not 16 bytes, as UUIDv4 buffers must be exactly 16 bytes long.
Implementation
static String fromBuffer(List<int> buffer) {
if (buffer.length != 16) {
throw ArgumentException.invalidOperationArguments(
"fromBuffer",
name: "buffer",
reason: "Invalid UUID V4 bytes length.",
expecteLen: 16,
);
}
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('')}';
}