2 lines
9.0 KiB
JavaScript
2 lines
9.0 KiB
JavaScript
|
|
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):(t="undefined"!=typeof globalThis?globalThis:t||self).Pbf=i()}(this,(function(){"use strict";const t=4294967296,i=1/t,e="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8");function s(t,i,e){return e?4294967296*i+(t>>>0):4294967296*(i>>>0)+(t>>>0)}function r(t,i,e){const s=i<=16383?1:i<=2097151?2:i<=268435455?3:Math.floor(Math.log(i)/(7*Math.LN2));e.realloc(s);for(let i=e.pos-1;i>=t;i--)e.buf[i+s]=e.buf[i]}function o(t,i){for(let e=0;e<t.length;e++)i.writeVarint(t[e])}function h(t,i){for(let e=0;e<t.length;e++)i.writeSVarint(t[e])}function n(t,i){for(let e=0;e<t.length;e++)i.writeFloat(t[e])}function a(t,i){for(let e=0;e<t.length;e++)i.writeDouble(t[e])}function d(t,i){for(let e=0;e<t.length;e++)i.writeBoolean(t[e])}function l(t,i){for(let e=0;e<t.length;e++)i.writeFixed32(t[e])}function u(t,i){for(let e=0;e<t.length;e++)i.writeSFixed32(t[e])}function f(t,i){for(let e=0;e<t.length;e++)i.writeFixed64(t[e])}function p(t,i){for(let e=0;e<t.length;e++)i.writeSFixed64(t[e])}return class{constructor(t=new Uint8Array(16)){this.buf=ArrayBuffer.isView(t)?t:new Uint8Array(t),this.dataView=new DataView(this.buf.buffer),this.pos=0,this.type=0,this.length=this.buf.length}readFields(t,i,e=this.length){for(;this.pos<e;){const e=this.readVarint(),s=e>>3,r=this.pos;this.type=7&e,t(s,i,this),this.pos===r&&this.skip(e)}return i}readMessage(t,i){return this.readFields(t,i,this.readVarint()+this.pos)}readFixed32(){const t=this.dataView.getUint32(this.pos,!0);return this.pos+=4,t}readSFixed32(){const t=this.dataView.getInt32(this.pos,!0);return this.pos+=4,t}readFixed64(){const i=this.dataView.getUint32(this.pos,!0)+this.dataView.getUint32(this.pos+4,!0)*t;return this.pos+=8,i}readSFixed64(){const i=this.dataView.getUint32(this.pos,!0)+this.dataView.getInt32(this.pos+4,!0)*t;return this.pos+=8,i}readFloat(){const t=this.dataView.getFloat32(this.pos,!0);return this.pos+=4,t}readDouble(){const t=this.dataView.getFloat64(this.pos,!0);return this.pos+=8,t}readVarint(t){const i=this.buf;let e,r;return r=i[this.pos++],e=127&r,r<128?e:(r=i[this.pos++],e|=(127&r)<<7,r<128?e:(r=i[this.pos++],e|=(127&r)<<14,r<128?e:(r=i[this.pos++],e|=(127&r)<<21,r<128?e:(r=i[this.pos],e|=(15&r)<<28,function(t,i,e){const r=e.buf;let o,h;if(h=r[e.pos++],o=(112&h)>>4,h<128)return s(t,o,i);if(h=r[e.pos++],o|=(127&h)<<3,h<128)return s(t,o,i);if(h=r[e.pos++],o|=(127&h)<<10,h<128)return s(t,o,i);if(h=r[e.pos++],o|=(127&h)<<17,h<128)return s(t,o,i);if(h=r[e.pos++],o|=(127&h)<<24,h<128)return s(t,o,i);if(h=r[e.pos++],o|=(1&h)<<31,h<128)return s(t,o,i);throw new Error("Expected varint not more than 10 bytes")}(e,t,this)))))}readVarint64(){return this.readVarint(!0)}readSVarint(){const t=this.readVarint();return t%2==1?(t+1)/-2:t/2}readBoolean(){return Boolean(this.readVarint())}readString(){const t=this.readVarint()+this.pos,i=this.pos;return this.pos=t,t-i>=12&&e?e.decode(this.buf.subarray(i,t)):function(t,i,e){let s="",r=i;for(;r<e;){const i=t[r];let o,h,n,a=null,d=i>239?4:i>223?3:i>191?2:1;if(r+d>e)break;1===d?i<128&&(a=i):2===d?(o=t[r+1],128==(192&o)&&(a=(31&i)<<6|63&o,a<=127&&(a=null))):3===d?(o=t[r+1],h=t[r+2],128==(192&o)&&128==(192&h)&&(a=(15&i)<<12|(63&o)<<6|63&h,(a<=2047||a>=55296&&a<=57343)&&(a=null))):4===d&&(o=t[r+1],h=t[r+2],n=t[r+3],128==(192&o)&&128==(192&h)&&128==(192&n)&&(a=(15&i)<<18|(63&o)<<12|(63&h)<<6|63&n,(a<=65535||a>=1114112)&&(a=null))),null===a?(a=65533,d=1):a>65535&&(a-=65536,s+=String.fromCharCode(a>>>10&1023|55296),a=56320|1023&a),s+=String.fromCharCode(a),r+=d}return s}(this.buf,i,t)}readBytes(){const t=this.readVarint()+this.pos,i=this.buf.subarray(this.pos,t);return this.pos=t,i}readPackedVarint(t=[],i){const e=this.readPackedEnd();for(;this.pos<e;)t.push(this.readVarint(i));return t}readPackedSVarint(t=[]){const i=this.readPackedEnd();for(;this.pos<i;)t.push(this.readSVarint());return t}readPackedBoolean(t=[]){const i=this.readPackedEnd();for(;this.pos<i;)t.push(this.readBoolean());return t}readPackedF
|