cbor-x 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,53 +1,61 @@
1
- (function(a,b){"object"==typeof exports&&"undefined"!=typeof module?b(exports):"function"==typeof define&&define.amd?define(["exports"],b):(a=a||self,b(a.msgpackr={}))})(this,function(a){'use strict';function b(){let a=u[w++],d=a>>5;if(a&=31,23<a)switch(a){case 24:a=u[w++];break;case 25:if(7==d)return i();a=C.getUint16(w),w+=2;break;case 26:if(7==d){let a=C.getFloat32(w);if(2<D.useFloat32){// this does rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
2
- let b=S[(127&u[w])<<1|u[w+1]>>7];return w+=4,(b*a+(0<a?.5:-.5)>>0)/b}return w+=4,a}a=C.getUint32(w),w+=4;break;case 27:if(7==d){let a=C.getFloat64(w);return w+=8,a}if(D.uint64AsNumber)return 72057594037927940*u[w++]+281474976710656*u[w++]+1099511627776*u[w++]+4294967296*u[w++]+16777216*u[w++]+(u[w++]<<16)+(u[w++]<<8)+u[w++];a=C.getBigUint64(w),w+=8;break;case 31:// indefinite length
3
- switch(d){case 2:// byte string
1
+ (function(a,b){"object"==typeof exports&&"undefined"!=typeof module?b(exports):"function"==typeof define&&define.amd?define(["exports"],b):(a=a||self,b(a.CBOR={}))})(this,function(a){'use strict';function b(){try{let a=c();if(z==y)// finished reading this source, cleanup references
2
+ C=null,x=null,E&&(E=null);else if(z>y){// over read
3
+ let a=new Error("Unexpected end of CBOR data");throw a.incomplete=!0,a}else if(!M)throw new Error("Data read, but end of buffer not reached");// else more to read, but we are reading sequentially, so don't clear source yet
4
+ return a}catch(a){throw n(),(a instanceof RangeError||a.message.startsWith("Unexpected end of buffer"))&&(a.incomplete=!0),a}}function c(){let a=x[z++],b=a>>5;if(a&=31,23<a)switch(a){case 24:a=x[z++];break;case 25:if(7==b)return j();a=F.getUint16(z),z+=2;break;case 26:if(7==b){let a=F.getFloat32(z);if(2<H.useFloat32){// this does rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
5
+ let b=X[(127&x[z])<<1|x[z+1]>>7];return z+=4,(b*a+(0<a?.5:-.5)>>0)/b}return z+=4,a}a=F.getUint32(z),z+=4;break;case 27:if(7==b){let a=F.getFloat64(z);return z+=8,a}if(H.uint64AsNumber)return 72057594037927940*x[z++]+281474976710656*x[z++]+1099511627776*x[z++]+4294967296*x[z++]+16777216*x[z++]+(x[z++]<<16)+(x[z++]<<8)+x[z++];a=F.getBigUint64(z),z+=8;break;case 31:// indefinite length
6
+ switch(b){case 2:// byte string
4
7
  case 3:// text string
5
8
  case 4:// array
6
- let a,c=[],e=0;for(;(a=b())!=y;)c[e++]=a;return 4==d?c:3==d?c.join(""):Buffer.concat(c);case 5:// map
7
- let f;if(D.mapsAsObjects){let a={};for(;(f=j())!=y;)a[f]=b();return a}else{let a=new Map;for(;(f=b())!=y;)a.set(f,b());return a}case 7:return y;default:throw new Error("Invalid major type for indefinite length "+d);}default:throw new Error("Unknown token "+a);}switch(d){case 0:// positive int
9
+ let a,d=[],e=0;for(;(a=c())!=B;)d[e++]=a;return 4==b?d:3==b?d.join(""):Buffer.concat(d);case 5:// map
10
+ let f;if(H.mapsAsObjects){let a={};for(;(f=k())!=B;)a[f]=c();return a}else{G&&(H.mapsAsObjects=!0,G=!1);let a=new Map;for(;(f=c())!=B;)a.set(f,c());return a}case 7:return B;default:throw new Error("Invalid major type for indefinite length "+b);}default:throw new Error("Unknown token "+a);}switch(b){case 0:// positive int
8
11
  return a;case 1:// negative int
9
12
  return~a;case 2:// buffer
10
- return h(a);case 3:// string
11
- if(F>=w)return A.slice(w-E,(w+=a)-E);if(0==F&&140>v&&32>a){// for small blocks, avoiding the overhead of the extract call is helpful
12
- let b=16>a?g(a):f(a);if(null!=b)return b}return K(a);case 4:// array
13
- let e=Array(a);for(let c=0;c<a;c++)e[c]=b();return e;case 5:// map
14
- if(D.mapsAsObjects){let c={};for(let d=0;d<a;d++)c[j()]=b();return c}else{let c=new Map;for(let d=0;d<a;d++)c.set(b(),b());return c}case 6:// extension
15
- if(a>>8==x){// record structures
16
- let b=z[255&a];if(b)return b.read||(b.read=c(b)),b.read();if(D.getStructures){let d=l(()=>(u=null,D.getStructures()));return!0===z?D.structures=z=d:z.splice.apply(z,[0,d.length].concat(d)),b=z[255&a],b?(b.read||(b.read=c(b)),b.read()):a}return a}else{let c=G[a];return c?c.handlesRead?c(b):c(b()):new N(b())}case 7:// fixed value
13
+ return i(a);case 3:// string
14
+ if(J>=z)return D.slice(z-I,(z+=a)-I);if(0==J&&140>y&&32>a){// for small blocks, avoiding the overhead of the extract call is helpful
15
+ let b=16>a?h(a):g(a);if(null!=b)return b}return P(a);case 4:// array
16
+ let e=Array(a);for(let b=0;b<a;b++)e[b]=c();return e;case 5:// map
17
+ if(H.mapsAsObjects){let b={};for(let d=0;d<a;d++)b[k()]=c();return b}else{G&&(H.mapsAsObjects=!0,G=!1);let b=new Map;for(let d=0;d<a;d++)b.set(c(),c());return b}case 6:// extension
18
+ if(a>>8==A){// record structures
19
+ let b=C[255&a];if(b)return b.read||(b.read=d(b)),b.read();if(H.getStructures){let c=m(()=>(x=null,H.getStructures()));return!0===C?H.structures=C=c:C.splice.apply(C,[0,c.length].concat(c)),b=C[255&a],b?(b.read||(b.read=d(b)),b.read()):a}return a}else{let b=K[a];return b?b.handlesRead?b(c):b(c()):new S(c())}case 7:// fixed value
17
20
  switch(a){case 20:return!1;case 21:return!0;case 22:return null;case 23:return;// undefined
18
21
  case 31:default:throw new Error("Unknown token "+a);}default:// negative int
19
- if(isNaN(a)){let a=new Error("Unexpected end of CBOR data");throw a.incomplete=!0,a}throw new Error("Unknown CBOR token "+a);}}function c(a){function c(){// This initial function is quick to instantiate, but runs slower. After several iterations pay the cost to build the faster function
20
- if(2<c.count++)return this.read=new Function("a","r","return function(){a();return {"+a.map(a=>J.test(a)?a+":r()":"["+JSON.stringify(a)+"]:r()").join(",")+"}}")(d,b),this.read();d();let f={};for(let c,d=0;d<e;d++)c=a[d],f[c]=b();return f}let e=a.length;return c.count=0,c}function d(){// consume the array header, TODO: check expected length
21
- let a=u[w++];//let majorType = token >> 5
22
- a&=31;23<a&&(24===a?w++:25===a?w+=2:26===a?w+=4:void 0)}function e(a){let b;if(16>a&&(b=g(a)))return b;if(64<a&&t)return t.decode(u.subarray(w,w+=a));const c=w+a,d=[];for(b="";w<c;){const a=u[w++];if(0==(128&a))d.push(a);else if(192==(224&a)){// 2 bytes
23
- const b=63&u[w++];d.push((31&a)<<6|b)}else if(224==(240&a)){// 3 bytes
24
- const b=63&u[w++],c=63&u[w++];d.push((31&a)<<12|b<<6|c)}else if(240==(248&a)){// 4 bytes
25
- const b=63&u[w++],c=63&u[w++],e=63&u[w++];let f=(7&a)<<18|b<<12|c<<6|e;65535<f&&(f-=65536,d.push(55296|1023&f>>>10),f=56320|1023&f),d.push(f)}else d.push(a);4096<=d.length&&(b+=L.apply(String,d),d.length=0)}return 0<d.length&&(b+=L.apply(String,d)),b}function f(a){let b=w,c=Array(a);for(let d=0;d<a;d++){const a=u[w++];if(0<(128&a))return void(w=b);c[d]=a}return L.apply(String,c)}function g(p){if(4>p){if(!(2>p)){let d=u[w++],a=u[w++];if(0<(128&d)||0<(128&a))return void(w-=2);if(3>p)return L(d,a);let b=u[w++];return 0<(128&b)?void(w-=3):L(d,a,b)}if(0===p)return"";else{let b=u[w++];return 1<(128&b)?void(w-=1):L(b)}}else{let q=u[w++],a=u[w++],b=u[w++],c=u[w++];if(0<(128&q)||0<(128&a)||0<(128&b)||0<(128&c))return void(w-=4);if(6>p){if(4===p)return L(q,a,b,c);else{let d=u[w++];return 0<(128&d)?void(w-=5):L(q,a,b,c,d)}}else if(8>p){let d=u[w++],e=u[w++];if(0<(128&d)||0<(128&e))return void(w-=6);if(7>p)return L(q,a,b,c,d,e);let f=u[w++];return 0<(128&f)?void(w-=7):L(q,a,b,c,d,e,f)}else{let d=u[w++],e=u[w++],f=u[w++],g=u[w++];if(0<(128&d)||0<(128&e)||0<(128&f)||0<(128&g))return void(w-=8);if(10>p){if(8===p)return L(q,a,b,c,d,e,f,g);else{let h=u[w++];return 0<(128&h)?void(w-=9):L(q,a,b,c,d,e,f,g,h)}}else if(12>p){let h=u[w++],i=u[w++];if(0<(128&h)||0<(128&i))return void(w-=10);if(11>p)return L(q,a,b,c,d,e,f,g,h,i);let j=u[w++];return 0<(128&j)?void(w-=11):L(q,a,b,c,d,e,f,g,h,i,j)}else{let h=u[w++],i=u[w++],j=u[w++],k=u[w++];if(0<(128&h)||0<(128&i)||0<(128&j)||0<(128&k))return void(w-=12);if(!(14>p)){let l=u[w++],m=u[w++];if(0<(128&l)||0<(128&m))return void(w-=14);if(15>p)return L(q,a,b,c,d,e,f,g,h,i,j,k,l,m);let n=u[w++];return 0<(128&n)?void(w-=15):L(q,a,b,c,d,e,f,g,h,i,j,k,l,m,n)}if(12===p)return L(q,a,b,c,d,e,f,g,h,i,j,k);else{let l=u[w++];return 0<(128&l)?void(w-=13):L(q,a,b,c,d,e,f,g,h,i,j,k,l)}}}}}function h(a){return D.copyBuffers?// specifically use the copying slice (not the node one)
26
- Uint8Array.prototype.slice.call(u,w,w+=a):u.subarray(w,w+=a)}function i(){var a=Math.exp;let b,c=u[w++],d=u[w++],e=(c<<8)+d,f=31&e>>10,g=1023&e;return b=0==f?a(g,-24):31==f?0==g?1/0:NaN:a(g+1024,f-25),32768&e?-b:b}function j(){let a=u[w++];if(96<=a&&120>a){if(a-=96,F>=w)// if it has been extracted, must use it (and faster anyway)
27
- return A.slice(w-E,(w+=a)-E);if(!(0==F&&180>v))return K(a)}else return w--,b();let c,d=4095&(a<<5^(1<a?C.getUint16(w):0<a?u[w]:0)),e=M[d],h=w,j=w+a-3,k=0;if(e&&e.bytes==a){for(;h<j;){if(c=C.getUint32(h),c!=e[k++]){h=1879048192;break}h+=4}for(j+=3;h<j;)if(c=u[h++],c!=e[k++]){h=1879048192;break}if(h===j)return w=h,e.string;j-=3,h=w}for(e=[],M[d]=e,e.bytes=a;h<j;)c=C.getUint32(h),e.push(c),h+=4;for(j+=3;h<j;)c=u[h++],e.push(c);// for small blocks, avoiding the overhead of the extract call is helpful
28
- let l=16>a?g(a):f(a);return null==l?e.string=K(a):e.string=l}function k(a,b){G[b]=b=>{if(!a)throw new Error("Could not find typed array for code "+typeCode);// we have to always slice/copy here to get a new ArrayBuffer that is word/byte aligned
29
- return new O[a](Uint8Array.prototype.slice.call(b,0).buffer)}}function l(a){let b=v,c=w,d=E,e=F,f=A,g=B,h=new Uint8Array(u.slice(0,v)),i=z,j=D,k=a();return v=b,w=c,E=d,F=e,A=f,B=g,u=h,z=i,D=j,C=new DataView(u.buffer,u.byteOffset,u.byteLength),k}function m(){u=null,B=null,z=null}function n(a){G[a.tag]=a.decode}function o(a){256>a?(ea[ha++]=152,ea[ha++]=a):65536>a?(ea[ha++]=153,ea[ha++]=a>>8,ea[ha++]=255&a):(ea[ha++]=154,fa.setUint32(ha,a),ha+=4)}function p(a){return{tag:a,encode:function(a,b){let c=a.byteLength,d=a.byteOffset||0,e=a.buffer||a;b($?Buffer.from(e,d,c):new Uint8Array(e,d,c))}}}function q(a,b){let c=a.byteLength;256>c?(ea[ha++]=88,ea[ha++]=c):65536>c?(ea[ha++]=89,ea[ha++]=c>>8,ea[ha++]=255&c):(ea[ha++]=90,fa.setUint32(ha,c),ha+=4),ha+c>=ea.length&&b(ha+c),ea.set(a,ha),ha+=c}function r(a,b){// insert the ids that need to be referenced for structured clones
22
+ if(isNaN(a)){let a=new Error("Unexpected end of CBOR data");throw a.incomplete=!0,a}throw new Error("Unknown CBOR token "+a);}}function d(a){function b(){// This initial function is quick to instantiate, but runs slower. After several iterations pay the cost to build the faster function
23
+ if(2<b.count++)return this.read=new Function("a","r","return function(){a();return {"+a.map(a=>O.test(a)?a+":r()":"["+JSON.stringify(a)+"]:r()").join(",")+"}}")(e,c),this.read();e();let f={};for(let b,e=0;e<d;e++)b=a[e],f[b]=c();return f}let d=a.length;return b.count=0,b}function e(){// consume the array header, TODO: check expected length
24
+ let a=x[z++];//let majorType = token >> 5
25
+ a&=31;23<a&&(24===a?z++:25===a?z+=2:26===a?z+=4:void 0)}function f(a){let b;if(16>a&&(b=h(a)))return b;if(64<a&&w)return w.decode(x.subarray(z,z+=a));const c=z+a,d=[];for(b="";z<c;){const a=x[z++];if(0==(128&a))d.push(a);else if(192==(224&a)){// 2 bytes
26
+ const b=63&x[z++];d.push((31&a)<<6|b)}else if(224==(240&a)){// 3 bytes
27
+ const b=63&x[z++],c=63&x[z++];d.push((31&a)<<12|b<<6|c)}else if(240==(248&a)){// 4 bytes
28
+ const b=63&x[z++],c=63&x[z++],e=63&x[z++];let f=(7&a)<<18|b<<12|c<<6|e;65535<f&&(f-=65536,d.push(55296|1023&f>>>10),f=56320|1023&f),d.push(f)}else d.push(a);4096<=d.length&&(b+=Q.apply(String,d),d.length=0)}return 0<d.length&&(b+=Q.apply(String,d)),b}function g(a){let b=z,c=Array(a);for(let d=0;d<a;d++){const a=x[z++];if(0<(128&a))return void(z=b);c[d]=a}return Q.apply(String,c)}function h(p){if(4>p){if(!(2>p)){let d=x[z++],a=x[z++];if(0<(128&d)||0<(128&a))return void(z-=2);if(3>p)return Q(d,a);let b=x[z++];return 0<(128&b)?void(z-=3):Q(d,a,b)}if(0===p)return"";else{let b=x[z++];return 1<(128&b)?void(z-=1):Q(b)}}else{let q=x[z++],a=x[z++],b=x[z++],c=x[z++];if(0<(128&q)||0<(128&a)||0<(128&b)||0<(128&c))return void(z-=4);if(6>p){if(4===p)return Q(q,a,b,c);else{let d=x[z++];return 0<(128&d)?void(z-=5):Q(q,a,b,c,d)}}else if(8>p){let d=x[z++],e=x[z++];if(0<(128&d)||0<(128&e))return void(z-=6);if(7>p)return Q(q,a,b,c,d,e);let f=x[z++];return 0<(128&f)?void(z-=7):Q(q,a,b,c,d,e,f)}else{let d=x[z++],e=x[z++],f=x[z++],g=x[z++];if(0<(128&d)||0<(128&e)||0<(128&f)||0<(128&g))return void(z-=8);if(10>p){if(8===p)return Q(q,a,b,c,d,e,f,g);else{let h=x[z++];return 0<(128&h)?void(z-=9):Q(q,a,b,c,d,e,f,g,h)}}else if(12>p){let h=x[z++],i=x[z++];if(0<(128&h)||0<(128&i))return void(z-=10);if(11>p)return Q(q,a,b,c,d,e,f,g,h,i);let j=x[z++];return 0<(128&j)?void(z-=11):Q(q,a,b,c,d,e,f,g,h,i,j)}else{let h=x[z++],i=x[z++],j=x[z++],k=x[z++];if(0<(128&h)||0<(128&i)||0<(128&j)||0<(128&k))return void(z-=12);if(!(14>p)){let l=x[z++],m=x[z++];if(0<(128&l)||0<(128&m))return void(z-=14);if(15>p)return Q(q,a,b,c,d,e,f,g,h,i,j,k,l,m);let n=x[z++];return 0<(128&n)?void(z-=15):Q(q,a,b,c,d,e,f,g,h,i,j,k,l,m,n)}if(12===p)return Q(q,a,b,c,d,e,f,g,h,i,j,k);else{let l=x[z++];return 0<(128&l)?void(z-=13):Q(q,a,b,c,d,e,f,g,h,i,j,k,l)}}}}}function i(a){return H.copyBuffers?// specifically use the copying slice (not the node one)
29
+ Uint8Array.prototype.slice.call(x,z,z+=a):x.subarray(z,z+=a)}function j(){var a=Math.exp;let b,c=x[z++],d=x[z++],e=(c<<8)+d,f=31&e>>10,g=1023&e;return b=0==f?a(g,-24):31==f?0==g?1/0:NaN:a(g+1024,f-25),32768&e?-b:b}function k(){let a=x[z++];if(96<=a&&120>a){if(a-=96,J>=z)// if it has been extracted, must use it (and faster anyway)
30
+ return D.slice(z-I,(z+=a)-I);if(!(0==J&&180>y))return P(a)}else return z--,c();let b,d=4095&(a<<5^(1<a?F.getUint16(z):0<a?x[z]:0)),e=R[d],f=z,j=z+a-3,k=0;if(e&&e.bytes==a){for(;f<j;){if(b=F.getUint32(f),b!=e[k++]){f=1879048192;break}f+=4}for(j+=3;f<j;)if(b=x[f++],b!=e[k++]){f=1879048192;break}if(f===j)return z=f,e.string;j-=3,f=z}for(e=[],R[d]=e,e.bytes=a;f<j;)b=F.getUint32(f),e.push(b),f+=4;for(j+=3;f<j;)b=x[f++],e.push(b);// for small blocks, avoiding the overhead of the extract call is helpful
31
+ let l=16>a?h(a):g(a);return null==l?e.string=P(a):e.string=l}function l(a,b){K[b]=b=>{if(!a)throw new Error("Could not find typed array for code "+typeCode);// we have to always slice/copy here to get a new ArrayBuffer that is word/byte aligned
32
+ return new T[a](Uint8Array.prototype.slice.call(b,0).buffer)}}function m(a){let b=y,c=z,d=I,e=J,f=D,g=E,h=new Uint8Array(x.slice(0,y)),i=C,j=H,k=M,l=a();return y=b,z=c,I=d,J=e,D=f,E=g,x=h,M=k,C=i,H=j,F=new DataView(x.buffer,x.byteOffset,x.byteLength),l}function n(){x=null,E=null,C=null}function o(a){K[a.tag]=a.decode}function p(a){256>a?(la[oa++]=152,la[oa++]=a):65536>a?(la[oa++]=153,la[oa++]=a>>8,la[oa++]=255&a):(la[oa++]=154,ma.setUint32(oa,a),oa+=4)}function q(a){return{tag:a,encode:function(a,b){let c=a.byteLength,d=a.byteOffset||0,e=a.buffer||a;b(fa?Buffer.from(e,d,c):new Uint8Array(e,d,c))}}}function r(a,b){let c=a.byteLength;24>c?la[oa++]=64+c:256>c?(la[oa++]=88,la[oa++]=c):65536>c?(la[oa++]=89,la[oa++]=c>>8,la[oa++]=255&c):(la[oa++]=90,ma.setUint32(oa,c),oa+=4),oa+c>=la.length&&b(oa+c),la.set(a,oa),oa+=c}function s(a,b){// insert the ids that need to be referenced for structured clones
30
33
  let c,d=8*b.length,e=a.length-d;for(b.sort((c,a)=>c.offset>a.offset?1:-1);c=b.pop();){let b=c.offset,f=c.id;a.copyWithin(b+d,b,e),d-=8;let g=b+d;// uint32
31
- a[g++]=217,a[g++]=156,a[g++]=73,a[g++]=26,a[g++]=f>>24,a[g++]=255&f>>16,a[g++]=255&f>>8,a[g++]=255&f,e=b}return a}function s(a){if(a.Class){if(!a.encode)throw new Error("Extension has no encode function");Z.unshift(a.Class),Y.unshift(a)}n(a)}let t;try{t=new TextDecoder}catch(a){}let u,v,w=0;const x=105,y={};let z,A,B,C,D={},E=0,F=0,G=[],H={useRecords:!1,mapsAsObjects:!0};class I{constructor(a){a&&(!1===a.useRecords&&a.mapsAsObjects===void 0&&(a.mapsAsObjects=!0),a.getStructures&&!a.structures&&((a.structures=[]).uninitialized=!0)),Object.assign(this,a)}decode(a,c,d){if(u)// re-entrant execution, save the state and restore it after we do this decode
32
- return l(()=>(m(),this?this.decode(a,c,d):I.prototype.decode.call(H,a,c,d)));if(v=-1<c?c:a.length,w=0,F=0,A=null,u=a,C=a.dataView||(a.dataView=new DataView(a.buffer,a.byteOffset,a.byteLength)),!this)D=H,(!z||0<z.length)&&(z=[]);else if(D=this,this.structures){z=this.structures;try{return b()}finally{(w>=v||!d)&&(z=null,u=null,B&&(B=null))}}else(!z||0<z.length)&&(z=[]);try{return b()}finally{(w>=v||!d)&&(u=null,B&&(B=null))}}decodeMultiple(a,c){try{let d,e=this,f=a.length,g=this?this.decode(a,f,!0):T.decode(a,f,!0);if(c){for(c(g);w<f;)if(!1===c(b()))return;}else{for(d=[g];w<f;)d.push(b());return d}}finally{m()}}}const J=/^[a-zA-Z_$][a-zA-Z\d_$]*$/;let K=e,L=String.fromCharCode,M=Array(4096);class N{constructor(a){this.value=a}}let O="object"==typeof window?window:global;G[0]=a=>new Date(a),G[1]=a=>new Date(1e3*a),G[2]=a=>new DataView(a.buffer,a.byteOffset,a.byteLength).getBigUint64(0),G[3]=a=>BigInt(-1)-new DataView(a.buffer,a.byteOffset,a.byteLength).getBigUint64(0);// the registration of the record definition extension (tag 105)
33
- const P=()=>{let a=b(),d=a[0],e=a[1];z[255&e]=d,d.read=c(d);let f={};for(let b,c=2,e=a.length;c<e;c++)b=d[c-2],f[b]=a[c];return f};P.handlesRead=!0,G[105]=P,G[27]=a=>(O[a[0]]||Error)(a[1],a[2]),G[40009]=a=>{B||(B=new Map);let c,d=u[w];c=4==d>>5?[]:{};let e={target:c};// a placeholder object
34
- B.set(a,e);let f=b();// read the next value as the target object to id
35
- return e.used?Object.assign(c,f):(e.target=f,f);// no cycle, can just use the returned read object
36
- },G[40010]=a=>{// pointer extension (for structured clones)
37
- let b=B.get(a);return b.used=!0,b.target},G[258]=a=>new Set(a);// https://github.com/input-output-hk/cbor-sets-spec/blob/master/CBOR_SETS.md
38
- const Q=["Uint8","Uint8Clamped","Uint16","Uint32","BigUint64","Int8","Int16","Int32","BigInt64","Float32","Float64"].map(a=>a+"Array"),R=[64,68,69,70,71,72,77,78,79,81,82];for(let b=0;b<Q.length;b++)k(Q[b],R[b]);let S=Array(147);// this is a table matching binary exponents to the multiplier to determine significant digit rounding
39
- for(let b=0;256>b;b++)S[b]=+("1e"+Math.floor(45.15-.30103*b));let T=new I({useRecords:!1});const U=T.decode,V=T.decodeMultiple,W={NEVER:0,ALWAYS:1,DECIMAL_ROUND:3,DECIMAL_FIT:4};let X;try{X=new TextEncoder}catch(a){}let Y,Z;const $="undefined"!=typeof Buffer,_=$?Buffer.allocUnsafeSlow:Uint8Array,aa=$?Buffer:Uint8Array,ba=105,ca=256,da=$?4294967296:2144337920;let ea,fa,ga,ha=0;const ia=Symbol("record-id");class ja extends I{constructor(a){super(a),this.offset=0;let b,c,d,e,f,g=0,h=aa.prototype.utf8Write?function(a,b,c){return ea.utf8Write(a,b,c)}:!!(X&&X.encodeInto)&&function(a,b){return X.encodeInto(a,ea.subarray(b)).written},i=this,j=64,k=a&&a.sequential;k&&(j=0,this.structures=[]);let m=[],n=0,p=0;if(this.structures&&this.structures.length>j)throw new Error("Too many shared structures");this.encode=function(a){if(ea||(ea=new _(8192),fa=new DataView(ea.buffer,0,8192),ha=0),ga=ea.length-10,2048>ga-ha&&(ea=new _(ea.length),fa=new DataView(ea.buffer,0,ea.length),ga=ea.length-10,ha=0),b=ha,f=i.structuredClone?new Map:null,c=i.structures,c){c.uninitialized&&(i.structures=c=i.getStructures());let a=c.length;if(a>j&&!k&&(a=j),!c.transitions){c.transitions=Object.create(null);for(let b,d=0;d<a;d++){if(b=c[d],!b)continue;let a,e=c.transitions;for(let c,d=0,f=b.length;d<f;d++)c=b[d],a=e[c],a||(a=e[c]=Object.create(null)),e=a;e[ia]=d}g=c.length}k||(c.nextId=a)}d&&(d=!1),e=c||[];try{// update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
40
- if(q(a),i.offset=ha,f&&f.idsToInsert){ha+=8*f.idsToInsert.length,ha>ga&&t(ha),i.offset=ha;let a=r(ea.subarray(b,ha),f.idsToInsert);return f=null,a}return ea.subarray(b,ha);// position can change if we call encode again in saveStructures, so we get the buffer now
41
- }finally{if(c){if(10>p&&p++,1e4<n)c.transitions=null,p=0,n=0,0<m.length&&(m=[]);else if(0<m.length&&!k){for(let a=0,b=m.length;a<b;a++)m[a][ia]=0;m=[]}if(d&&i.saveStructures){if(i.structures.length>j&&(i.structures=i.structures.slice(0,j)),!1===i.saveStructures(i.structures,g))return i.structures=i.getStructures()||[],i.encode(a);g=i.structures.length}}}};const q=a=>{ha>ga&&(ea=t(ha));var c,d=typeof a;if("string"==d){let b,d=a.length;b=32>d?1:256>d?2:65536>d?3:5;let e=3*d;if(ha+e>ga&&(ea=t(ha+e)),64>d||!h){let e,f,g,h=ha+b;for(e=0;e<d;e++)f=a.charCodeAt(e),128>f?ea[h++]=f:2048>f?(ea[h++]=192|f>>6,ea[h++]=128|63&f):55296==(64512&f)&&56320==(64512&(g=a.charCodeAt(e+1)))?(f=65536+((1023&f)<<10)+(1023&g),e++,ea[h++]=240|f>>18,ea[h++]=128|63&f>>12,ea[h++]=128|63&f>>6,ea[h++]=128|63&f):(ea[h++]=224|f>>12,ea[h++]=128|63&f>>6,ea[h++]=128|63&f);c=h-ha-b}else c=h(a,ha+b,e);24>c?ea[ha++]=96|c:256>c?(2>b&&ea.copyWithin(ha+2,ha+1,ha+1+c),ea[ha++]=120,ea[ha++]=c):65536>c?(3>b&&ea.copyWithin(ha+3,ha+2,ha+2+c),ea[ha++]=121,ea[ha++]=c>>8,ea[ha++]=255&c):(5>b&&ea.copyWithin(ha+5,ha+3,ha+3+c),ea[ha++]=122,fa.setUint32(ha,c),ha+=4),ha+=c}else if("number"===d){if(a>>>0===a)24>a?ea[ha++]=a:256>a?(ea[ha++]=24,ea[ha++]=a):65536>a?(ea[ha++]=25,ea[ha++]=a>>8,ea[ha++]=255&a):(ea[ha++]=26,fa.setUint32(ha,a),ha+=4);else if(a>>0===a)-24<=a?ea[ha++]=31-a:-256<=a?(ea[ha++]=56,ea[ha++]=~a):-65536<=a?(ea[ha++]=57,fa.setUint16(ha,~a),ha+=2):(ea[ha++]=58,fa.setUint32(ha,~a),ha+=4);else{let b;if(0<(b=this.useFloat32)&&4294967296>a&&-2147483648<=a){ea[ha++]=250,fa.setFloat32(ha,a);let c;if(4>b||// this checks for rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
42
- (c=a*S[(127&ea[ha])<<1|ea[ha+1]>>7])>>0===c)return void(ha+=4);// move back into position for writing a double
43
- ha--}ea[ha++]=251,fa.setFloat64(ha,a),ha+=8}}else if("object"===d){if(!a)ea[ha++]=246;else{if(f){let c=f.get(a);if(c){if(!c.id){let a=f.idsToInsert||(f.idsToInsert=[]);c.id=a.push(c)}return ea[ha++]=217,ea[ha++]=156,ea[ha++]=74,ea[ha++]=26,fa.setUint32(ha,c.id),void(ha+=4)}f.set(a,{offset:ha-b})}let d=a.constructor;if(d===Object)s(a,!0);else if(d===Array){c=a.length,24>c?ea[ha++]=128|c:o(c);for(let b=0;b<c;b++)q(a[b])}else if(d===Map){c=a.size,24>c?ea[ha++]=160|c:256>c?(ea[ha++]=184,ea[ha++]=c):65536>c?(ea[ha++]=185,ea[ha++]=c>>8,ea[ha++]=255&c):(ea[ha++]=186,fa.setUint32(ha,c),ha+=4);for(let[b,c]of a)q(b),q(c)}else{for(let b,c=0,d=Y.length;c<d;c++)if(b=Z[c],a instanceof b){let b=Y[c],d=b.tag;return 24>d?ea[ha++]=192|d:256>d?(ea[ha++]=216,ea[ha++]=d):65536>d?(ea[ha++]=217,ea[ha++]=d>>8,ea[ha++]=255&d):-1<d&&(ea[ha++]=218,fa.setUint32(ha,d),ha+=4),void b.encode.call(this,a,q,t)}if(a[Symbol.iterator]){ea[ha++]=159;// indefinite length array
34
+ a[g++]=217,a[g++]=156,a[g++]=73,a[g++]=26,a[g++]=f>>24,a[g++]=255&f>>16,a[g++]=255&f>>8,a[g++]=255&f,e=b}return a}function t(a){if(a.Class){if(!a.encode)throw new Error("Extension has no encode function");ea.unshift(a.Class),da.unshift(a)}o(a)}function*u(a,b){const c=new qa(b);for(const d of a)yield c.encode(d)}async function*v(a,b){const c=new qa(b);for await(const d of a)yield c.encode(d)}/**
35
+ * Given an Iterable/Iterator input which yields buffers, returns an IterableIterator which yields sync decoded objects
36
+ * Or, given an Async Iterable/Iterator which yields promises resolving in buffers, returns an AsyncIterableIterator.
37
+ * @param {Iterable|Iterator|AsyncIterable|AsyncIterableIterator} bufferIterator
38
+ * @param {object} [options] - Decoder options
39
+ * @returns {IterableIterator|Promise.<AsyncIterableIterator}
40
+ */let w;try{w=new TextDecoder}catch(a){}let x,y,z=0;const A=105,B={};let C,D,E,F,G,H={},I=0,J=0,K=[],L={useRecords:!1,mapsAsObjects:!0},M=!1;class N{constructor(a){a&&(!1===a.useRecords&&a.mapsAsObjects===void 0&&(a.mapsAsObjects=!0),a.getStructures&&!a.structures&&((a.structures=[]).uninitialized=!0)),Object.assign(this,a)}decode(a,c){if(x)// re-entrant execution, save the state and restore it after we do this decode
41
+ return m(()=>(n(),this?this.decode(a,c):N.prototype.decode.call(L,a,c)));if(y=-1<c?c:a.length,z=0,J=0,D=null,x=a,F=a.dataView||(a.dataView=new DataView(a.buffer,a.byteOffset,a.byteLength)),this){if(H=this,this.structures)return C=this.structures,b();(!C||0<C.length)&&(C=[])}else H=L,(!C||0<C.length)&&(C=[]);return b()}decodeMultiple(a,c){let d,e=0;try{let f=a.length;M=!0;let g=this?this.decode(a,f):Y.decode(a,f);if(c){for(c(g);z<f;)if(e=z,!1===c(b()))return;}else{for(d=[g];z<f;)e=z,d.push(b());return d}}catch(a){throw a.lastPosition=e,a.values=d,a}finally{M=!1,n()}}}const O=/^[a-zA-Z_$][a-zA-Z\d_$]*$/;let P=f,Q=String.fromCharCode,R=Array(4096);class S{constructor(a){this.value=a}}let T="object"==typeof window?window:global;K[0]=a=>new Date(a),K[1]=a=>new Date(1e3*a),K[2]=a=>new DataView(a.buffer,a.byteOffset,a.byteLength).getBigUint64(0),K[3]=a=>BigInt(-1)-new DataView(a.buffer,a.byteOffset,a.byteLength).getBigUint64(0);// the registration of the record definition extension (tag 105)
42
+ const U=()=>{let a=c(),b=a[0],e=a[1];C[255&e]=b,b.read=d(b);let f={};for(let c,d=2,e=a.length;d<e;d++)c=b[d-2],f[c]=a[d];return f};U.handlesRead=!0,K[105]=U,K[27]=a=>(T[a[0]]||Error)(a[1],a[2]),K[40009]=a=>{E||(E=new Map);let b,d=x[z];b=4==d>>5?[]:{};let e={target:b};// a placeholder object
43
+ E.set(a,e);let f=c();// read the next value as the target object to id
44
+ return e.used?Object.assign(b,f):(e.target=f,f);// no cycle, can just use the returned read object
45
+ },K[40010]=a=>{// pointer extension (for structured clones)
46
+ let b=E.get(a);return b.used=!0,b.target},K[258]=a=>new Set(a),(K[259]=a=>(H.mapsAsObjects&&(H.mapsAsObjects=!1,G=!0),a())).handlesRead=!0;const V=["Uint8","Uint8Clamped","Uint16","Uint32","BigUint64","Int8","Int16","Int32","BigInt64","Float32","Float64"].map(a=>a+"Array"),W=[64,68,69,70,71,72,77,78,79,81,82];for(let b=0;b<V.length;b++)l(V[b],W[b]);const X=Array(147);// this is a table matching binary exponents to the multiplier to determine significant digit rounding
47
+ for(let b=0;256>b;b++)X[b]=+("1e"+Math.floor(45.15-.30103*b));let Y=new N({useRecords:!1});const Z=Y.decode,$=Y.decodeMultiple,_={NEVER:0,ALWAYS:1,DECIMAL_ROUND:3,DECIMAL_FIT:4};let aa,ba=new Float32Array(1),ca=new Uint8Array(ba.buffer,0,4);try{aa=new TextEncoder}catch(a){}let da,ea;const fa="undefined"!=typeof Buffer,ga=fa?Buffer.allocUnsafeSlow:Uint8Array,ha=fa?Buffer:Uint8Array,ia=105,ja=256,ka=fa?4294967296:2144337920;let la,ma,na,oa=0;const pa=Symbol("record-id");class qa extends N{constructor(a){super(a),this.offset=0;let b,c,d,e,f,g=0,h=ha.prototype.utf8Write?function(a,b,c){return la.utf8Write(a,b,c)}:!!(aa&&aa.encodeInto)&&function(a,b){return aa.encodeInto(a,la.subarray(b)).written},i=this,j=64,k=a&&a.sequential;k&&(j=0,this.structures=[]);let m=[],n=0,o=0;this.encode=function(a,h){if(la||(la=new ga(8192),ma=new DataView(la.buffer,0,8192),oa=0),na=la.length-10,2048>na-oa?(la=new ga(la.length),ma=new DataView(la.buffer,0,la.length),na=la.length-10,oa=0):h===xa&&(oa=2147483640&oa+7),b=oa,f=i.structuredClone?new Map:null,c=i.structures,c){c.uninitialized&&(i.structures=c=i.getStructures());let a=c.length;if(a>j&&!k&&(a=j),!c.transitions){c.transitions=Object.create(null);for(let b,d=0;d<a;d++){if(b=c[d],!b)continue;let a,e=c.transitions;for(let c,d=0,f=b.length;d<f;d++)c=b[d],a=e[c],a||(a=e[c]=Object.create(null)),e=a;e[pa]=d}g=c.length}k||(c.nextId=a)}d&&(d=!1),e=c||[];try{// update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
48
+ if(q(a),i.offset=oa,f&&f.idsToInsert){oa+=8*f.idsToInsert.length,oa>na&&t(oa),i.offset=oa;let a=s(la.subarray(b,oa),f.idsToInsert);return f=null,a}return h===xa?(la.start=b,la.end=oa,la):la.subarray(b,oa);// position can change if we call pack again in saveStructures, so we get the buffer now
49
+ }finally{if(c){if(10>o&&o++,1e4<n)c.transitions=null,o=0,n=0,0<m.length&&(m=[]);else if(0<m.length&&!k){for(let a=0,b=m.length;a<b;a++)m[a][pa]=void 0;m=[]}if(d&&i.saveStructures){i.structures.length>j&&(i.structures=i.structures.slice(0,j));// we can't rely on start/end with REUSE_BUFFER_MODE since they will (probably) change when we save
50
+ let c=la.subarray(b,oa);return!1===i.saveStructures(i.structures,g)?(i.structures=i.getStructures()||[],i.encode(a)):(g=i.structures.length,c)}}}};const q=a=>{oa>na&&(la=t(oa));var c,d=typeof a;if("string"==d){let b,d=a.length;b=32>d?1:256>d?2:65536>d?3:5;let e=3*d;if(oa+e>na&&(la=t(oa+e)),64>d||!h){let e,f,g,h=oa+b;for(e=0;e<d;e++)f=a.charCodeAt(e),128>f?la[h++]=f:2048>f?(la[h++]=192|f>>6,la[h++]=128|63&f):55296==(64512&f)&&56320==(64512&(g=a.charCodeAt(e+1)))?(f=65536+((1023&f)<<10)+(1023&g),e++,la[h++]=240|f>>18,la[h++]=128|63&f>>12,la[h++]=128|63&f>>6,la[h++]=128|63&f):(la[h++]=224|f>>12,la[h++]=128|63&f>>6,la[h++]=128|63&f);c=h-oa-b}else c=h(a,oa+b,e);24>c?la[oa++]=96|c:256>c?(2>b&&la.copyWithin(oa+2,oa+1,oa+1+c),la[oa++]=120,la[oa++]=c):65536>c?(3>b&&la.copyWithin(oa+3,oa+2,oa+2+c),la[oa++]=121,la[oa++]=c>>8,la[oa++]=255&c):(5>b&&la.copyWithin(oa+5,oa+3,oa+3+c),la[oa++]=122,ma.setUint32(oa,c),oa+=4),oa+=c}else if("number"===d){if(a>>>0===a)24>a?la[oa++]=a:256>a?(la[oa++]=24,la[oa++]=a):65536>a?(la[oa++]=25,la[oa++]=a>>8,la[oa++]=255&a):(la[oa++]=26,ma.setUint32(oa,a),oa+=4);else if(a>>0===a)-24<=a?la[oa++]=31-a:-256<=a?(la[oa++]=56,la[oa++]=~a):-65536<=a?(la[oa++]=57,ma.setUint16(oa,~a),oa+=2):(la[oa++]=58,ma.setUint32(oa,~a),oa+=4);else{let b;if(0<(b=this.useFloat32)&&4294967296>a&&-2147483648<=a){la[oa++]=250,ma.setFloat32(oa,a);let c;if(4>b||// this checks for rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
51
+ (c=a*X[(127&la[oa])<<1|la[oa+1]>>7])>>0===c)return void(oa+=4);// move back into position for writing a double
52
+ oa--}la[oa++]=251,ma.setFloat64(oa,a),oa+=8}}else if("object"===d){if(!a)la[oa++]=246;else{if(f){let c=f.get(a);if(c){if(!c.id){let a=f.idsToInsert||(f.idsToInsert=[]);c.id=a.push(c)}return la[oa++]=217,la[oa++]=156,la[oa++]=74,la[oa++]=26,ma.setUint32(oa,c.id),void(oa+=4)}f.set(a,{offset:oa-b})}let d=a.constructor;if(d===Object)r(a,!0);else if(d===Array){c=a.length,24>c?la[oa++]=128|c:p(c);for(let b=0;b<c;b++)q(a[b])}else if(d===Map){(this.mapsAsObjects?!1!==this.useTag259ForMaps:this.useTag259ForMaps)&&(la[oa++]=217,la[oa++]=1,la[oa++]=3),c=a.size,24>c?la[oa++]=160|c:256>c?(la[oa++]=184,la[oa++]=c):65536>c?(la[oa++]=185,la[oa++]=c>>8,la[oa++]=255&c):(la[oa++]=186,ma.setUint32(oa,c),oa+=4);for(let[b,c]of a)q(b),q(c)}else{for(let b,c=0,d=da.length;c<d;c++)if(b=ea[c],a instanceof b){let b=da[c],d=b.tag;return 24>d?la[oa++]=192|d:256>d?(la[oa++]=216,la[oa++]=d):65536>d?(la[oa++]=217,la[oa++]=d>>8,la[oa++]=255&d):-1<d&&(la[oa++]=218,ma.setUint32(oa,d),oa+=4),void b.encode.call(this,a,q,t)}if(a[Symbol.iterator]){la[oa++]=159;// indefinite length array
44
53
  for(let b of a)q(b);// stop-code
45
- return void(ea[ha++]=255)}// no extension found, write as object
46
- s(a,!a.hasOwnProperty)}}}else if("boolean"===d)ea[ha++]=a?245:244;else if("bigint"===d){if(a<BigInt(1)<<BigInt(64)&&0<=a)ea[ha++]=27,fa.setBigUint64(ha,a);else if(a>-(BigInt(1)<<BigInt(64))&&0>a)ea[ha++]=59,fa.setBigUint64(ha,-a-BigInt(1));else// overflow
47
- if(this.largeBigIntToFloat)ea[ha++]=251,fa.setFloat64(ha,+a);else throw new RangeError(a+" was too large to fit in CBOR 64-bit integer format, set largeBigIntToFloat to convert to float-64");ha+=8}else if("undefined"===d)//target[position++] = 0xc1 // this is the "never-used" byte
48
- ea[ha++]=247;else throw new Error("Unknown type "+d)},s=!1===this.useRecords?this.variableMapSize?a=>{// this method is slightly slower, but generates "preferred serialization" (optimally small for smaller objects)
49
- let b=Object.keys(a),c=b.length;24>c?ea[ha++]=160|c:256>c?(ea[ha++]=184,ea[ha++]=c):65536>c?(ea[ha++]=185,ea[ha++]=c>>8,ea[ha++]=255&c):(ea[ha++]=186,fa.setUint32(ha,c),ha+=4);let d;for(let e=0;e<c;e++)q(d=b[e]),q(a[d])}:(a,c)=>{ea[ha++]=185;// always use map 16, so we can preallocate and set the length afterwards
50
- let d=ha-b;ha+=2;let e=0;for(let b in a)(c||a.hasOwnProperty(b))&&(q(b),q(a[b]),e++);ea[d++ +b]=e>>8,ea[d+b]=255&e}:/* sharedStructures ? // For highly stable structures, using for-in can a little bit faster
54
+ return void(la[oa++]=255)}// no extension found, write as object
55
+ r(a,!a.hasOwnProperty)}}}else if("boolean"===d)la[oa++]=a?245:244;else if("bigint"===d){if(a<BigInt(1)<<BigInt(64)&&0<=a)la[oa++]=27,ma.setBigUint64(oa,a);else if(a>-(BigInt(1)<<BigInt(64))&&0>a)la[oa++]=59,ma.setBigUint64(oa,-a-BigInt(1));else// overflow
56
+ if(this.largeBigIntToFloat)la[oa++]=251,ma.setFloat64(oa,+a);else throw new RangeError(a+" was too large to fit in CBOR 64-bit integer format, set largeBigIntToFloat to convert to float-64");oa+=8}else if("undefined"===d)la[oa++]=247;else throw new Error("Unknown type: "+d)},r=!1===this.useRecords?this.variableMapSize?a=>{// this method is slightly slower, but generates "preferred serialization" (optimally small for smaller objects)
57
+ let b=Object.keys(a),c=b.length;24>c?la[oa++]=160|c:256>c?(la[oa++]=184,la[oa++]=c):65536>c?(la[oa++]=185,la[oa++]=c>>8,la[oa++]=255&c):(la[oa++]=186,ma.setUint32(oa,c),oa+=4);let d;for(let e=0;e<c;e++)q(d=b[e]),q(a[d])}:(a,c)=>{la[oa++]=185;// always use map 16, so we can preallocate and set the length afterwards
58
+ let d=oa-b;oa+=2;let e=0;for(let b in a)(c||a.hasOwnProperty(b))&&(q(b),q(a[b]),e++);la[d++ +b]=e>>8,la[d+b]=255&e}:/* sharedStructures ? // For highly stable structures, using for-in can a little bit faster
51
59
  (object, safePrototype) => {
52
60
  let nextTransition, transition = structures.transitions || (structures.transitions = Object.create(null))
53
61
  let objectOffset = position++ - start
@@ -86,15 +94,21 @@ let d=ha-b;ha+=2;let e=0;for(let b in a)(c||a.hasOwnProperty(b))&&(q(b),q(a[b]),
86
94
  sharedStructures.onUpdate(id, transition.__keys__)
87
95
  }
88
96
  target[objectOffset + start] = id
89
- }*/a=>{let b,f=Object.keys(a),g=e.transitions||(e.transitions=Object.create(null)),h=0,k=f.length;for(let c,d=0;d<k;d++)c=f[d],b=g[c],b||(b=g[c]=Object.create(null),h++),g=b;let l=g[ia];if(l)// tag two byte
90
- ea[ha++]=217,ea[ha++]=ba,ea[ha++]=l;else if(l=e.nextId++,l||(l=0,e.nextId=1),l>=ca&&(e.nextId=(l=j)+1),g[ia]=l,e[l]=f,c&&c.length<=j)// tag two byte
97
+ }*/a=>{let b,f=Object.keys(a),g=e.transitions||(e.transitions=Object.create(null)),h=0,k=f.length;for(let c,d=0;d<k;d++)c=f[d],b=g[c],b||(b=g[c]=Object.create(null),h++),g=b;let l=g[pa];if(void 0!==l)// tag two byte
98
+ la[oa++]=217,la[oa++]=ia,la[oa++]=l;else if(l=e.nextId++,l||(l=0,e.nextId=1),l>=ja&&(e.nextId=(l=j)+1),g[pa]=l,e[l]=f,c&&c.length<=j)// tag two byte
91
99
  // tag number
92
- ea[ha++]=217,ea[ha++]=ba,ea[ha++]=l,d=!0;else{ea[ha++]=216,ea[ha++]=ba,h&&(n+=p*h),m.length>=ca-j&&(m.shift()[ia]=0),m.push(g),22>k?ea[ha++]=130+k:// array header, length of values + 2
93
- o(k+2),q(f),ea[ha++]=25,ea[ha++]=ba,ea[ha++]=l;// now write the values
94
- for(let b=0;b<k;b++)q(a[f[b]]);return}24>k?ea[ha++]=128|k:o(k);for(let b=0;b<k;b++)q(a[f[b]])},t=a=>{var c=Math.min,d=Math.round,e=Math.max;let f;if(16777216<a){// special handling for really large buffers
95
- if(a-b>da)throw new Error("Encoded buffer would be larger than maximum buffer size");f=c(da,4096*d(e((a-b)*(67108864<a?1.25:2),16777216)/4096))}else// faster handling for smaller buffers
96
- f=(e(a-b<<2,ea.length-1)>>12)+1<<12;let g=new _(f);return fa=new DataView(g.buffer,0,f),ea.copy?ea.copy(g,0,b,a):g.set(ea.slice(b,a)),ha-=b,b=0,ga=g.length-10,ea=g}}useBuffer(a){// this means we are finished using our own buffer and we can write over it safely
97
- ea=a,fa=new DataView(ea.buffer,ea.byteOffset,ea.byteLength),ha=0}}Z=[Date,Set,Error,RegExp,ArrayBuffer,aa,Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array,BigUint64Array,Int8Array,Int16Array,Int32Array,BigInt64Array,Float32Array,Float64Array],Y=[{tag:1,encode(a){let b=a.getTime()/1e3;(this.useTimestamp32||0===a.getMilliseconds())&&0<=b&&4294967296>b?(ea[ha++]=26,fa.setUint32(ha,b),ha+=4):(ea[ha++]=251,fa.setFloat64(ha,b),ha+=8)}},{tag:258,// https://github.com/input-output-hk/cbor-sets-spec/blob/master/CBOR_SETS.md
100
+ la[oa++]=217,la[oa++]=ia,la[oa++]=l,d=!0;else{la[oa++]=216,la[oa++]=ia,h&&(n+=o*h),m.length>=ja-j&&(m.shift()[pa]=void 0),m.push(g),22>k?la[oa++]=130+k:p(k+2),q(f),la[oa++]=25,la[oa++]=ia,la[oa++]=l;// now write the values
101
+ for(let b=0;b<k;b++)q(a[f[b]]);return}24>k?la[oa++]=128|k:p(k);for(let b=0;b<k;b++)q(a[f[b]])},t=a=>{var c=Math.min,d=Math.round,e=Math.max;let f;if(16777216<a){// special handling for really large buffers
102
+ if(a-b>ka)throw new Error("Encoded buffer would be larger than maximum buffer size");f=c(ka,4096*d(e((a-b)*(67108864<a?1.25:2),16777216)/4096))}else// faster handling for smaller buffers
103
+ f=(e(a-b<<2,la.length-1)>>12)+1<<12;let g=new ga(f);return ma=new DataView(g.buffer,0,f),la.copy?la.copy(g,0,b,a):g.set(la.slice(b,a)),oa-=b,b=0,na=g.length-10,la=g}}useBuffer(a){// this means we are finished using our own buffer and we can write over it safely
104
+ la=a,ma=new DataView(la.buffer,la.byteOffset,la.byteLength),oa=0}}ea=[Date,Set,Error,RegExp,ArrayBuffer,ha,Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array,BigUint64Array,Int8Array,Int16Array,Int32Array,BigInt64Array,Float32Array,Float64Array],da=[{tag:1,encode(a){let b=a.getTime()/1e3;(this.useTimestamp32||0===a.getMilliseconds())&&0<=b&&4294967296>b?(la[oa++]=26,ma.setUint32(oa,b),oa+=4):(la[oa++]=251,ma.setFloat64(oa,b),oa+=8)}},{tag:258,// https://github.com/input-output-hk/cbor-sets-spec/blob/master/CBOR_SETS.md
98
105
  encode(a,b){let c=Array.from(a);b(c)}},{tag:27,// http://cbor.schmorp.de/generic-object
99
106
  encode(a,b){b([a.name,a.message])}},{tag:27,// http://cbor.schmorp.de/generic-object
100
- encode(a,b){b(["RegExp",a.source,a.flags])}},{encode(a,b,c){q(a,c)}},{encode(a,b,c){q(a,c)}},p(64),p(68),p(69),p(70),p(71),p(72),p(77),p(78),p(79),p(81),p(82)];let ka=new ja({useRecords:!1});const la=ka.encode,{NEVER:ma,ALWAYS:na,DECIMAL_ROUND:oa,DECIMAL_FIT:pa}=W;a.ALWAYS=na,a.DECIMAL_FIT=pa,a.DECIMAL_ROUND=oa,a.Decoder=I,a.Encoder=ja,a.FLOAT32_OPTIONS=W,a.NEVER=ma,a.Tag=N,a.addExtension=s,a.decode=U,a.decodeMultiple=V,a.encode=la,a.mapsAsObjects=!0,a.useRecords=!1,Object.defineProperty(a,"__esModule",{value:!0})});
107
+ encode(a,b){b(["RegExp",a.source,a.flags])}},{encode(a,b,c){r(a,c)}},{encode(a,b,c){r(a,c)}},q(64),q(68),q(69),q(70),q(71),q(72),q(77),q(78),q(79),q(81),q(82)];let ra=new qa({useRecords:!1});const sa=ra.encode,{NEVER:ta,ALWAYS:ua,DECIMAL_ROUND:va,DECIMAL_FIT:wa}=_,xa=1e3;a.ALWAYS=ua,a.DECIMAL_FIT=wa,a.DECIMAL_ROUND=va,a.Decoder=N,a.Encoder=qa,a.FLOAT32_OPTIONS=_,a.NEVER=ta,a.Tag=S,a.addExtension=t,a.clearSource=n,a.decode=Z,a.decodeIter=function(a,b={}){if(!a||"object"!=typeof a)throw new Error("first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a promise");const c=new N(b);let d;const e=a=>{let b;// if there's incomplete data from previous chunk, concatinate and try again
108
+ d&&(a=Buffer.concat([d,a]),d=void 0);try{b=c.decodeMultiple(a)}catch(c){if(c.incomplete)d=a.slice(c.lastPosition),b=c.values;else throw c}return b};if("function"==typeof a[Symbol.iterator])return function*(){for(const b of a)yield*e(b)}();return"function"==typeof a[Symbol.asyncIterator]?async function*(){for await(const b of a)yield*e(b)}():void 0},a.decodeMultiple=$,a.encode=sa,a.encodeIter=/**
109
+ * Given an Iterable first argument, returns an Iterable where each value is encoded as a Buffer
110
+ * If the argument is only Async Iterable, the return value will be an Async Iterable.
111
+ * @param {Iterable|Iterator|AsyncIterable|AsyncIterator} objectIterator - iterable source, like a Readable object stream, an array, Set, or custom object
112
+ * @param {options} [options] - cbor-x Encoder options
113
+ * @returns {IterableIterator|Promise.<AsyncIterableIterator>}
114
+ */function(a,b={}){if(!a||"object"!=typeof a)throw new Error("first argument must be an Iterable, Async Iterable, or a Promise for an Async Iterable");else{if("function"==typeof a[Symbol.iterator])return u(a,b);if("function"==typeof a.then||"function"==typeof a[Symbol.asyncIterator])return v(a,b);throw new Error("first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a Promise")}},a.mapsAsObjects=!0,a.roundFloat32=function(a){ba[0]=a;let b=X[(127&ca[3])<<1|ca[2]>>7];return(b*a+(0<a?.5:-.5)>>0)/b},a.useRecords=!1,Object.defineProperty(a,"__esModule",{value:!0})});