function t(r,f){f<251?r.end++:f<256?r.end+=2:f<65536?r.end+=3:f<16777216?r.end+=4:f<4294967296?r.end+=5:(r.end++,t(r,Math.floor(Math.log(f)/Math.log(2))-32),r.end+=6)}function r(t,f){const e=f-251;if(f<251)t.buffer[t.start++]=f;else if(f<256)t.buffer[t.start++]=251,t.buffer[t.start++]=e;else if(f<65536)t.buffer[t.start++]=252,t.buffer[t.start++]=e>>8&255,t.buffer[t.start++]=255&e;else if(f<16777216)t.buffer[t.start++]=253,t.buffer[t.start++]=e>>16,t.buffer[t.start++]=e>>8&255,t.buffer[t.start++]=255&e;else if(f<4294967296)t.buffer[t.start++]=254,t.buffer[t.start++]=e>>24,t.buffer[t.start++]=e>>16&255,t.buffer[t.start++]=e>>8&255,t.buffer[t.start++]=255&e;else{const f=Math.floor(Math.log(e)/Math.log(2))-32;t.buffer[t.start++]=255,r(t,f);const s=e/Math.pow(2,f-11);for(let r=5;r>=0;r--)t.buffer[t.start++]=s/Math.pow(2,8*r)&255}}function f(t){const r=251;if(t.end-t.start<1)throw new Error("Out of bounds");const e=t.buffer[t.start++];if(e<r)return e;if(t.end-t.start<e-r+1)throw new Error("Out of bounds.");if(e<252)return t.buffer[t.start++]+r;if(e<253)return(t.buffer[t.start++]<<8)+t.buffer[t.start++]+r;if(e<254)return(t.buffer[t.start++]<<16)+(t.buffer[t.start++]<<8)+t.buffer[t.start++]+r;if(e<255)return 16777216*t.buffer[t.start++]+(t.buffer[t.start++]<<16)+(t.buffer[t.start++]<<8)+t.buffer[t.start++]+r;const s=f(t);if(t.end-t.start<6)throw new Error("Out of bounds");let u=0;for(let r=5;r>=0;r--)u+=t.buffer[t.start++]*Math.pow(2,8*r);return u*Math.pow(2,s-11)+r}module.exports={preencode:t,encode:r,decode:f};