deal with both int8 and uint8 buffers

master
Michael Murtaugh 3 years ago
parent e098eeef3b
commit b1740a4f12

File diff suppressed because one or more lines are too long

@ -78,13 +78,15 @@ thead.selectAll("th").data(["name", "size", "time", " "]).enter().append("t
})()
function compareBuffers (a, b) {
if (a.byteLength != b.byteLength) { return false; }
for (var i=0; i<a.length; i++) {
if (a[i] != b[i]) { return false;}
var ad = new DataView(a.buffer),
bd = new DataView(b.buffer);
if (ad.byteLength != bd.byteLength) { return false; }
for (var i=0; i<ad.byteLength; i++) {
if (ad.getUint8(i, 1) != bd.getUint8(i, 1)) { return false;}
}
return true;
}
async function load_key (key) {
const db = await openDB(DB_NAME);
var objectStore = db.transaction([DB_STORE], "readonly").objectStore(DB_STORE);
@ -102,6 +104,7 @@ async function load_key (key) {
//var cart_js = cart.tojson();
//code.setValue(JSON.stringify(cart_js, null, 2));
var outputBuffer = cart.tobuffer();
console.log("buffers same", compareBuffers(inputBuffer, outputBuffer))
});
}

@ -42,27 +42,29 @@ function tohex (a) {
// }
export function parsetic (buf) {
if (!(buf instanceof Uint8Array)) {
console.log("ERROR buf is not UInt8Array");
return;
}
// if (!(buf instanceof Uint8Array)) {
// console.log("ERROR buf is not UInt8Array");
// return;
// }
var ret = {},
data = new DataView(buf.buffer),
i=0,
bank,
ctype,
clen,
future_use;
future_use,
firstbyte;
ret.chunks = [];
ret.chunks_by_type = {};
while (i<buf.length) {
bank = buf[i] >> 5;
ctype = buf[i] & 0b11111;
firstbyte = data.getUint8(i, LITTLE_ENDIAN);
bank = firstbyte >> 5;
ctype = firstbyte & 0b11111;
i+=1;
clen = data.getUint16(i, LITTLE_ENDIAN);
i+=2;
future_use = buf[i];
future_use = data.getUint8(i, LITTLE_ENDIAN);
i+=1; // byte reserved for future_use
var chunk = {bank: bank, ctype: ctype, future_use: future_use};
chunk.original_length = clen; // can be out of sync with data, only for control purposes

Loading…
Cancel
Save