Member 10047337
Я нашел решение, и ниже приведены коды и ссылка на случай, если у кого-то еще возникнет такой же вопрос. Я добавляю немного в код, чтобы разделить и объединить вывод, чтобы он соответствовал моим потребностям.
Первоначальный поставщик
идентификатор GUID/javascriptGuid мастер · dalaqa/идентификатор GUID · на GitHub[^]
FormatByteArrayToGuidString = function (b) {
//@ Made by Zura Dalakishvili, Tbilisi, Georgia 2016
//Guid representation created from byte[] array for Javascript
// Usage:
// var inst = new Guid(array);
// var guidStr = inst.guidString;
var _a;
var _b;
var _c;
var _d;
var _e;
var _f;
var _g;
var _h;
var _i;
var _j;
var _k;
if (b == null)
return;
if (b.length != 16)
return;
_a = ((b[3]) << 24) | ((b[2]) << 16) | ((b[1]) << 8) | b[0];
_b = (((b[5]) << 8) | b[4]);
_c = (((b[7]) << 8) | b[6]);
_d = b[8];
_e = b[9];
_f = b[10];
_g = b[11];
_h = b[12];
_i = b[13];
_j = b[14];
_k = b[15];
function HexToChar(a) {
a = a & 0xf;
return String.fromCharCode(((a > 9) ? a - 10 + 0x61 : a + 0x30));
}
function HexsToChars(guidChars, offset, a, b) {
return HexsToChars(guidChars, offset, a, b, false);
}
function HexsToChars(guidChars, offset, a, b, hex) {
if (hex) {
guidChars[offset++] = '0';
guidChars[offset++] = 'x';
}
guidChars[offset++] = HexToChar(a >> 4);
guidChars[offset++] = HexToChar(a);
if (hex) {
guidChars[offset++] = ',';
guidChars[offset++] = '0';
guidChars[offset++] = 'x';
}
guidChars[offset++] = HexToChar(b >> 4);
guidChars[offset++] = HexToChar(b);
return offset;
}
this.b = b;
//_toGUID(this.b);
var _toString = function (format, provider) {
if (format == null || format.length == 0)
format = "D";
var guidChars = new Array();
var offset = 0;
var strLength = 38;
var dash = true;
var hex = false;
if (format.length != 1) {
// all acceptable format strings are of length 1
return null;
}
var formatCh = format[0];
if (formatCh == 'D' || formatCh == 'd') {
guidChars = new Array(36);
strLength = 36;
} else if (formatCh == 'N' || formatCh == 'n') {
guidChars = new Array(32);
strLength = 32;
dash = false;
} else if (formatCh == 'B' || formatCh == 'b') {
guidChars = new Array(38);
guidChars[offset++] = '{';
guidChars[37] = '}';
} else if (formatCh == 'P' || formatCh == 'p') {
guidChars = new Array(38);
guidChars[offset++] = '(';
guidChars[37] = ')';
} else if (formatCh == 'X' || formatCh == 'x') {
guidChars = new Array(68);
guidChars[offset++] = '{';
guidChars[67] = '}';
strLength = 68;
dash = false;
hex = true;
} else {
return null;
}
if (hex) {
// {0xdddddddd,0xdddd,0xdddd,{0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd}}
guidChars[offset++] = '0';
guidChars[offset++] = 'x';
offset = HexsToChars(guidChars, offset, _a >> 24, _a >> 16);
offset = HexsToChars(guidChars, offset, _a >> 8, _a);
guidChars[offset++] = ',';
guidChars[offset++] = '0';
guidChars[offset++] = 'x';
offset = HexsToChars(guidChars, offset, _b >> 8, _b);
guidChars[offset++] = ',';
guidChars[offset++] = '0';
guidChars[offset++] = 'x';
offset = HexsToChars(guidChars, offset, _c >> 8, _c);
guidChars[offset++] = ',';
guidChars[offset++] = '{';
offset = HexsToChars(guidChars, offset, _d, _e, true);
guidChars[offset++] = ',';
offset = HexsToChars(guidChars, offset, _f, _g, true);
guidChars[offset++] = ',';
offset = HexsToChars(guidChars, offset, _h, _i, true);
guidChars[offset++] = ',';
offset = HexsToChars(guidChars, offset, _j, _k, true);
guidChars[offset++] = '}';
} else {
// [{|(]dddddddd[-]dddd[-]dddd[-]dddd[-]dddddddddddd[}|)]
offset = HexsToChars(guidChars, offset, _a >> 24, _a >> 16);
offset = HexsToChars(guidChars, offset, _a >> 8, _a);
if (dash) guidChars[offset++] = '-';
offset = HexsToChars(guidChars, offset, _b >> 8, _b);
if (dash) guidChars[offset++] = '-';
offset = HexsToChars(guidChars, offset, _c >> 8, _c);
if (dash) guidChars[offset++] = '-';
offset = HexsToChars(guidChars, offset, _d, _e);
if (dash) guidChars[offset++] = '-';
offset = HexsToChars(guidChars, offset, _f, _g);
offset = HexsToChars(guidChars, offset, _h, _i);
offset = HexsToChars(guidChars, offset, _j, _k);
}
return new String(guidChars);
}
this.guidString = function () {
return _toString('D', null).split(',').join('');
}
return this.guidString();
}