Socket
Socket
Sign inDemoInstall

tsbuffer

Package Overview
Dependencies
Maintainers
1
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tsbuffer - npm Package Compare versions

Comparing version 1.3.6 to 1.3.7

2

index.js

@@ -1,1 +0,1 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),require("k8w-extend-native");var LengthType,tsbufferValidator=require("tsbuffer-validator"),__assign=function(){return(__assign=Object.assign||function(e){for(var t,r=1,i=arguments.length;r<i;r++)for(var n in t=arguments[r])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e}).apply(this,arguments)},Config={interface:{maxExtendsNum:9}},Varint64=function(){function s(e,t,r){this.uint32s=new Uint32Array([e,t]),void 0!==r&&(this._byteLength=r)}return s.from=function(e){if(0===e)return this.Zero;var t=e<0;t&&(e=-e);var r=e>>>0,i=(e-r)/4294967296>>>0;return t&&(i=~i>>>0,r=~r>>>0,4294967295<++r&&(r=0,4294967295<++i&&(i=0))),new s(i,r)},s.prototype.toNumber=function(e){if(!e&&this.uint32s[0]>>>31){var t=1+~this.uint32s[1]>>>0,r=~this.uint32s[0]>>>0;return t||(r=r+1>>>0),-(t+4294967296*r)}return this.uint32s[1]+4294967296*this.uint32s[0]},s.prototype.zzEncode=function(){var e=this.uint32s[0]>>31;return this.uint32s[0]=((this.uint32s[0]<<1|this.uint32s[1]>>>31)^e)>>>0,this.uint32s[1]=(this.uint32s[1]<<1^e)>>>0,this},s.prototype.zzDecode=function(){var e=-(1&this.uint32s[1]);return this.uint32s[1]=((this.uint32s[1]>>>1|this.uint32s[0]<<31)^e)>>>0,this.uint32s[0]=(this.uint32s[0]>>>1^e)>>>0,this},Object.defineProperty(s.prototype,"byteLength",{get:function(){var e,t,r;return void 0===this._byteLength&&(e=this.uint32s[1],t=(this.uint32s[1]>>>28|this.uint32s[0]<<4)>>>0,r=this.uint32s[0]>>>24,this._byteLength=0==r?0==t?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:r<128?9:10),this._byteLength},enumerable:!1,configurable:!0}),s.prototype.writeToBuffer=function(e,t){for(;this.uint32s[0];)e[t++]=127&this.uint32s[1]|128,this.uint32s[1]=(this.uint32s[1]>>>7|this.uint32s[0]<<25)>>>0,this.uint32s[0]>>>=7;for(;127<this.uint32s[1];)e[t++]=127&this.uint32s[1]|128,this.uint32s[1]=this.uint32s[1]>>>7;return e[t++]=this.uint32s[1],t},s.readFromBuffer=function(e,t){var r=t,i=0,n=0,a=0;if(!(4<e.byteLength-t)){for(;a<3;++a){if(t>=e.byteLength)throw new Error("Read varint error: index out of range");if(n=(n|(127&e[t])<<7*a)>>>0,e[t++]<128)return new s(i,n,t-r)}return new s(i,n=(n|(127&e[t++])<<7*a)>>>0,t-r)}for(;a<4;++a)if(n=(n|(127&e[t])<<7*a)>>>0,e[t++]<128)return new s(i,n,t-r);if(n=(n|(127&e[t])<<28)>>>0,i=(i|(127&e[t])>>4)>>>0,e[t++]<128)return new s(i,n,t-r);if(a=0,4<e.byteLength-t){for(;a<5;++a)if(i=(i|(127&e[t])<<7*a+3)>>>0,e[t++]<128)return new s(i,n,t-r)}else for(;a<5;++a){if(t>=e.byteLength)throw new Error("Read varint error: index out of range");if(i=(i|(127&e[t])<<7*a+3)>>>0,e[t++]<128)return new s(i,n,t-r)}throw Error("invalid varint encoding")},s.Zero=new s(0,0),s}(),TypedArrays={Int8Array:Int8Array,Int16Array:Int16Array,Int32Array:Int32Array,Uint8Array:Uint8Array,Uint16Array:Uint16Array,Uint32Array:Uint32Array,Float32Array:Float32Array,Float64Array:Float64Array},IdBlockUtil=function(){function e(){}return e.getPayloadLengthInfo=function(e){switch(e.type){case"Boolean":case"Enum":return{lengthType:LengthType.Varint};case"Number":return!e.scalarType||e.scalarType.includes("64")||"double"===e.scalarType?{lengthType:LengthType.Bit64}:e.scalarType&&e.scalarType.startsWith("big")?{lengthType:LengthType.LengthDelimited}:{lengthType:LengthType.Varint};case"Buffer":case"String":case"Any":case"NonPrimitive":return{lengthType:LengthType.LengthDelimited};case"Interface":case"Pick":case"Partial":case"Omit":case"Union":case"Intersection":return{lengthType:LengthType.IdBlock};case"Array":case"Overwrite":case"Tuple":return{lengthType:LengthType.LengthDelimited,needLengthPrefix:!0};case"Literal":return{lengthType:LengthType.LengthDelimited,needLengthPrefix:!1};default:throw new Error("Unrecognized schema type: "+e.type)}},e}();!function(e){e[e.LengthDelimited=0]="LengthDelimited",e[e.Varint=1]="Varint",e[e.Bit64=2]="Bit64",e[e.IdBlock=3]="IdBlock"}(LengthType=LengthType||{});var BufferWriter=function(){function e(e){this._ops=[],this._utf8=e}return Object.defineProperty(e.prototype,"ops",{get:function(){return this._ops},enumerable:!1,configurable:!0}),e.prototype.clear=function(){this._ops=[]},e.prototype.push=function(e){return this._ops.push(this.req2op(e)),this},e.prototype.req2op=function(e){if("string"===e.type||"buffer"===e.type){var t=this.measureLength(e);return this.push({type:"varint",value:Varint64.from(t)}),__assign(__assign({},e),{length:t})}var r=this.measureLength(e);return __assign(__assign({},e),{length:r})},e.prototype.measureLength=function(e){switch(e.type){case"varint":return e.value.byteLength;case"string":return this._utf8.measureLength(e.value);case"buffer":return e.value.byteLength;case"double":return 8;case"boolean":return 1;default:return NaN}},e.prototype.finish=function(){for(var e=this._ops.sum(function(e){return e.length}),t=0,r=new Uint8Array(e),i=new DataView(r.buffer),n=0,a=this._ops;n<a.length;n++){var s=a[n];switch(s.type){case"varint":var o=s.value.writeToBuffer(r,t);if(o!==t+s.length)throw new Error("Error varint measuredLength "+s.length+", actual is "+(o-t)+", value is "+s.value.toNumber());break;case"double":i.setFloat64(r.byteOffset+t,s.value);break;case"string":var p=this._utf8.write(s.value,r,t);if(p!==s.length)throw new Error("Expect "+s.length+" bytes but encoded "+p+" bytes");break;case"buffer":r.subarray(t,t+s.length).set(s.value);break;case"boolean":i.setUint8(r.byteOffset+t,s.value?255:0)}t+=s.length}return r},e}(),Encoder=function(){function e(e,t){this._writer=new BufferWriter(t),this._validator=e}return e.prototype.encode=function(e,t){return this._writer.clear(),this._write(e,t),this._writer.finish()},e.prototype._write=function(t,e,r){switch(e.type){case"Boolean":this._writer.push({type:"boolean",value:t});break;case"Number":this._writeNumber(t,e);break;case"String":this._writer.push({type:"string",value:t});break;case"Array":var i=t;this._writer.push({type:"varint",value:Varint64.from(i.length)});for(var n=0;n<i.length;++n)this._write(i[n],e.elementType);break;case"Tuple":if(64<e.elementTypes.length)throw new Error("Elements oversized, maximum supported tuple elements is 64, now get "+e.elementTypes.length);for(var i=t,a=[],n=0;n<i.length;++n)void 0!==i[n]&&a.push(n);for(var s=0,o=0,p=0,h=a;p<h.length;p++){var u=h[p];u<32?s|=1<<u:o|=1<<u-32}this._writer.push({type:"varint",value:new Varint64(o,s)});for(var f=0,l=a;f<l.length;f++){n=l[f];this._write(i[n],e.elementTypes[n])}break;case"Enum":var c=e.members.find(function(e){return e.value===t});if(!c)throw new Error("Unexpect enum value: "+t);this._writer.push({type:"varint",value:Varint64.from(c.id)});break;case"Any":void 0===t?this._writer.push({type:"string",value:"undefined"}):this._writer.push({type:"string",value:JSON.stringify(t)});break;case"NonPrimitive":this._writer.push({type:"string",value:JSON.stringify(t)});break;case"Literal":break;case"Interface":this._writeInterface(t,e,r);break;case"Buffer":this._writeBuffer(t,e);break;case"IndexedAccess":case"Reference":this._write(t,this._validator.protoHelper.parseReference(e),r);break;case"Partial":case"Pick":case"Omit":case"Overwrite":var d=this._validator.protoHelper.parseMappedType(e);"Interface"===d.type?this._writePureMappedType(t,e,r):this._writeUnion(t,d,null==r?void 0:r.skipFields);break;case"Union":this._writeUnion(t,e,null==r?void 0:r.skipFields);break;case"Intersection":this._writeIntersection(t,e,null==r?void 0:r.skipFields);break;default:throw new Error("Unrecognized schema type: "+e.type)}},e.prototype._writePureMappedType=function(e,t,r){if(r=r||{},"Pick"===t.type)if(r.pickFields){for(var i={},n=0,a=t.keys;n<a.length;n++){var s=a[n];r.pickFields[s]&&(i[s]=1)}r.pickFields=i}else{r.pickFields={};for(var o=0,p=t.keys;o<p.length;o++){s=p[o];r.pickFields[s]=1}}else if("Omit"===t.type){null!=r&&r.skipFields||((r=r||{}).skipFields={});for(var h=0,u=t.keys;h<u.length;h++){s=u[h];r.skipFields[s]=1}}else if("Overwrite"===t.type){var f=this._parseOverwrite(e,t);this._write(f.overwriteValue,f.overwrite,r)}else if("Partial"!==t.type)throw new Error("Invalid PureMappedType child: "+t.type);var l=this._validator.protoHelper.parseReference(t.target);"Interface"===l.type?this._writeInterface(e,l,r):this._writePureMappedType(e,l,r)},e.prototype._writeNumber=function(e,t){var r=t.scalarType||"double";switch(r){case"double":this._writer.push({type:r,value:e});break;case"int":this._writer.push({type:"varint",value:Varint64.from(e).zzEncode()});break;case"uint":this._writer.push({type:"varint",value:Varint64.from(e)});break;default:throw new Error("Scalar type not support : "+r)}},e.prototype._writeInterface=function(e,t,r){(r=r||{}).skipFields||(r.skipFields={});var i=this._writer.ops.length,n=0;if(t.extends){if(t.extends.length>Config.interface.maxExtendsNum)throw new Error("Max support "+Config.interface.maxExtendsNum+" extends, actual: "+t.extends.length);for(var a=0,s=t.extends;a<s.length;a++){var o=s[a],p=o.id+1;this._writer.push({type:"varint",value:Varint64.from(p)});var h=this._writer.ops.length-1,u=this._writer.ops.length,f=this._validator.protoHelper.parseReference(o.type);this._writeInterface(e,f,__assign(__assign({},r),{skipIndexSignature:!!t.indexSignature||r.skipIndexSignature})),this._writer.ops.length===u+1?this._writer.ops.splice(this._writer.ops.length-2,2):(++n,this._processIdWithLengthType(h,o.type))}}if(t.properties)for(var l=0,c=t.properties;l<c.length;l++){var d=c[l],y=this._validator.protoHelper.parseReference(d.type);r.pickFields&&!r.pickFields[d.name]||("Literal"!==y.type?void 0===e[d.name]||!this._validator._options.strictNullCheck&&null==e[d.name]||r.skipFields[d.name]||(r.skipFields[d.name]=1,p=d.id+Config.interface.maxExtendsNum+1,this._writer.push({type:"varint",value:Varint64.from(p)}),h=this._writer.ops.length-1,this._write(e[d.name],y),++n,this._processIdWithLengthType(h,y)):r.skipFields[d.name]=1)}if(!r.skipIndexSignature){var v,_=this._validator.protoHelper.getFlatInterfaceSchema(t);if(_.indexSignature)for(var g in e){void 0!==e[g]&&(r.pickFields&&!r.pickFields[g]||r.skipFields[g]||(r.skipFields[g]=1,this._writer.push({type:"varint",value:Varint64.from(0)}),h=this._writer.ops.length-1,this._writer.push({type:"string",value:g}),v=this._writer.ops.length,this._write(e[g],_.indexSignature.type),++n,this._processIdWithLengthType(h,_.indexSignature.type,v)))}}this._writer.ops.splice(i,0,this._writer.req2op({type:"varint",value:Varint64.from(n)}))},e.prototype._parseOverwrite=function(e,t){var r,i,n={},a=this._validator.protoHelper.parseReference(t.target),s=this._validator.protoHelper.parseReference(t.overwrite),o=this._validator.protoHelper.getFlatInterfaceSchema(a),p=this._validator.protoHelper.getFlatInterfaceSchema(s),h={},u={};if(p.properties)for(var f=0,l=p.properties;f<l.length;f++){void 0===e[(c=l[f]).name]||n[c.name]||(h[c.name]=e[c.name],n[c.name]=1)}if(o.properties)for(var c,d=0,y=o.properties;d<y.length;d++){void 0===e[(c=y[d]).name]||n[c.name]||(u[c.name]=e[c.name],n[c.name]=1)}if(p.indexSignature?(i=p.indexSignature,r=h):o.indexSignature&&(i=o.indexSignature,r=u),i)for(var v in e)n[v]||(r[v]=e[v],n[v]=1);return{target:a,targetValue:u,overwrite:s,overwriteValue:h}},e.prototype._writeUnion=function(e,t,r,i){void 0===r&&(r={}),i=i||(r?Object.keys(r):[]),this._validator.protoHelper.extendsUnionFields(i,t.members.map(function(e){return e.type}));for(var n=this._writer.ops.length,a=0,s=0,o=t.members;s<o.length;s++){var p=o[s];if((this._validator.protoHelper.isInterface(p.type)?this._validator.validateBySchema(e,p.type,{unionFields:i}):"Union"===p.type.type?this._validator.validateUnionType(e,p.type,i):"Intersection"===p.type.type?this._validator.validateIntersectionType(e,p.type,i):this._validator.validateBySchema(e,p.type)).isSucc){this._writer.push({type:"varint",value:Varint64.from(p.id)});var h=this._writer.ops.length-1;if("Union"===p.type.type?this._writeUnion(e,p.type,r,i):this._write(e,p.type,r),a++,this._processIdWithLengthType(h,p.type),"object"!=typeof e)break}}if(!(0<a))throw new Error("Non member is satisfied for union type");this._writer.ops.splice(n,0,this._writer.req2op({type:"varint",value:Varint64.from(a)}))},e.prototype._writeIntersection=function(e,t,r){void 0===r&&(r={}),this._writer.push({type:"varint",value:Varint64.from(t.members.length)});for(var i=0,n=t.members;i<n.length;i++){var a=n[i];this._writer.push({type:"varint",value:Varint64.from(a.id)});var s=this._writer.ops.length-1;this._write(e,a.type,r),this._processIdWithLengthType(s,a.type)}},e.prototype._writeBuffer=function(e,t){var r,i,n;e instanceof ArrayBuffer?this._writer.push({type:"buffer",value:new Uint8Array(e)}):e instanceof Uint8Array?this._writer.push({type:"buffer",value:e}):(r=e.constructor.name,i=TypedArrays[r],n=new Uint8Array(e.buffer,e.byteOffset,e.length*i.BYTES_PER_ELEMENT),this._writer.push({type:"buffer",value:n}))},e.prototype._processIdWithLengthType=function(r,e,t){var i=this._writer.ops[r];if("varint"!==i.type)throw new Error("Error idPos: "+r);var n,a=this._validator.protoHelper.parseReference(e),s=IdBlockUtil.getPayloadLengthInfo(a),o=(i.value.toNumber()<<2)+s.lengthType;this._writer.ops[r]=this._writer.req2op({type:"varint",value:Varint64.from(o)}),s.needLengthPrefix&&(n=this._writer.ops.filter(function(e,t){return r<t}).sum(function(e){return e.length}),this._writer.ops.splice(null==t?r+1:t,0,this._writer.req2op({type:"varint",value:Varint64.from(n)})))},e}(),BufferReader=function(){function e(e){this._pos=0,this._utf8=e}return e.prototype.load=function(e,t){void 0===t&&(t=0),this._buf=e,this._pos=t,this._view=new DataView(e.buffer)},e.prototype.readVarint=function(){var e=Varint64.readFromBuffer(this._buf,this._pos);return this._pos+=e.byteLength,e},e.prototype.readUint=function(){return this.readVarint().toNumber(!0)},e.prototype.readInt=function(){return this.readVarint().zzDecode().toNumber()},e.prototype.readDouble=function(){var e=this._pos;return this._pos+=8,this._view.getFloat64(this._buf.byteOffset+e)},e.prototype.readString=function(){var e=this.readUint(),t=this._utf8.read(this._buf,this._pos,e);return this._pos+=e,t},e.prototype.readBuffer=function(){var e=this.readUint(),t=this._buf.subarray(this._pos,this._pos+e);return this._pos+=e,t},e.prototype.skip=function(e){this._pos+=e},e.prototype.skipByLengthType=function(e){if(e===LengthType.Bit64)this._pos+=8;else if(e===LengthType.Varint)this.readVarint();else if(e===LengthType.LengthDelimited){var t=this.readUint();this._pos+=t}else{if(e!==LengthType.IdBlock)throw new Error("Unknown lengthType: "+e);this.skipIdBlock()}},e.prototype.skipIdBlock=function(){for(var e=this.readUint(),t=0;t<e;++t){var r=3&this.readUint();this.skipByLengthType(r)}},e.prototype.readBoolean=function(){var e=this._view.getUint8(this._buf.byteOffset+this._pos++);if(255===e)return!0;if(0===e)return!1;throw new Error("Invalid boolean encoding ["+e+"] at pos "+(this._pos-1))},Object.defineProperty(e.prototype,"unreadByteLength",{get:function(){return this._buf.byteLength-this._pos},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){this._buf=this._view=void 0},e}(),Decoder=function(){function e(e,t){this._reader=new BufferReader(t),this._validator=e}return e.prototype.decode=function(e,t){return this._reader.load(e),this._read(t)},e.prototype._read=function(e){switch(e.type){case"Boolean":return this._reader.readBoolean();case"Number":return this._readNumber(e);case"String":return this._reader.readString();case"Array":for(var t=[],r=this._reader.readUint(),i=0;i<r;++i){var n=this._read(e.elementType);t.push(n)}return t;case"Tuple":if(64<e.elementTypes.length)throw new Error("Elements oversized, maximum supported tuple elements is 64, now get "+e.elementTypes.length);for(var t=[],a=this._reader.readVarint(),s=[],i=0;i<32;++i)a.uint32s[1]&1<<i&&s.push(i);for(i=0;i<32;++i)a.uint32s[0]&1<<i&&s.push(i+32);if(!s.length)return[];for(var o=s.last(),i=0,p=0,h=s[0];i<=o;++i)i===h?(t[i]=this._read(e.elementTypes[i]),h=s[++p]):t[i]=void 0;return t;case"Enum":var u=this._reader.readVarint().toNumber(),f=e.members.find(function(e){return e.id===u});if(!f)throw new Error("Invalid enum encoding: unexpected id "+u);return f.value;case"Any":case"NonPrimitive":var l=this._reader.readString();if("undefined"===l)return;return JSON.parse(l);case"Literal":return e.literal;case"Interface":return this._readInterface(e);case"Buffer":var c=this._reader.readBuffer();if(e.arrayType){if("BigInt64Array"===e.arrayType||"BigUint64Array"===e.arrayType)throw new Error("Unsupported arrayType: "+e.arrayType);if("Uint8Array"===e.arrayType)return c;var d=TypedArrays[e.arrayType];return c.byteOffset%d.BYTES_PER_ELEMENT==0?new d(c.buffer,c.byteOffset,c.byteLength/d.BYTES_PER_ELEMENT):new d(c.buffer.slice(c.byteOffset,c.byteOffset+c.byteLength))}return c.buffer.slice(c.byteOffset,c.byteOffset+c.byteLength);case"IndexedAccess":case"Reference":return this._read(this._validator.protoHelper.parseReference(e));case"Partial":case"Pick":case"Omit":case"Overwrite":var y=this._validator.protoHelper.parseMappedType(e);if("Interface"===y.type)return this._readPureMappedType(e);if("Union"===y.type)return this._readUnionOrIntersection(y);break;case"Union":case"Intersection":return this._readUnionOrIntersection(e);default:throw new Error("Unrecognized schema type: "+e.type)}},e.prototype._readPureMappedType=function(e){var t,r;"Overwrite"===e.type&&(r=this._read(e.overwrite));var i=this._validator.protoHelper.parseReference(e.target);if("Interface"===i.type)t=this._readInterface(i);else{if("Pick"!==i.type&&"Omit"!==i.type&&"Partial"!==i.type&&"Overwrite"!==i.type)throw new Error("Invalid PureMappedType child: "+e.type);t=this._readPureMappedType(i)}if("Pick"===e.type)for(var n in t)-1===e.keys.indexOf(n)&&delete t[n];else if("Omit"===e.type)for(var n in t)-1<e.keys.indexOf(n)&&delete t[n];else"Overwrite"===e.type&&Object.assign(t,r);return t},e.prototype._readNumber=function(e){var t=e.scalarType||"double";switch(t){case"double":return this._reader.readDouble();case"int":return this._reader.readInt();case"uint":return this._reader.readUint();default:throw new Error("Scalar type not support : "+t)}},e.prototype._readInterface=function(f){for(var l={},c=this._validator.protoHelper.getFlatInterfaceSchema(f),e=this._reader.readUint(),t=function(e){var t,r,i,n,a,s,o,p=d._reader.readUint(),h=3&p,u=p>>2;0==u?c.indexSignature?(t=c.indexSignature.type,r=d._reader.readString(),d._skipIdLengthPrefix(d._validator.protoHelper.parseReference(t)),l[r]=d._read(t)):(d._reader.skipByLengthType(LengthType.LengthDelimited),d._reader.skipByLengthType(h)):u<=9?(i=u-1,(n=f.extends&&f.extends.find(function(e){return e.id===i}))?(d._skipIdLengthPrefix(d._validator.protoHelper.parseReference(n.type)),a=d._read(n.type),Object.assign(l,a)):d._reader.skipByLengthType(h)):(s=u-10,(o=f.properties&&f.properties.find(function(e){return e.id===s}))?(d._skipIdLengthPrefix(d._validator.protoHelper.parseReference(o.type)),l[o.name]=d._read(o.type)):d._reader.skipByLengthType(h))},d=this,r=0;r<e;++r)t();for(var i=0,n=c.properties;i<n.length;i++){var a,s=n[i];l.hasOwnProperty(s.name)||"Literal"===(a=this._validator.protoHelper.parseReference(s.type)).type&&(l[s.name]=a.literal)}return l},e.prototype._skipIdLengthPrefix=function(e){IdBlockUtil.getPayloadLengthInfo(e).needLengthPrefix&&this._reader.skipByLengthType(LengthType.Varint)},e.prototype._readUnionOrIntersection=function(s){for(var o,e=this._reader.readUint(),t=function(e){var t=p._reader.readUint(),r=3&t,i=t>>2,n=s.members.find(function(e){return e.id===i});if(!n)return p._reader.skipByLengthType(r),"continue";p._skipIdLengthPrefix(p._validator.protoHelper.parseReference(n.type));var a=p._read(n.type);p._isObject(o)&&p._isObject(a)?Object.assign(o,a):o=a},p=this,r=0;r<e;++r)t();return o},e.prototype._isObject=function(e){return"object"==typeof e&&null!==e},e}(),Utf8Util=function(){function e(){}return e.measureLength=function(e){for(var t=0,r=0,i=0;i<e.length;++i)(r=e.charCodeAt(i))<128?t+=1:r<2048?t+=2:55296==(64512&r)&&56320==(64512&e.charCodeAt(i+1))?(++i,t+=4):t+=3;return t},e.write=function(e,t,r){for(var i,n,a=r,s=0;s<e.length;++s)(i=e.charCodeAt(s))<128?t[r++]=i:(i<2048?t[r++]=i>>6|192:(55296==(64512&i)&&56320==(64512&(n=e.charCodeAt(s+1)))?(i=65536+((1023&i)<<10)+(1023&n),++s,t[r++]=i>>18|240,t[r++]=i>>12&63|128):t[r++]=i>>12|224,t[r++]=i>>6&63|128),t[r++]=63&i|128);return r-a},e.read=function(e,t,r){if(r<1)return"";for(var i,n=void 0,a=[],s=0,o=t+r;t<o;)(i=e[t++])<128?a[s++]=i:191<i&&i<224?a[s++]=(31&i)<<6|63&e[t++]:239<i&&i<365?(i=((7&i)<<18|(63&e[t++])<<12|(63&e[t++])<<6|63&e[t++])-65536,a[s++]=55296+(i>>10),a[s++]=56320+(1023&i)):a[s++]=(15&i)<<12|(63&e[t++])<<6|63&e[t++],8191<s&&((n=n||[]).push(String.fromCharCode.apply(String,a)),s=0);return n?(s&&n.push(String.fromCharCode.apply(String,a.slice(0,s))),n.join("")):String.fromCharCode.apply(String,a.slice(0,s))},e}(),TSBuffer=function(){function e(e,t){this.options={strictExcessCheck:!1,strictNullCheck:!0,utf8:Utf8Util},Object.assign(this.options,t),this._proto=e,this._validator=new tsbufferValidator.TSBufferValidator(e,{skipExcessCheck:!this.options.strictExcessCheck,strictNullCheck:this.options.strictNullCheck}),this._encoder=new Encoder(this._validator,this.options.utf8),this._decoder=new Decoder(this._validator,this.options.utf8)}return e.prototype.encode=function(e,t,r){var i;if("string"==typeof t){if(!(i=this._proto[t]))throw new Error("Cannot find schema: "+t)}else i=t;if(!r||!r.skipValidate){var n=this._validator.validateBySchema(e,i);if(!n.isSucc)throw new Error(n.originalError.message)}return this._encoder.encode(e,i)},e.prototype.decode=function(e,t,r){var i,n;if("string"==typeof t){if(!(i=this._proto[t]))throw new Error("Cannot find schema: "+t)}else i=t;try{n=this._decoder.decode(e,i)}catch(e){var a=new Error("Invalid buffer encoding");throw a.encodingError=e,a}if(!r||!r.skipValidate){var s=this._validator.validateBySchema(n,i);if(!s.isSucc)throw new Error(s.originalError.message)}return n},e.prototype.validate=function(e,t){var r;if("string"==typeof t){if(!(r=this._proto[t]))throw new Error("Cannot find schema: "+t)}else r=t;return this._validator.validateBySchema(e,r)},e}();exports.TSBuffer=TSBuffer;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),require("k8w-extend-native");var LengthType,tsbufferValidator=require("tsbuffer-validator"),__assign=function(){return(__assign=Object.assign||function(e){for(var t,r=1,i=arguments.length;r<i;r++)for(var n in t=arguments[r])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e}).apply(this,arguments)},Config={interface:{maxExtendsNum:9}},Varint64=function(){function s(e,t,r){this.uint32s=new Uint32Array([e,t]),void 0!==r&&(this._byteLength=r)}return s.from=function(e){if(0===e)return this.Zero;var t=e<0,r=(e=t?-e:e)>>>0,e=(e-r)/4294967296>>>0;return t&&(e=~e>>>0,r=~r>>>0,4294967295<++r&&(r=0,4294967295<++e&&(e=0))),new s(e,r)},s.prototype.toNumber=function(e){if(!e&&this.uint32s[0]>>>31){var t=1+~this.uint32s[1]>>>0,e=~this.uint32s[0]>>>0;return-(t+4294967296*(e=!t?e+1>>>0:e))}return this.uint32s[1]+4294967296*this.uint32s[0]},s.prototype.zzEncode=function(){var e=this.uint32s[0]>>31;return this.uint32s[0]=((this.uint32s[0]<<1|this.uint32s[1]>>>31)^e)>>>0,this.uint32s[1]=(this.uint32s[1]<<1^e)>>>0,this},s.prototype.zzDecode=function(){var e=-(1&this.uint32s[1]);return this.uint32s[1]=((this.uint32s[1]>>>1|this.uint32s[0]<<31)^e)>>>0,this.uint32s[0]=(this.uint32s[0]>>>1^e)>>>0,this},Object.defineProperty(s.prototype,"byteLength",{get:function(){var e,t,r;return void 0===this._byteLength&&(e=this.uint32s[1],t=(this.uint32s[1]>>>28|this.uint32s[0]<<4)>>>0,r=this.uint32s[0]>>>24,this._byteLength=0==r?0==t?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:r<128?9:10),this._byteLength},enumerable:!1,configurable:!0}),s.prototype.writeToBuffer=function(e,t){for(;this.uint32s[0];)e[t++]=127&this.uint32s[1]|128,this.uint32s[1]=(this.uint32s[1]>>>7|this.uint32s[0]<<25)>>>0,this.uint32s[0]>>>=7;for(;127<this.uint32s[1];)e[t++]=127&this.uint32s[1]|128,this.uint32s[1]=this.uint32s[1]>>>7;return e[t++]=this.uint32s[1],t},s.readFromBuffer=function(e,t){var r=t,i=0,n=0,a=0;if(!(4<e.byteLength-t)){for(;a<3;++a){if(t>=e.byteLength)throw new Error("Read varint error: index out of range");if(n=(n|(127&e[t])<<7*a)>>>0,e[t++]<128)return new s(i,n,t-r)}return new s(i,n=(n|(127&e[t++])<<7*a)>>>0,t-r)}for(;a<4;++a)if(n=(n|(127&e[t])<<7*a)>>>0,e[t++]<128)return new s(i,n,t-r);if(n=(n|(127&e[t])<<28)>>>0,i=(i|(127&e[t])>>4)>>>0,e[t++]<128)return new s(i,n,t-r);if(a=0,4<e.byteLength-t){for(;a<5;++a)if(i=(i|(127&e[t])<<7*a+3)>>>0,e[t++]<128)return new s(i,n,t-r)}else for(;a<5;++a){if(t>=e.byteLength)throw new Error("Read varint error: index out of range");if(i=(i|(127&e[t])<<7*a+3)>>>0,e[t++]<128)return new s(i,n,t-r)}throw Error("invalid varint encoding")},s.Zero=new s(0,0),s}(),TypedArrays={Int8Array:Int8Array,Int16Array:Int16Array,Int32Array:Int32Array,Uint8Array:Uint8Array,Uint16Array:Uint16Array,Uint32Array:Uint32Array,Float32Array:Float32Array,Float64Array:Float64Array},IdBlockUtil=function(){function e(){}return e.getPayloadLengthInfo=function(e){switch(e.type){case"Boolean":case"Enum":return{lengthType:LengthType.Varint};case"Number":return!e.scalarType||e.scalarType.includes("64")||"double"===e.scalarType?{lengthType:LengthType.Bit64}:e.scalarType&&e.scalarType.startsWith("big")?{lengthType:LengthType.LengthDelimited}:{lengthType:LengthType.Varint};case"Buffer":case"String":case"Any":case"NonPrimitive":return{lengthType:LengthType.LengthDelimited};case"Interface":case"Pick":case"Partial":case"Omit":case"Union":case"Intersection":return{lengthType:LengthType.IdBlock};case"Array":case"Overwrite":case"Tuple":return{lengthType:LengthType.LengthDelimited,needLengthPrefix:!0};case"Literal":return{lengthType:LengthType.LengthDelimited,needLengthPrefix:!1};default:throw new Error("Unrecognized schema type: "+e.type)}},e}();!function(e){e[e.LengthDelimited=0]="LengthDelimited",e[e.Varint=1]="Varint",e[e.Bit64=2]="Bit64",e[e.IdBlock=3]="IdBlock"}(LengthType=LengthType||{});var BufferWriter=function(){function e(e){this._ops=[],this._utf8=e}return Object.defineProperty(e.prototype,"ops",{get:function(){return this._ops},enumerable:!1,configurable:!0}),e.prototype.clear=function(){this._ops=[]},e.prototype.push=function(e){return this._ops.push(this.req2op(e)),this},e.prototype.req2op=function(e){if("string"===e.type||"buffer"===e.type){var t=this.measureLength(e);return this.push({type:"varint",value:Varint64.from(t)}),__assign(__assign({},e),{length:t})}t=this.measureLength(e);return __assign(__assign({},e),{length:t})},e.prototype.measureLength=function(e){switch(e.type){case"varint":return e.value.byteLength;case"string":return this._utf8.measureLength(e.value);case"buffer":return e.value.byteLength;case"double":return 8;case"boolean":return 1;default:return NaN}},e.prototype.finish=function(){for(var e=this._ops.sum(function(e){return e.length}),t=0,r=new Uint8Array(e),i=new DataView(r.buffer),n=0,a=this._ops;n<a.length;n++){var s=a[n];switch(s.type){case"varint":var o=s.value.writeToBuffer(r,t);if(o!==t+s.length)throw new Error("Error varint measuredLength "+s.length+", actual is "+(o-t)+", value is "+s.value.toNumber());break;case"double":i.setFloat64(r.byteOffset+t,s.value);break;case"string":o=this._utf8.write(s.value,r,t);if(o!==s.length)throw new Error("Expect "+s.length+" bytes but encoded "+o+" bytes");break;case"buffer":r.subarray(t,t+s.length).set(s.value);break;case"boolean":i.setUint8(r.byteOffset+t,s.value?255:0)}t+=s.length}return r},e}(),Encoder=function(){function e(e,t){this._writer=new BufferWriter(t),this._validator=e}return e.prototype.encode=function(e,t){return this._writer.clear(),this._write(e,t),this._writer.finish()},e.prototype._write=function(t,e,r){switch(e.type){case"Boolean":this._writer.push({type:"boolean",value:t});break;case"Number":this._writeNumber(t,e);break;case"String":this._writer.push({type:"string",value:t});break;case"Array":this._writer.push({type:"varint",value:Varint64.from((n=t).length)});for(var i=0;i<n.length;++i)this._write(n[i],e.elementType);break;case"Tuple":if(64<e.elementTypes.length)throw new Error("Elements oversized, maximum supported tuple elements is 64, now get "+e.elementTypes.length);for(var n=t,a=[],i=0;i<n.length;++i)void 0!==n[i]&&a.push(i);for(var s=0,o=0,p=0,h=a;p<h.length;p++){var u=h[p];u<32?s|=1<<u:o|=1<<u-32}this._writer.push({type:"varint",value:new Varint64(o,s)});for(var f=0,l=a;f<l.length;f++){i=l[f];this._write(n[i],e.elementTypes[i])}break;case"Enum":var c=e.members.find(function(e){return e.value===t});if(!c)throw new Error("Unexpect enum value: "+t);this._writer.push({type:"varint",value:Varint64.from(c.id)});break;case"Any":void 0===t?this._writer.push({type:"string",value:"undefined"}):this._writer.push({type:"string",value:JSON.stringify(t)});break;case"NonPrimitive":this._writer.push({type:"string",value:JSON.stringify(t)});break;case"Literal":break;case"Interface":this._writeInterface(t,e,r);break;case"Buffer":this._writeBuffer(t,e);break;case"IndexedAccess":case"Reference":this._write(t,this._validator.protoHelper.parseReference(e),r);break;case"Partial":case"Pick":case"Omit":case"Overwrite":c=this._validator.protoHelper.parseMappedType(e);"Interface"===c.type?this._writePureMappedType(t,e,r):this._writeUnion(t,c,null==r?void 0:r.skipFields);break;case"Union":this._writeUnion(t,e,null==r?void 0:r.skipFields);break;case"Intersection":this._writeIntersection(t,e,null==r?void 0:r.skipFields);break;default:throw new Error("Unrecognized schema type: "+e.type)}},e.prototype._writePureMappedType=function(e,t,r){if(r=r||{},"Pick"===t.type)if(r.pickFields){for(var i={},n=0,a=t.keys;n<a.length;n++){var s=a[n];r.pickFields[s]&&(i[s]=1)}r.pickFields=i}else{r.pickFields={};for(var o=0,p=t.keys;o<p.length;o++){s=p[o];r.pickFields[s]=1}}else if("Omit"===t.type){null!=r&&r.skipFields||((r=r||{}).skipFields={});for(var h=0,u=t.keys;h<u.length;h++){s=u[h];r.skipFields[s]=1}}else if("Overwrite"===t.type){var f=this._parseOverwrite(e,t);this._write(f.overwriteValue,f.overwrite,r)}else if("Partial"!==t.type)throw new Error("Invalid PureMappedType child: "+t.type);t=this._validator.protoHelper.parseReference(t.target);"Interface"===t.type?this._writeInterface(e,t,r):this._writePureMappedType(e,t,r)},e.prototype._writeNumber=function(e,t){var r=t.scalarType||"double";switch(r){case"double":this._writer.push({type:r,value:e});break;case"int":this._writer.push({type:"varint",value:Varint64.from(e).zzEncode()});break;case"uint":this._writer.push({type:"varint",value:Varint64.from(e)});break;default:throw new Error("Scalar type not support : "+r)}},e.prototype._writeInterface=function(e,t,r){(r=r||{}).skipFields||(r.skipFields={});var i=this._writer.ops.length,n=0;if(t.extends){if(t.extends.length>Config.interface.maxExtendsNum)throw new Error("Max support "+Config.interface.maxExtendsNum+" extends, actual: "+t.extends.length);for(var a=0,s=t.extends;a<s.length;a++){var o=s[a],p=o.id+1;this._writer.push({type:"varint",value:Varint64.from(p)});var h=this._writer.ops.length-1,u=this._writer.ops.length,f=this._validator.protoHelper.parseReference(o.type);this._writeInterface(e,f,__assign(__assign({},r),{skipIndexSignature:!!t.indexSignature||r.skipIndexSignature})),this._writer.ops.length===u+1?this._writer.ops.splice(this._writer.ops.length-2,2):(++n,this._processIdWithLengthType(h,o.type))}}if(t.properties)for(var l=0,c=t.properties;l<c.length;l++){var d=c[l],y=this._validator.protoHelper.parseReference(d.type);r.pickFields&&!r.pickFields[d.name]||("Literal"!==y.type?void 0===e[d.name]||!this._validator._options.strictNullCheck&&null==e[d.name]||r.skipFields[d.name]||(r.skipFields[d.name]=1,p=d.id+Config.interface.maxExtendsNum+1,this._writer.push({type:"varint",value:Varint64.from(p)}),h=this._writer.ops.length-1,this._write(e[d.name],y),++n,this._processIdWithLengthType(h,y)):r.skipFields[d.name]=1)}if(!r.skipIndexSignature){var _,v=this._validator.protoHelper.getFlatInterfaceSchema(t);if(v.indexSignature)for(var g in e)void 0!==e[g]&&(r.pickFields&&!r.pickFields[g]||r.skipFields[g]||(r.skipFields[g]=1,this._writer.push({type:"varint",value:Varint64.from(0)}),h=this._writer.ops.length-1,this._writer.push({type:"string",value:g}),_=this._writer.ops.length,this._write(e[g],v.indexSignature.type),++n,this._processIdWithLengthType(h,v.indexSignature.type,_)))}this._writer.ops.splice(i,0,this._writer.req2op({type:"varint",value:Varint64.from(n)}))},e.prototype._parseOverwrite=function(e,t){var r,i,n={},a=this._validator.protoHelper.parseReference(t.target),s=this._validator.protoHelper.parseReference(t.overwrite),o=this._validator.protoHelper.getFlatInterfaceSchema(a),t=this._validator.protoHelper.getFlatInterfaceSchema(s),p={},h={};if(t.properties)for(var u=0,f=t.properties;u<f.length;u++)void 0===e[(l=f[u]).name]||n[l.name]||(p[l.name]=e[l.name],n[l.name]=1);if(o.properties)for(var l,c=0,d=o.properties;c<d.length;c++)void 0===e[(l=d[c]).name]||n[l.name]||(h[l.name]=e[l.name],n[l.name]=1);if(t.indexSignature?(i=t.indexSignature,r=p):o.indexSignature&&(i=o.indexSignature,r=h),i)for(var y in e)n[y]||(r[y]=e[y],n[y]=1);return{target:a,targetValue:h,overwrite:s,overwriteValue:p}},e.prototype._writeUnion=function(e,t,r,i){void 0===r&&(r={}),i=i||(r?Object.keys(r):[]),this._validator.protoHelper.extendsUnionFields(i,t.members.map(function(e){return e.type}));for(var n=this._writer.ops.length,a=0,s=0,o=t.members;s<o.length;s++){var p=o[s];if((this._validator.protoHelper.isInterface(p.type)?this._validator.validateBySchema(e,p.type,{unionFields:i}):"Union"===p.type.type?this._validator.validateUnionType(e,p.type,i):"Intersection"===p.type.type?this._validator.validateIntersectionType(e,p.type,i):this._validator.validateBySchema(e,p.type)).isSucc){this._writer.push({type:"varint",value:Varint64.from(p.id)});var h=this._writer.ops.length-1;if("Union"===p.type.type?this._writeUnion(e,p.type,r,i):this._write(e,p.type,r),a++,this._processIdWithLengthType(h,p.type),"object"!=typeof e)break}}if(!(0<a))throw new Error("Non member is satisfied for union type");this._writer.ops.splice(n,0,this._writer.req2op({type:"varint",value:Varint64.from(a)}))},e.prototype._writeIntersection=function(e,t,r){void 0===r&&(r={}),this._writer.push({type:"varint",value:Varint64.from(t.members.length)});for(var i=0,n=t.members;i<n.length;i++){var a=n[i];this._writer.push({type:"varint",value:Varint64.from(a.id)});var s=this._writer.ops.length-1;this._write(e,a.type,r),this._processIdWithLengthType(s,a.type)}},e.prototype._writeBuffer=function(e,t){var r;e instanceof ArrayBuffer?this._writer.push({type:"buffer",value:new Uint8Array(e)}):e instanceof Uint8Array?this._writer.push({type:"buffer",value:e}):(r=e.constructor.name,r=TypedArrays[r],r=new Uint8Array(e.buffer,e.byteOffset,e.length*r.BYTES_PER_ELEMENT),this._writer.push({type:"buffer",value:r}))},e.prototype._processIdWithLengthType=function(r,e,t){var i=this._writer.ops[r];if("varint"!==i.type)throw new Error("Error idPos: "+r);e=this._validator.protoHelper.parseReference(e),e=IdBlockUtil.getPayloadLengthInfo(e),i=(i.value.toNumber()<<2)+e.lengthType;this._writer.ops[r]=this._writer.req2op({type:"varint",value:Varint64.from(i)}),e.needLengthPrefix&&(e=this._writer.ops.filter(function(e,t){return r<t}).sum(function(e){return e.length}),this._writer.ops.splice(null==t?r+1:t,0,this._writer.req2op({type:"varint",value:Varint64.from(e)})))},e}(),BufferReader=function(){function e(e){this._pos=0,this._utf8=e}return e.prototype.load=function(e,t){void 0===t&&(t=0),this._buf=e,this._pos=t,this._view=new DataView(e.buffer)},e.prototype.readVarint=function(){var e=Varint64.readFromBuffer(this._buf,this._pos);return this._pos+=e.byteLength,e},e.prototype.readUint=function(){return this.readVarint().toNumber(!0)},e.prototype.readInt=function(){return this.readVarint().zzDecode().toNumber()},e.prototype.readDouble=function(){var e=this._pos;return this._pos+=8,this._view.getFloat64(this._buf.byteOffset+e)},e.prototype.readString=function(){var e=this.readUint(),t=this._utf8.read(this._buf,this._pos,e);return this._pos+=e,t},e.prototype.readBuffer=function(){var e=this.readUint(),t=this._buf.subarray(this._pos,this._pos+e);return this._pos+=e,t},e.prototype.skip=function(e){this._pos+=e},e.prototype.skipByLengthType=function(e){if(e===LengthType.Bit64)this._pos+=8;else if(e===LengthType.Varint)this.readVarint();else if(e===LengthType.LengthDelimited){var t=this.readUint();this._pos+=t}else{if(e!==LengthType.IdBlock)throw new Error("Unknown lengthType: "+e);this.skipIdBlock()}},e.prototype.skipIdBlock=function(){for(var e=this.readUint(),t=0;t<e;++t){var r=this.readUint();this.skipByLengthType(3&r)}},e.prototype.readBoolean=function(){var e=this._view.getUint8(this._buf.byteOffset+this._pos++);if(255===e)return!0;if(0===e)return!1;throw new Error("Invalid boolean encoding ["+e+"] at pos "+(this._pos-1))},Object.defineProperty(e.prototype,"unreadByteLength",{get:function(){return this._buf.byteLength-this._pos},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){this._buf=this._view=void 0},e}(),Decoder=function(){function e(e,t){this._reader=new BufferReader(t),this._validator=e}return e.prototype.decode=function(e,t){return this._reader.load(e),this._read(t)},e.prototype._read=function(e){switch(e.type){case"Boolean":return this._reader.readBoolean();case"Number":return this._readNumber(e);case"String":return this._reader.readString();case"Array":for(var t=[],r=this._reader.readUint(),i=0;i<r;++i){var n=this._read(e.elementType);t.push(n)}return t;case"Tuple":if(64<e.elementTypes.length)throw new Error("Elements oversized, maximum supported tuple elements is 64, now get "+e.elementTypes.length);for(var t=[],a=this._reader.readVarint(),s=[],i=0;i<32;++i)a.uint32s[1]&1<<i&&s.push(i);for(i=0;i<32;++i)a.uint32s[0]&1<<i&&s.push(i+32);if(!s.length)return[];for(var o=s.last(),i=0,p=0,h=s[0];i<=o;++i)i===h?(t[i]=this._read(e.elementTypes[i]),h=s[++p]):t[i]=void 0;return t;case"Enum":var u=this._reader.readVarint().toNumber(),f=e.members.find(function(e){return e.id===u});if(!f)throw new Error("Invalid enum encoding: unexpected id "+u);return f.value;case"Any":case"NonPrimitive":var l=this._reader.readString();return"undefined"===l?void 0:JSON.parse(l);case"Literal":return e.literal;case"Interface":return this._readInterface(e);case"Buffer":var c=this._reader.readBuffer();if(e.arrayType){if("BigInt64Array"===e.arrayType||"BigUint64Array"===e.arrayType)throw new Error("Unsupported arrayType: "+e.arrayType);if("Uint8Array"===e.arrayType)return c;l=TypedArrays[e.arrayType];return c.byteOffset%l.BYTES_PER_ELEMENT==0?new l(c.buffer,c.byteOffset,c.byteLength/l.BYTES_PER_ELEMENT):new l(c.buffer.slice(c.byteOffset,c.byteOffset+c.byteLength))}return c.buffer.slice(c.byteOffset,c.byteOffset+c.byteLength);case"IndexedAccess":case"Reference":return this._read(this._validator.protoHelper.parseReference(e));case"Partial":case"Pick":case"Omit":case"Overwrite":c=this._validator.protoHelper.parseMappedType(e);if("Interface"===c.type)return this._readPureMappedType(e);if("Union"===c.type)return this._readUnionOrIntersection(c);break;case"Union":case"Intersection":return this._readUnionOrIntersection(e);default:throw new Error("Unrecognized schema type: "+e.type)}},e.prototype._readPureMappedType=function(e){var t,r;"Overwrite"===e.type&&(r=this._read(e.overwrite));var i=this._validator.protoHelper.parseReference(e.target);if("Interface"===i.type)t=this._readInterface(i);else{if("Pick"!==i.type&&"Omit"!==i.type&&"Partial"!==i.type&&"Overwrite"!==i.type)throw new Error("Invalid PureMappedType child: "+e.type);t=this._readPureMappedType(i)}if("Pick"===e.type)for(var n in t)-1===e.keys.indexOf(n)&&delete t[n];else if("Omit"===e.type)for(var n in t)-1<e.keys.indexOf(n)&&delete t[n];else"Overwrite"===e.type&&Object.assign(t,r);return t},e.prototype._readNumber=function(e){var t=e.scalarType||"double";switch(t){case"double":return this._reader.readDouble();case"int":return this._reader.readInt();case"uint":return this._reader.readUint();default:throw new Error("Scalar type not support : "+t)}},e.prototype._readInterface=function(s){for(var o={},p=this._validator.protoHelper.getFlatInterfaceSchema(s),e=this._reader.readUint(),h=this,t=0;t<e;++t)!function(){var t,e,r,i=h._reader.readUint(),n=3&i,a=i>>2;0==a?p.indexSignature?(e=p.indexSignature.type,i=h._reader.readString(),h._skipIdLengthPrefix(h._validator.protoHelper.parseReference(e)),o[i]=h._read(e)):(h._reader.skipByLengthType(LengthType.LengthDelimited),h._reader.skipByLengthType(n)):a<=9?(t=a-1,(e=s.extends&&s.extends.find(function(e){return e.id===t}))?(h._skipIdLengthPrefix(h._validator.protoHelper.parseReference(e.type)),e=h._read(e.type),Object.assign(o,e)):h._reader.skipByLengthType(n)):(r=a-10,(a=s.properties&&s.properties.find(function(e){return e.id===r}))?(h._skipIdLengthPrefix(h._validator.protoHelper.parseReference(a.type)),o[a.name]=h._read(a.type)):h._reader.skipByLengthType(n))}();for(var r=0,i=p.properties;r<i.length;r++){var n,a=i[r];o.hasOwnProperty(a.name)||"Literal"===(n=this._validator.protoHelper.parseReference(a.type)).type&&(o[a.name]=n.literal)}return o},e.prototype._skipIdLengthPrefix=function(e){IdBlockUtil.getPayloadLengthInfo(e).needLengthPrefix&&this._reader.skipByLengthType(LengthType.Varint)},e.prototype._readUnionOrIntersection=function(i){for(var n,e=this._reader.readUint(),a=this,t=0;t<e;++t)!function(){var e=a._reader.readUint(),t=3&e,r=e>>2,e=i.members.find(function(e){return e.id===r});if(!e)return a._reader.skipByLengthType(t);a._skipIdLengthPrefix(a._validator.protoHelper.parseReference(e.type));e=a._read(e.type);a._isObject(n)&&a._isObject(e)?Object.assign(n,e):n=e}();return n},e.prototype._isObject=function(e){return"object"==typeof e&&null!==e},e}(),Utf8Util=function(){function e(){}return e.measureLength=function(e){for(var t,r=0,i=0;i<e.length;++i)(t=e.charCodeAt(i))<128?r+=1:t<2048?r+=2:55296==(64512&t)&&56320==(64512&e.charCodeAt(i+1))?(++i,r+=4):r+=3;return r},e.write=function(e,t,r){for(var i,n,a=r,s=0;s<e.length;++s)(i=e.charCodeAt(s))<128?t[r++]=i:(i<2048?t[r++]=i>>6|192:(55296==(64512&i)&&56320==(64512&(n=e.charCodeAt(s+1)))?(++s,t[r++]=(i=65536+((1023&i)<<10)+(1023&n))>>18|240,t[r++]=i>>12&63|128):t[r++]=i>>12|224,t[r++]=i>>6&63|128),t[r++]=63&i|128);return r-a},e.read=function(e,t,r){if(r<1)return"";for(var i,n=void 0,a=[],s=0,o=t+r;t<o;)(i=e[t++])<128?a[s++]=i:191<i&&i<224?a[s++]=(31&i)<<6|63&e[t++]:239<i&&i<365?(i=((7&i)<<18|(63&e[t++])<<12|(63&e[t++])<<6|63&e[t++])-65536,a[s++]=55296+(i>>10),a[s++]=56320+(1023&i)):a[s++]=(15&i)<<12|(63&e[t++])<<6|63&e[t++],8191<s&&((n=n||[]).push(String.fromCharCode.apply(String,a)),s=0);return n?(s&&n.push(String.fromCharCode.apply(String,a.slice(0,s))),n.join("")):String.fromCharCode.apply(String,a.slice(0,s))},e}(),TSBuffer=function(){function e(e,t){this.options={strictExcessCheck:!1,strictNullCheck:!0,utf8:Utf8Util},Object.assign(this.options,t),this._proto=e,this._validator=new tsbufferValidator.TSBufferValidator(e,{skipExcessCheck:!this.options.strictExcessCheck,strictNullCheck:this.options.strictNullCheck}),this._encoder=new Encoder(this._validator,this.options.utf8),this._decoder=new Decoder(this._validator,this.options.utf8)}return e.prototype.encode=function(e,t,r){var i;if("string"==typeof t){if(!(i=this._proto[t]))throw new Error("Cannot find schema: "+t)}else i=t;if(!r||!r.skipValidate){r=this._validator.validateBySchema(e,i);if(!r.isSucc)throw new Error(r.originalError.message)}return this._encoder.encode(e,i)},e.prototype.decode=function(t,e,r){var i;if("string"==typeof e){if(!(n=this._proto[e]))throw new Error("Cannot find schema: "+e)}else n=e;try{i=this._decoder.decode(t,n)}catch(e){t=new Error("Invalid buffer encoding");throw t.encodingError=e,t}if(!r||!r.skipValidate){var n=this._validator.validateBySchema(i,n);if(!n.isSucc)throw new Error(n.originalError.message)}return i},e.prototype.validate=function(e,t){var r;if("string"==typeof t){if(!(r=this._proto[t]))throw new Error("Cannot find schema: "+t)}else r=t;return this._validator.validateBySchema(e,r)},e}();exports.TSBuffer=TSBuffer;
{
"name": "tsbuffer",
"version": "1.3.6",
"version": "1.3.7",
"description": "",

@@ -11,4 +11,4 @@ "main": "index.js",

"k8w-extend-native": "*",
"tsbuffer-schema": "^1.2.1",
"tsbuffer-validator": "^1.0.12"
"tsbuffer-schema": "~1.2.1",
"tsbuffer-validator": "=1.0.7"
},

@@ -15,0 +15,0 @@ "devDependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc