You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
699 B
24 lines
699 B
7 years ago
|
/**
|
||
|
* Convert array of 16 byte values to UUID string format of the form:
|
||
|
* XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
|
||
|
*/
|
||
|
var byteToHex = [];
|
||
|
for (var i = 0; i < 256; ++i) {
|
||
|
byteToHex[i] = (i + 0x100).toString(16).substr(1);
|
||
|
}
|
||
|
|
||
|
function bytesToUuid(buf, offset) {
|
||
|
var i = offset || 0;
|
||
|
var bth = byteToHex;
|
||
|
return bth[buf[i++]] + bth[buf[i++]] +
|
||
|
bth[buf[i++]] + bth[buf[i++]] + '-' +
|
||
|
bth[buf[i++]] + bth[buf[i++]] + '-' +
|
||
|
bth[buf[i++]] + bth[buf[i++]] + '-' +
|
||
|
bth[buf[i++]] + bth[buf[i++]] + '-' +
|
||
|
bth[buf[i++]] + bth[buf[i++]] +
|
||
|
bth[buf[i++]] + bth[buf[i++]] +
|
||
|
bth[buf[i++]] + bth[buf[i++]];
|
||
|
}
|
||
|
|
||
|
module.exports = bytesToUuid;
|