2014-01-28 16:38:02 +00:00
|
|
|
/* [MS-XLSB] 2.1.4 Record */
|
2014-06-29 18:29:45 +00:00
|
|
|
function recordhopper(data, cb, opts) {
|
2014-01-29 06:00:09 +00:00
|
|
|
var tmpbyte, cntbyte, length;
|
2014-01-28 16:38:02 +00:00
|
|
|
prep_blob(data, data.l || 0);
|
|
|
|
while(data.l < data.length) {
|
|
|
|
var RT = data.read_shift(1);
|
|
|
|
if(RT & 0x80) RT = (RT & 0x7F) + ((data.read_shift(1) & 0x7F)<<7);
|
|
|
|
var R = RecordEnum[RT] || RecordEnum[0xFFFF];
|
2014-02-12 06:09:42 +00:00
|
|
|
tmpbyte = data.read_shift(1);
|
|
|
|
length = tmpbyte & 0x7F;
|
2014-01-28 16:38:02 +00:00
|
|
|
for(cntbyte = 1; cntbyte <4 && (tmpbyte & 0x80); ++cntbyte) length += ((tmpbyte = data.read_shift(1)) & 0x7F)<<(7*cntbyte);
|
2014-02-13 06:22:42 +00:00
|
|
|
var d = R.f(data, length, opts);
|
2014-01-31 11:52:18 +00:00
|
|
|
if(cb(d, R, RT)) return;
|
2014-01-28 16:38:02 +00:00
|
|
|
}
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2014-05-16 00:33:34 +00:00
|
|
|
|
|
|
|
/* control buffer usage for fixed-length buffers */
|
2014-06-29 18:29:45 +00:00
|
|
|
function buf_array() {
|
2014-05-29 22:30:03 +00:00
|
|
|
var bufs = [], blksz = 2048;
|
2014-06-29 18:29:45 +00:00
|
|
|
var newblk = function ba_newblk(sz) {
|
|
|
|
var o = new_buf(sz);
|
|
|
|
prep_blob(o, 0);
|
2014-05-29 22:30:03 +00:00
|
|
|
return o;
|
|
|
|
};
|
|
|
|
|
2014-06-29 18:29:45 +00:00
|
|
|
var curbuf = newblk(blksz);
|
2014-05-29 22:30:03 +00:00
|
|
|
|
2014-06-29 18:29:45 +00:00
|
|
|
var endbuf = function ba_endbuf() {
|
2014-05-29 22:30:03 +00:00
|
|
|
curbuf.length = curbuf.l;
|
|
|
|
if(curbuf.length > 0) bufs.push(curbuf);
|
|
|
|
curbuf = null;
|
|
|
|
};
|
|
|
|
|
2014-06-29 18:29:45 +00:00
|
|
|
var next = function ba_next(sz) {
|
2014-05-29 22:30:03 +00:00
|
|
|
if(sz < curbuf.length - curbuf.l) return curbuf;
|
|
|
|
endbuf();
|
|
|
|
return (curbuf = newblk(Math.max(sz+1, blksz)));
|
|
|
|
};
|
|
|
|
|
2014-06-29 18:29:45 +00:00
|
|
|
var end = function ba_end() {
|
2014-05-29 22:30:03 +00:00
|
|
|
endbuf();
|
|
|
|
return __toBuffer([bufs]);
|
|
|
|
};
|
|
|
|
|
2014-06-29 18:29:45 +00:00
|
|
|
var push = function ba_push(buf) { endbuf(); curbuf = buf; next(blksz); };
|
2014-05-29 22:30:03 +00:00
|
|
|
|
|
|
|
return { next:next, push:push, end:end, _bufs:bufs };
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2014-05-29 22:30:03 +00:00
|
|
|
|
2014-06-29 18:29:45 +00:00
|
|
|
function write_record(ba, type, payload, length) {
|
2014-05-29 22:30:03 +00:00
|
|
|
var t = evert_RE[type], l;
|
|
|
|
if(!length) length = RecordEnum[t].p || (payload||[]).length || 0;
|
|
|
|
l = 1 + (t >= 0x80 ? 1 : 0) + 1 + length;
|
|
|
|
if(length >= 0x80) ++l; if(length >= 0x4000) ++l; if(length >= 0x200000) ++l;
|
|
|
|
var o = ba.next(l);
|
|
|
|
if(t <= 0x7F) o.write_shift(1, t);
|
|
|
|
else {
|
|
|
|
o.write_shift(1, (t & 0x7F) + 0x80);
|
|
|
|
o.write_shift(1, (t >> 7));
|
|
|
|
}
|
|
|
|
for(var i = 0; i != 4; ++i) {
|
|
|
|
if(length >= 0x80) { o.write_shift(1, (length & 0x7F)+0x80); length >>= 7; }
|
|
|
|
else { o.write_shift(1, length); break; }
|
|
|
|
}
|
|
|
|
if(length > 0 && is_buf(payload)) ba.push(payload);
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|