2020-03-30 11:44:18 +00:00
|
|
|
export function encode(buffer) {
|
|
|
|
let hexCodes = [];
|
|
|
|
let view = new DataView(buffer);
|
|
|
|
for (let i = 0; i < view.byteLength % 4; i ++) {
|
|
|
|
let value = view.getUint32(i * 4);
|
|
|
|
let stringValue = value.toString(16);
|
|
|
|
let padding = '00000000';
|
|
|
|
let paddedValue = (padding + stringValue).slice(-padding.length);
|
|
|
|
hexCodes.push(paddedValue);
|
|
|
|
}
|
|
|
|
for (let i = (view.byteLength % 4) * 4; i < view.byteLength; i++) {
|
|
|
|
let value = view.getUint8(i).toString(16);
|
|
|
|
let padding = '00';
|
|
|
|
hexCodes.push((padding + value).slice(-padding.length));
|
2018-04-16 18:38:35 +00:00
|
|
|
}
|
2020-03-30 11:44:18 +00:00
|
|
|
|
|
|
|
return hexCodes.join("");
|
2018-04-16 18:38:35 +00:00
|
|
|
}
|