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) { function compareBuffers (a, b) {
if (a.byteLength != b.byteLength) { return false; } var ad = new DataView(a.buffer),
for (var i=0; i<a.length; i++) { bd = new DataView(b.buffer);
if (a[i] != b[i]) { return false;} 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; return true;
} }
async function load_key (key) { async function load_key (key) {
const db = await openDB(DB_NAME); const db = await openDB(DB_NAME);
var objectStore = db.transaction([DB_STORE], "readonly").objectStore(DB_STORE); var objectStore = db.transaction([DB_STORE], "readonly").objectStore(DB_STORE);
@ -102,6 +104,7 @@ async function load_key (key) {
//var cart_js = cart.tojson(); //var cart_js = cart.tojson();
//code.setValue(JSON.stringify(cart_js, null, 2)); //code.setValue(JSON.stringify(cart_js, null, 2));
var outputBuffer = cart.tobuffer(); var outputBuffer = cart.tobuffer();
console.log("buffers same", compareBuffers(inputBuffer, outputBuffer))
}); });
} }

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

Loading…
Cancel
Save