@basmilius/apple-encoding 0.8.1 → 0.8.2
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/chunk-DQk6qfdC.mjs +18 -0
- package/dist/index.mjs +1461 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-0Lt9GpW0.mjs +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,1462 @@
|
|
|
1
|
-
import{t as e}from"./chunk-0Lt9GpW0.mjs";var t=e({ContentCode:()=>n,TagType:()=>r,decode:()=>l,decodeTag:()=>u,decodeToObject:()=>d,decodeTrackMetadata:()=>f,encodeContainer:()=>a,encodePlaybackStatus:()=>o,encodeTag:()=>i,encodeTagWithSize:()=>s,encodeTrackMetadata:()=>c});const n={mlit:`dmap.listingitem`,mlcl:`dmap.listing`,msrv:`dmap.serverinforesponse`,mcon:`dmap.container`,miid:`dmap.itemid`,minm:`dmap.itemname`,mikd:`dmap.itemkind`,mper:`dmap.persistentid`,asal:`daap.songalbum`,asar:`daap.songartist`,asaa:`daap.songalbumartist`,ascp:`daap.songcomposer`,asgn:`daap.songgenre`,astm:`daap.songtime`,astn:`daap.songtracknumber`,asdc:`daap.songdisccount`,asdn:`daap.songdiscnumber`,astc:`daap.songtrackcount`,asyr:`daap.songyear`,asbr:`daap.songbitrate`,assr:`daap.songsamplerate`,assz:`daap.songsize`,caps:`daap.songplaystatus`,cash:`daap.songshufflestate`,carp:`daap.songrepeatstate`,cavs:`daap.songvisiblestate`,aePP:`com.apple.itunes.photo-properties`},r={mlit:12,mlcl:12,mcon:12,msrv:12,miid:5,minm:9,mikd:1,mper:7,asal:9,asar:9,asaa:9,ascp:9,asgn:9,astm:5,astn:3,asdc:3,asdn:3,astc:3,asyr:3,asbr:3,assr:5,assz:5,caps:1,cash:1,carp:1,cavs:1,aePP:9};function i(e,t){if(e.length!==4)throw Error(`Invalid DAAP tag: ${e}. Tags must be exactly 4 characters.`);let n=Buffer.from(e,`ascii`),r;typeof t==`string`?r=Buffer.from(t,`utf8`):typeof t==`bigint`?(r=Buffer.alloc(8),r.writeBigUInt64BE(t,0)):typeof t==`number`?t<=255&&t>=0?(r=Buffer.alloc(1),r.writeUInt8(t,0)):t<=65535&&t>=0?(r=Buffer.alloc(2),r.writeUInt16BE(t,0)):t<=4294967295&&t>=0?(r=Buffer.alloc(4),r.writeUInt32BE(t,0)):(r=Buffer.alloc(8),r.writeBigInt64BE(BigInt(t),0)):r=t;let i=Buffer.allocUnsafe(4);return i.writeUInt32BE(r.length,0),Buffer.concat([n,i,r])}function a(e,t){if(e.length!==4)throw Error(`Invalid DAAP tag: ${e}. Tags must be exactly 4 characters.`);let n=Buffer.from(e,`ascii`),r=Buffer.alloc(4);return r.writeUInt32BE(t.length,0),Buffer.concat([n,r,t])}function o(e){let t=[];if(e.playing!==void 0&&t.push(s(`caps`,e.playing?4:3,1)),e.shuffle!==void 0&&t.push(s(`cash`,e.shuffle?1:0,1)),e.repeat!==void 0){let n=0;e.repeat===`one`?n=1:e.repeat===`all`&&(n=2),t.push(s(`carp`,n,1))}return Buffer.concat(t)}function s(e,t,n){if(e.length!==4)throw Error(`Invalid DAAP tag: ${e}. Tags must be exactly 4 characters.`);let r=Buffer.from(e,`ascii`),i=Buffer.alloc(n);switch(n){case 1:i.writeUInt8(t,0);break;case 2:i.writeUInt16BE(t,0);break;case 4:i.writeUInt32BE(t,0);break;case 8:i.writeBigUInt64BE(BigInt(t),0);break}let a=Buffer.alloc(4);return a.writeUInt32BE(n,0),Buffer.concat([r,a,i])}function c(e){let t=[];return e.title!==void 0&&t.push(i(`minm`,e.title)),e.artist!==void 0&&t.push(i(`asar`,e.artist)),e.albumArtist!==void 0&&t.push(i(`asaa`,e.albumArtist)),e.album!==void 0&&t.push(i(`asal`,e.album)),e.composer!==void 0&&t.push(i(`ascp`,e.composer)),e.genre!==void 0&&t.push(i(`asgn`,e.genre)),e.duration!==void 0&&t.push(s(`astm`,Math.floor(e.duration*1e3),4)),e.trackNumber!==void 0&&t.push(s(`astn`,e.trackNumber,2)),e.trackCount!==void 0&&t.push(s(`astc`,e.trackCount,2)),e.discNumber!==void 0&&t.push(s(`asdn`,e.discNumber,2)),e.discCount!==void 0&&t.push(s(`asdc`,e.discCount,2)),e.year!==void 0&&t.push(s(`asyr`,e.year,2)),e.bitrate!==void 0&&t.push(s(`asbr`,e.bitrate,2)),e.sampleRate!==void 0&&t.push(s(`assr`,e.sampleRate,4)),e.size!==void 0&&t.push(s(`assz`,e.size,4)),a(`mlit`,Buffer.concat(t))}function l(e){let t=[],n=e;for(;n.length>0;){let e=u(n);if(!e)break;let[r,i]=e;t.push(r),n=i}return t}function u(e){if(e.length<8)return null;let t=e.subarray(0,4).toString(`ascii`),n=e.readUInt32BE(4);if(e.length<8+n)return null;let r=e.subarray(8,8+n),i=e.subarray(8+n);return[{tag:t,length:n,value:r},i]}function d(e){let t={},n=l(e);for(let{tag:e,value:i}of n){let n=r[e];n===void 0?t[e]=i:n===12?t[e]=d(i):n===9?t[e]=i.toString(`utf8`):n===1||n===2?t[e]=i.readUInt8(0):n===3||n===4?t[e]=i.readUInt16BE(0):n===5||n===6?t[e]=i.readUInt32BE(0):n===7||n===8?t[e]=i.readBigUInt64BE(0):t[e]=i}return t}function f(e){let t=d(e),n=t.mlit??t;return{title:n.minm,artist:n.asar,albumArtist:n.asaa,album:n.asal,composer:n.ascp,genre:n.asgn,duration:n.astm===void 0?void 0:n.astm/1e3,trackNumber:n.astn,trackCount:n.astc,discNumber:n.asdn,discCount:n.asdc,year:n.asyr,bitrate:n.asbr,sampleRate:n.assr,size:n.assz}}var p=e({decode:()=>_,encode:()=>v,now:()=>m,ns:()=>h,parts:()=>g});function m(){let e=h()/1000n,t=e/1000000n,n=e-t*1000000n;return t+2208988800n<<32n|(n<<32n)/1000000n}function h(){return process.hrtime.bigint()}function g(e){return[Number(e>>32n),Number(e&4294967295n)]}function _(e){if(e.length<24)throw RangeError(`NTP packet too small: expected at least 24 bytes, got ${e.length}`);return{proto:e.readUInt8(0),type:e.readUInt8(1),seqno:e.readUInt16BE(2),padding:e.readUInt32BE(4),reftime_sec:e.readUInt32BE(8),reftime_frac:e.readUInt32BE(12),recvtime_sec:e.readUInt32BE(16),recvtime_frac:e.readUInt32BE(20),sendtime_sec:e.length>=28?e.readUInt32BE(24):0,sendtime_frac:e.length>=32?e.readUInt32BE(28):0}}function v(e){let t=Buffer.allocUnsafe(32);return t.writeUInt8(e.proto,0),t.writeUInt8(e.type,1),t.writeUInt16BE(e.seqno,2),t.writeUInt32BE(e.padding,4),t.writeUInt32BE(e.reftime_sec,8),t.writeUInt32BE(e.reftime_frac,12),t.writeUInt32BE(e.recvtime_sec,16),t.writeUInt32BE(e.recvtime_frac,20),t.writeUInt32BE(e.sendtime_sec,24),t.writeUInt32BE(e.sendtime_frac,28),t}var y=e({decode:()=>re,encode:()=>ie,float:()=>te,int:()=>ne,sizedInteger:()=>T});const b={TRUE:1,FALSE:2,TERMINATOR:3,NULL:4,UUID:5,TIMESTAMP:6,INT_BASE:8,INT_INLINE_MAX_VALUE:39,INT_MAX_INLINE:47,INT_1BYTE:48,INT_2BYTE:49,INT_4BYTE:50,INT_8BYTE:51,FLOAT32:53,FLOAT64:54,STR_BASE:64,STR_MAX_INLINE:96,STR_1BYTE_LEN:97,STR_2BYTE_LEN:98,STR_3BYTE_LEN:99,STR_4BYTE_LEN:100,BYTES_BASE:112,BYTES_MAX_INLINE:144,BYTES_1BYTE_LEN:145,BYTES_2BYTE_LEN:146,BYTES_4BYTE_LEN:147,REF_BASE:160,REF_MAX_INLINE:192,REF_1BYTE:193,REF_2BYTE:194,REF_4BYTE:195,REF_8BYTE:196,ARRAY_BASE:208,ARRAY_VARIABLE:223,DICT_BASE:224,DICT_VARIABLE:239,DICT_TERMINATOR:129},x=new TextDecoder,ee=new TextEncoder;var S=class{get value(){return this.#e}#e;constructor(e){this.#e=e}},C=class{get value(){return this.#e}#e;constructor(e){this.#e=e}},w=class{get size(){return this.#e}get value(){return this.#t}#e;#t;constructor(e,t){this.#e=t,this.#t=e}valueOf(){return this.#t}};function te(e){return new S(e)}function ne(e){return new C(e)}function T(e,t){return new w(e,t)}function re(e){return A(e,0,[]).value}function ie(e){return k(e,[])}function E(e){return Uint8Array.of(e)}function D(e,t){let n=new Uint8Array(t),r=BigInt(e);for(let e=0;e<t;e++)n[e]=Number(r&255n),r>>=8n;return n}function O(e,t,n){if(n===1)return e[t];if(n===2)return e[t]|e[t+1]<<8;if(n===4)return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24>>>0;{let r=0n;for(let i=n-1;i>=0;i--)r=r<<8n|BigInt(e[t+i]);return Number(r)}}function k(e,t){let n=null;if(e==null)n=E(b.NULL);else if(typeof e==`boolean`)n=E(e?b.TRUE:b.FALSE);else if(e instanceof S)n=new Uint8Array(9),n[0]=b.FLOAT64,new DataView(n.buffer,n.byteOffset+1,8).setFloat64(0,e.value,!0);else if(e instanceof C){let t=e.value;t<=b.INT_INLINE_MAX_VALUE?n=E(b.INT_BASE+t):t<=255?(n=new Uint8Array(2),n[0]=b.INT_1BYTE,n[1]=t):t<=65535?(n=new Uint8Array(3),n[0]=b.INT_2BYTE,n[1]=t&255,n[2]=t>>8&255):t<=4294967295?(n=new Uint8Array(5),n[0]=b.INT_4BYTE,n[1]=t&255,n[2]=t>>8&255,n[3]=t>>16&255,n[4]=t>>24&255):(n=new Uint8Array(9),n[0]=b.INT_8BYTE,n.set(D(t,8),1))}else if(typeof e==`number`)Number.isInteger(e)?e<=b.INT_INLINE_MAX_VALUE?n=E(b.INT_BASE+e):e<=255?(n=new Uint8Array(2),n[0]=b.INT_1BYTE,n[1]=e):e<=65535?(n=new Uint8Array(3),n[0]=b.INT_2BYTE,n[1]=e&255,n[2]=e>>8&255):e<=4294967295?(n=new Uint8Array(5),n[0]=b.INT_4BYTE,n[1]=e&255,n[2]=e>>8&255,n[3]=e>>16&255,n[4]=e>>24&255):(n=new Uint8Array(9),n[0]=b.INT_8BYTE,n.set(D(e,8),1)):(n=new Uint8Array(9),n[0]=b.FLOAT64,new DataView(n.buffer,n.byteOffset+1,8).setFloat64(0,e,!0));else if(e instanceof w){let t=e.size;if(n=new Uint8Array(t+1),n[0]=b.INT_1BYTE+(31-Math.clz32(t)),t===1)n[1]=e.valueOf();else if(t===2){let t=e.valueOf();n[1]=t&255,n[2]=t>>8&255}else if(t===4){let t=e.valueOf();n[1]=t&255,n[2]=t>>8&255,n[3]=t>>16&255,n[4]=t>>24&255}else n.set(D(e.valueOf(),8),1)}else if(typeof e==`string`){let t=ee.encode(e),r=t.length;r<=32?(n=new Uint8Array(1+r),n[0]=b.STR_BASE+r,n.set(t,1)):r<=255?(n=new Uint8Array(2+r),n[0]=b.STR_1BYTE_LEN,n[1]=r,n.set(t,2)):r<=65535?(n=new Uint8Array(3+r),n[0]=b.STR_2BYTE_LEN,n[1]=r&255,n[2]=r>>8&255,n.set(t,3)):r<=16777215?(n=new Uint8Array(4+r),n[0]=b.STR_3BYTE_LEN,n[1]=r&255,n[2]=r>>8&255,n[3]=r>>16&255,n.set(t,4)):(n=new Uint8Array(5+r),n[0]=b.STR_4BYTE_LEN,n[1]=r&255,n[2]=r>>8&255,n[3]=r>>16&255,n[4]=r>>24&255,n.set(t,5))}else if(e instanceof Uint8Array||Buffer.isBuffer(e)){let t=e instanceof Uint8Array?e:new Uint8Array(e),r=t.length;r<=32?(n=new Uint8Array(1+r),n[0]=b.BYTES_BASE+r,n.set(t,1)):r<=255?(n=new Uint8Array(2+r),n[0]=b.BYTES_1BYTE_LEN,n[1]=r,n.set(t,2)):r<=65535?(n=new Uint8Array(3+r),n[0]=b.BYTES_2BYTE_LEN,n[1]=r&255,n[2]=r>>8&255,n.set(t,3)):(n=new Uint8Array(5+r),n[0]=b.BYTES_4BYTE_LEN,n[1]=r&255,n[2]=r>>8&255,n[3]=r>>16&255,n[4]=r>>24&255,n.set(t,5))}else if(Array.isArray(e)){let r=e.map(e=>k(e,t)),i=r.reduce((e,t)=>e+t.length,0),a=e.length;if(a<15){n=new Uint8Array(1+i),n[0]=b.ARRAY_BASE+a;let e=1;for(let t of r)n.set(t,e),e+=t.length}else{n=new Uint8Array(2+i),n[0]=b.ARRAY_VARIABLE;let e=1;for(let t of r)n.set(t,e),e+=t.length;n[e]=b.TERMINATOR}}else if(typeof e==`object`){let r=Object.keys(e),i=r.length,a=[],o=0;for(let n of r){let r=k(n,t),i=k(e[n],t);a.push(r,i),o+=r.length+i.length}let s=i>=15;n=new Uint8Array(1+o+(s?1:0)),n[0]=i<=15?b.DICT_BASE+i:b.DICT_VARIABLE;let c=1;for(let e of a)n.set(e,c),c+=e.length;s&&(n[c]=b.DICT_TERMINATOR)}else throw TypeError(typeof e);let r=t.findIndex(e=>e.length===n.length&&e.every((e,t)=>e===n[t]));return r>=0?r<33?n=E(b.REF_BASE+r):r<=255?(n=new Uint8Array(2),n[0]=b.REF_1BYTE,n[1]=r):r<=65535?(n=new Uint8Array(3),n[0]=b.REF_2BYTE,n[1]=r&255,n[2]=r>>8&255):r<=4294967295?(n=new Uint8Array(5),n[0]=b.REF_4BYTE,n[1]=r&255,n[2]=r>>8&255,n[3]=r>>16&255,n[4]=r>>24&255):(n=new Uint8Array(9),n[0]=b.REF_8BYTE,n.set(D(r,8),1)):n.length>1&&t.push(n),n}function A(e,t,n){if(t>=e.length)throw TypeError(`No data to unpack`);let r=e[t],i=!0,a,o;if(r===b.TRUE)a=!0,o=t+1;else if(r===b.FALSE)a=!1,o=t+1;else if(r===b.NULL)a=null,o=t+1;else if(r===b.UUID)a=e.subarray(t+1,t+17),o=t+17;else if(r===b.TIMESTAMP)a=O(e,t+1,8),o=t+9;else if(r>=b.INT_BASE&&r<=b.INT_MAX_INLINE)a=r-b.INT_BASE,o=t+1;else if(r===b.FLOAT32)a=new DataView(e.buffer,e.byteOffset+t+1,4).getFloat32(0,!0),o=t+5;else if(r===b.FLOAT64)a=new DataView(e.buffer,e.byteOffset+t+1,8).getFloat64(0,!0),o=t+9;else if((r&240)===b.INT_1BYTE){let n=1<<(r&15);a=T(O(e,t+1,n),n),o=t+1+n}else if(r>=b.STR_BASE&&r<=b.STR_MAX_INLINE){let n=r-b.STR_BASE;a=x.decode(e.subarray(t+1,t+1+n)),o=t+1+n}else if(r>=b.STR_1BYTE_LEN&&r<=b.STR_4BYTE_LEN){let n=r&15,i=O(e,t+1,n),s=t+1+n;a=x.decode(e.subarray(s,s+i)),o=s+i}else if(r>=b.BYTES_BASE&&r<=b.BYTES_MAX_INLINE){let n=r-b.BYTES_BASE;a=e.subarray(t+1,t+1+n),o=t+1+n}else if(r>=b.BYTES_1BYTE_LEN&&r<=b.BYTES_4BYTE_LEN){let n=1<<(r&15)-1,i=O(e,t+1,n),s=t+1+n;a=e.subarray(s,s+i),o=s+i}else if((r&240)===b.ARRAY_BASE){let s=r&15,c=t+1;if(s===15){let t=[];for(;e[c]!==b.TERMINATOR;){let r=A(e,c,n);t.push(r.value),c=r.offset}c++,a=t}else{let t=Array(s);for(let r=0;r<s;r++){let i=A(e,c,n);t[r]=i.value,c=i.offset}a=t}o=c,i=!1}else if((r&240)===b.DICT_BASE){let s=r&15,c={},l=t+1;if(s===15){for(;e[l]!==b.TERMINATOR;){let t=A(e,l,n),r=A(e,t.offset,n);c[t.value]=r.value,l=r.offset}l++}else for(let t=0;t<s;t++){let t=A(e,l,n),r=A(e,t.offset,n);c[t.value]=r.value,l=r.offset}a=c,o=l,i=!1}else if(r>=b.REF_BASE&&r<=b.REF_MAX_INLINE){let e=r-b.REF_BASE;if(e>=n.length)throw TypeError(`Reference index ${e} out of range`);a=n[e],o=t+1,i=!1}else if(r>=b.REF_1BYTE&&r<=b.REF_8BYTE){let s=r-b.REF_MAX_INLINE,c=O(e,t+1,s);if(c>=n.length)throw TypeError(`UID ${c} out of range`);a=n[c],o=t+1+s,i=!1}else throw TypeError(`Unknown tag 0x${r.toString(16)}`);return i&&n.push(a),{value:a,offset:o}}const j=9783072e5,M=`bplist00`;var ae;(function(e){e[e.BINARY=0]=`BINARY`,e[e.XML=1]=`XML`,e[e.OPENSTEP=2]=`OPENSTEP`})(ae||={});const N=100*1e3*1e3,P=new TextDecoder(`utf-8`),oe=new TextDecoder(`utf-16`);function F(e,t=0){return new DataView(e).getFloat64(t,!1)}function se(e,t=0){return new DataView(e).getFloat32(t,!1)}function I(e,t=0){return new DataView(e).getUint8(t)}function ce(e,t=0){return new DataView(e).getUint16(t,!1)}function le(e,t=0){return new DataView(e).getUint32(t,!1)}function L(e,t=0){return new DataView(e).getBigUint64(t,!1)}function R(e){switch(e.byteLength){case 1:return I(e);case 2:return ce(e);case 4:return le(e);case 8:return L(e);case 16:return L(e,8)}throw Error(`Invalid unsigned int length: ${e.byteLength}`)}function z(e,t=0){return new DataView(e).getInt8(t)}function ue(e,t=0){return new DataView(e).getInt16(t,!1)}function B(e,t=0){return new DataView(e).getInt32(t,!1)}function V(e,t=0){return new DataView(e).getBigInt64(t,!1)}function H(e){switch(e.byteLength){case 1:return z(e);case 2:return ue(e);case 4:return B(e);case 8:return V(e);case 16:return L(e,8)}throw Error(`Invalid int length: ${e.byteLength}`)}function U(e){let t=new Uint8Array(e);for(let e=0;e<t.length;e+=2){let n=t[e];t[e]=t[e+1],t[e+1]=n}return t.buffer}const de=e=>{let t=e.slice(0,8);if(P.decode(t)!==M)throw Error(`Invalid binary plist. Expected '${M}' at offset 0.`);let n=e.slice(e.byteLength-32,e.byteLength),r=I(n,6),i=I(n,7),a=Number(L(n,8)),o=Number(L(n,16)),s=Number(L(n,24));if(a>32768)throw Error(`maxObjectCount exceeded`);let c=[];for(let t=0;t<a;t++){let n=e.slice(s+t*r,s+(t+1)*r);c[t]=Number(R(n))}function l(t){let n=c[t],r=I(e,n),a=(r&240)>>4,o=r&15;switch(a){case 0:return s();case 1:return u();case 8:return d();case 2:return f();case 3:return p();case 4:return m();case 5:return h();case 6:return h(!0);case 10:return g();case 13:return _();default:throw Error(`Unhandled type 0x`+a.toString(16))}function s(){switch(o){case 0:return null;case 8:return!1;case 9:return!0;case 15:return null;default:throw Error(`Unhandled simple type 0x`+a.toString(16))}}function u(){let t=2**o;if(t<N)return H(e.slice(n+1,n+1+t));throw Error(`Too little heap space available! Wanted to read `+t+` bytes, but only 100000000 are available.`)}function d(){let t=o+1;if(t<N)return{CF$UID:R(e.slice(n+1,n+1+t))};throw Error(`Too little heap space available! Wanted to read `+t+` bytes, but only 100000000 are available.`)}function f(){let t=2**o;if(t<N){let r=e.slice(n+1,n+1+t);if(t===4)return se(r);if(t===8)return F(r);throw Error(`Invalid real length: ${t}`)}else throw Error(`Too little heap space available! Wanted to read `+t+` bytes, but only 100000000 are available.`)}function p(){o!=3&&console.error(`Unknown date type :`+o+`. Parsing anyway...`);let t=e.slice(n+1,n+9);return new Date(j+1e3*F(t))}function m(){let t=1,r=o;if(o==15){let i=z(e,n+1),a=(i&240)/16;a!=1&&console.error(`0x4: UNEXPECTED LENGTH-INT TYPE! `+a);let o=2**(i&15);t=2+o,r=Number(R(e.slice(n+2,n+2+o)))}if(r<N)return e.slice(n+t,n+t+Number(r));throw Error(`Too little heap space available! Wanted to read `+r+` bytes, but only 100000000 are available.`)}function h(t=!1){let r=o,i=1;if(o==15){let t=I(e,n+1),a=(t&240)/16;a!=1&&console.error(`UNEXPECTED LENGTH-INT TYPE! `+a);let o=2**(t&15);i=2+o,r=Number(R(e.slice(n+2,n+2+o)))}if(r*=t?2:1,r<N){let a=e.slice(n+i,n+i+r);return t?(a=U(a),oe.decode(a)):P.decode(a)}throw Error(`Too little heap space available! Wanted to read `+r+` bytes, but only 100000000 are available.`)}function g(){let t=o,r=1;if(o==15){let i=I(e,n+1),a=(i&240)/16;a!=1&&console.error(`0xa: UNEXPECTED LENGTH-INT TYPE! `+a);let o=2**(i&15);r=2+o,t=Number(R(e.slice(n+2,n+2+o)))}if(t*i>N)throw Error(`Too little heap space available!`);let a=[];for(let o=0;o<t;o++)a[o]=l(Number(R(e.slice(n+r+o*i,n+r+(o+1)*i))));return a}function _(){let t=o,r=1;if(o==15){let i=I(e,n+1),a=(i&240)/16;a!=1&&console.error(`0xD: UNEXPECTED LENGTH-INT TYPE! `+a);let o=2**(i&15);r=2+o,t=Number(R(e.slice(n+2,n+2+o)))}if(t*2*i>N)throw Error(`Too little heap space available!`);let a={};for(let o=0;o<t;o++){let s=Number(R(e.slice(n+r+o*i,n+r+(o+1)*i))),c=Number(R(e.slice(n+r+t*i+o*i,n+r+t*i+(o+1)*i))),u=l(s);if(typeof u!=`string`)throw Error(`Invalid key type.`);if(u===`__proto__`)throw Error(`Attempted prototype pollution`);a[u]=l(c)}return a}}return l(o)},W=new TextEncoder,fe=new Uint8Array([0,0,0,0,0,0]),pe=e=>Uint8Array.from(e.match(/.{1,2}/g).map(e=>parseInt(e,16))),G=e=>!!e&&typeof e==`object`&&Object.keys(e).length==1&&typeof e.CF$UID==`number`,me=e=>{let t=new ArrayBuffer(e.length*2),n=new Uint16Array(t);for(let t=0,r=e.length;t<r;t++)n[t]=e.charCodeAt(t);return new Uint8Array(t)},K=(e,t)=>{let n=new Uint8Array(e.length+t.length);return n.set(e),n.set(t,e.length),n},q=(e,t,n)=>{let r=new Uint8Array(e.length+n),i=new DataView(r.buffer);switch(r.set(e),n){case 1:i.setUint8(e.length,Number(t));break;case 2:i.setUint16(e.length,Number(t),!1);break;case 4:i.setUint32(e.length,Number(t),!1);break;case 8:i.setBigUint64(e.length,BigInt(t),!1);break;default:throw Error(`Unsupported int size`)}return r},he=(e,t,n)=>{let r=new Uint8Array(e.length+n),i=new DataView(r.buffer);switch(r.set(e),n){case 1:i.setInt8(e.length,Number(t));break;case 2:i.setInt16(e.length,Number(t),!1);break;case 4:i.setInt32(e.length,Number(t),!1);break;case 8:i.setBigInt64(e.length,BigInt(t),!1);break;default:throw Error(`Unsupported int size`)}return r},J=(e,t)=>{let n=new Uint8Array(e.length+8),r=new DataView(n.buffer);return n.set(e),r.setFloat64(e.length,t),n},ge=e=>{let t=W.encode(M);e instanceof Array&&e.length===1&&(e=e[0]);let n=Y(e),r=xe(n.length),i=[],a,o;return s(),n.forEach((e,n)=>{i[n]=t.byteLength,e==null?t=q(t,0,1):u(e)}),l(),c(),t.buffer;function s(){let e={},t=0;n.forEach(n=>{n.id||(typeof n.value==`string`?e.hasOwnProperty(n.value)?(n.type=`stringref`,n.id=e[n.value]):e[n.value]=n.id=t++:n.id=t++)}),n=n.filter(e=>e.type!==`stringref`)}function c(){t=K(t,fe),t=K(t,new Uint8Array([a,r])),t=q(t,BigInt(n.length),8),t=q(t,BigInt(`0`),8),t=q(t,BigInt(o),8)}function l(){o=t.byteLength,a=be(o),i.forEach(e=>{t=q(t,e,a)})}function u(e){if(e.type===`primitive`){let t=e.value;switch(typeof t){case`number`:case`bigint`:p(t);break;case`string`:_(t);break;case`boolean`:g(t);break}t instanceof Date?d(t):t instanceof ArrayBuffer?v(t):G(t)&&m(t.CF$UID);return}switch(e.type){case`dict`:f(e);break;case`array`:h(e);break;default:throw Error(`unhandled entry type: `+e.type)}}function d(e){t=q(t,51,1);let n=(e.getTime()-j)/1e3;t=J(t,n)}function f(e){y(13,e.entryKeys.length),e.entryKeys.forEach(e=>{b(e.id)}),e.entryValues.forEach(e=>{b(e.id)})}function p(e){if(typeof e==`bigint`){let n=pe(e.toString(16).padStart(32,`0`).slice(0,32));t=q(t,20,1),t=K(t,n)}else Number.isInteger(e)?e<0?(t=q(t,19,1),t=he(t,e,8)):e<=255?(t=q(t,16,1),t=q(t,e,1)):e<=65535?(t=q(t,17,1),t=q(t,e,2)):e<=4294967295?(t=q(t,18,1),t=q(t,e,4)):(t=q(t,19,1),t=q(t,e,8)):(t=q(t,35,1),t=J(t,e))}function m(e){y(8,0),b(e)}function h(e){y(10,e.entries.length),e.entries.forEach(e=>{b(e.id)})}function g(e){t=q(t,e?9:8,1)}function _(e){if(x(e)){let n=me(e);y(6,n.length/2);for(let e=0;e<n.length;e+=2){let t=n[e+0];n[e+0]=n[e+1],n[e+1]=t}t=K(t,n)}else{let n=W.encode(e);y(5,n.length),t=K(t,n)}}function v(e){y(4,e.byteLength),t=K(t,new Uint8Array(e))}function y(e,n){n<15?t=q(t,(e<<4)+n,1):(t=q(t,(e<<4)+15,1),p(n))}function b(e){t=q(t,e,r)}function x(e){return W.encode(e).byteLength!=e.length}},_e=[`string`,`number`,`boolean`,`bigint`];function Y(e){if(_e.includes(typeof e)||e instanceof ArrayBuffer||e instanceof Date||G(e))return[{type:`primitive`,value:e}];if(typeof e==`object`&&e)return Array.isArray(e)?ve(e):ye(e);throw Error(`unhandled entry: `+e)}function ve(e){let t=e.map(Y);return[{type:`array`,value:void 0,entries:t.map(e=>e[0])},...t.flat()]}function ye(e){let t=Object.keys(e).map(Y).flat(1),n=Object.values(e).map(Y);return[{type:`dict`,value:void 0,entryKeys:t,entryValues:n.map(e=>e[0])},...t,...n.flat()]}function be(e){return e<256?1:e<65536?2:e<4294967296?4:8}function xe(e){return e<256?1:e<65536?2:4}var Se=e({parse:()=>de,serialize:()=>ge}),Ce=e({makeHeader:()=>we,makeRequest:()=>Te,makeResponse:()=>Ee});function we(e,t,n,r,i,a,o){let s=[];s.push(`${e} ${t} RTSP/1.0`),s.push(`CSeq: ${r}`),s.push(`Active-Remote: ${i}`),s.push(`Client-Instance: ${a}`),s.push(`DACP-ID: ${a}`),s.push(`User-Agent: AirPlay/320.20`),s.push(`X-Apple-ProtocolVersion: 1`),s.push(`X-Apple-Session-ID: ${o}`),s.push(`X-ProtocolVersion: 1`);for(let[e,t]of Object.entries(n))s.push(`${e}: ${t}`);return s.push(``),s.push(``),s.join(`\r
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { t as __exportAll } from "./chunk-DQk6qfdC.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/daap.ts
|
|
4
|
+
var daap_exports = /* @__PURE__ */ __exportAll({
|
|
5
|
+
ContentCode: () => ContentCode,
|
|
6
|
+
TagType: () => TagType,
|
|
7
|
+
decode: () => decode$3,
|
|
8
|
+
decodeTag: () => decodeTag,
|
|
9
|
+
decodeToObject: () => decodeToObject,
|
|
10
|
+
decodeTrackMetadata: () => decodeTrackMetadata,
|
|
11
|
+
encodeContainer: () => encodeContainer,
|
|
12
|
+
encodePlaybackStatus: () => encodePlaybackStatus,
|
|
13
|
+
encodeTag: () => encodeTag,
|
|
14
|
+
encodeTagWithSize: () => encodeTagWithSize,
|
|
15
|
+
encodeTrackMetadata: () => encodeTrackMetadata
|
|
16
|
+
});
|
|
17
|
+
const ContentCode = {
|
|
18
|
+
mlit: "dmap.listingitem",
|
|
19
|
+
mlcl: "dmap.listing",
|
|
20
|
+
msrv: "dmap.serverinforesponse",
|
|
21
|
+
mcon: "dmap.container",
|
|
22
|
+
miid: "dmap.itemid",
|
|
23
|
+
minm: "dmap.itemname",
|
|
24
|
+
mikd: "dmap.itemkind",
|
|
25
|
+
mper: "dmap.persistentid",
|
|
26
|
+
asal: "daap.songalbum",
|
|
27
|
+
asar: "daap.songartist",
|
|
28
|
+
asaa: "daap.songalbumartist",
|
|
29
|
+
ascp: "daap.songcomposer",
|
|
30
|
+
asgn: "daap.songgenre",
|
|
31
|
+
astm: "daap.songtime",
|
|
32
|
+
astn: "daap.songtracknumber",
|
|
33
|
+
asdc: "daap.songdisccount",
|
|
34
|
+
asdn: "daap.songdiscnumber",
|
|
35
|
+
astc: "daap.songtrackcount",
|
|
36
|
+
asyr: "daap.songyear",
|
|
37
|
+
asbr: "daap.songbitrate",
|
|
38
|
+
assr: "daap.songsamplerate",
|
|
39
|
+
assz: "daap.songsize",
|
|
40
|
+
caps: "daap.songplaystatus",
|
|
41
|
+
cash: "daap.songshufflestate",
|
|
42
|
+
carp: "daap.songrepeatstate",
|
|
43
|
+
cavs: "daap.songvisiblestate",
|
|
44
|
+
aePP: "com.apple.itunes.photo-properties"
|
|
45
|
+
};
|
|
46
|
+
const TagType = {
|
|
47
|
+
mlit: 12,
|
|
48
|
+
mlcl: 12,
|
|
49
|
+
mcon: 12,
|
|
50
|
+
msrv: 12,
|
|
51
|
+
miid: 5,
|
|
52
|
+
minm: 9,
|
|
53
|
+
mikd: 1,
|
|
54
|
+
mper: 7,
|
|
55
|
+
asal: 9,
|
|
56
|
+
asar: 9,
|
|
57
|
+
asaa: 9,
|
|
58
|
+
ascp: 9,
|
|
59
|
+
asgn: 9,
|
|
60
|
+
astm: 5,
|
|
61
|
+
astn: 3,
|
|
62
|
+
asdc: 3,
|
|
63
|
+
asdn: 3,
|
|
64
|
+
astc: 3,
|
|
65
|
+
asyr: 3,
|
|
66
|
+
asbr: 3,
|
|
67
|
+
assr: 5,
|
|
68
|
+
assz: 5,
|
|
69
|
+
caps: 1,
|
|
70
|
+
cash: 1,
|
|
71
|
+
carp: 1,
|
|
72
|
+
cavs: 1,
|
|
73
|
+
aePP: 9
|
|
74
|
+
};
|
|
75
|
+
function encodeTag(tag, value) {
|
|
76
|
+
if (tag.length !== 4) throw new Error(`Invalid DAAP tag: ${tag}. Tags must be exactly 4 characters.`);
|
|
77
|
+
const tagBuffer = Buffer.from(tag, "ascii");
|
|
78
|
+
let valueBuffer;
|
|
79
|
+
if (typeof value === "string") valueBuffer = Buffer.from(value, "utf8");
|
|
80
|
+
else if (typeof value === "bigint") {
|
|
81
|
+
valueBuffer = Buffer.alloc(8);
|
|
82
|
+
valueBuffer.writeBigUInt64BE(value, 0);
|
|
83
|
+
} else if (typeof value === "number") if (value <= 255 && value >= 0) {
|
|
84
|
+
valueBuffer = Buffer.alloc(1);
|
|
85
|
+
valueBuffer.writeUInt8(value, 0);
|
|
86
|
+
} else if (value <= 65535 && value >= 0) {
|
|
87
|
+
valueBuffer = Buffer.alloc(2);
|
|
88
|
+
valueBuffer.writeUInt16BE(value, 0);
|
|
89
|
+
} else if (value <= 4294967295 && value >= 0) {
|
|
90
|
+
valueBuffer = Buffer.alloc(4);
|
|
91
|
+
valueBuffer.writeUInt32BE(value, 0);
|
|
92
|
+
} else {
|
|
93
|
+
valueBuffer = Buffer.alloc(8);
|
|
94
|
+
valueBuffer.writeBigInt64BE(BigInt(value), 0);
|
|
95
|
+
}
|
|
96
|
+
else valueBuffer = value;
|
|
97
|
+
const lengthBuffer = Buffer.allocUnsafe(4);
|
|
98
|
+
lengthBuffer.writeUInt32BE(valueBuffer.length, 0);
|
|
99
|
+
return Buffer.concat([
|
|
100
|
+
tagBuffer,
|
|
101
|
+
lengthBuffer,
|
|
102
|
+
valueBuffer
|
|
103
|
+
]);
|
|
104
|
+
}
|
|
105
|
+
function encodeContainer(tag, content) {
|
|
106
|
+
if (tag.length !== 4) throw new Error(`Invalid DAAP tag: ${tag}. Tags must be exactly 4 characters.`);
|
|
107
|
+
const tagBuffer = Buffer.from(tag, "ascii");
|
|
108
|
+
const lengthBuffer = Buffer.alloc(4);
|
|
109
|
+
lengthBuffer.writeUInt32BE(content.length, 0);
|
|
110
|
+
return Buffer.concat([
|
|
111
|
+
tagBuffer,
|
|
112
|
+
lengthBuffer,
|
|
113
|
+
content
|
|
114
|
+
]);
|
|
115
|
+
}
|
|
116
|
+
function encodePlaybackStatus(status) {
|
|
117
|
+
const tags = [];
|
|
118
|
+
if (status.playing !== void 0) tags.push(encodeTagWithSize("caps", status.playing ? 4 : 3, 1));
|
|
119
|
+
if (status.shuffle !== void 0) tags.push(encodeTagWithSize("cash", status.shuffle ? 1 : 0, 1));
|
|
120
|
+
if (status.repeat !== void 0) {
|
|
121
|
+
let repeatValue = 0;
|
|
122
|
+
if (status.repeat === "one") repeatValue = 1;
|
|
123
|
+
else if (status.repeat === "all") repeatValue = 2;
|
|
124
|
+
tags.push(encodeTagWithSize("carp", repeatValue, 1));
|
|
125
|
+
}
|
|
126
|
+
return Buffer.concat(tags);
|
|
127
|
+
}
|
|
128
|
+
function encodeTagWithSize(tag, value, byteSize) {
|
|
129
|
+
if (tag.length !== 4) throw new Error(`Invalid DAAP tag: ${tag}. Tags must be exactly 4 characters.`);
|
|
130
|
+
const tagBuffer = Buffer.from(tag, "ascii");
|
|
131
|
+
const valueBuffer = Buffer.alloc(byteSize);
|
|
132
|
+
switch (byteSize) {
|
|
133
|
+
case 1:
|
|
134
|
+
valueBuffer.writeUInt8(value, 0);
|
|
135
|
+
break;
|
|
136
|
+
case 2:
|
|
137
|
+
valueBuffer.writeUInt16BE(value, 0);
|
|
138
|
+
break;
|
|
139
|
+
case 4:
|
|
140
|
+
valueBuffer.writeUInt32BE(value, 0);
|
|
141
|
+
break;
|
|
142
|
+
case 8:
|
|
143
|
+
valueBuffer.writeBigUInt64BE(BigInt(value), 0);
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
const lengthBuffer = Buffer.alloc(4);
|
|
147
|
+
lengthBuffer.writeUInt32BE(byteSize, 0);
|
|
148
|
+
return Buffer.concat([
|
|
149
|
+
tagBuffer,
|
|
150
|
+
lengthBuffer,
|
|
151
|
+
valueBuffer
|
|
152
|
+
]);
|
|
153
|
+
}
|
|
154
|
+
function encodeTrackMetadata(metadata) {
|
|
155
|
+
const tags = [];
|
|
156
|
+
if (metadata.title !== void 0) tags.push(encodeTag("minm", metadata.title));
|
|
157
|
+
if (metadata.artist !== void 0) tags.push(encodeTag("asar", metadata.artist));
|
|
158
|
+
if (metadata.albumArtist !== void 0) tags.push(encodeTag("asaa", metadata.albumArtist));
|
|
159
|
+
if (metadata.album !== void 0) tags.push(encodeTag("asal", metadata.album));
|
|
160
|
+
if (metadata.composer !== void 0) tags.push(encodeTag("ascp", metadata.composer));
|
|
161
|
+
if (metadata.genre !== void 0) tags.push(encodeTag("asgn", metadata.genre));
|
|
162
|
+
if (metadata.duration !== void 0) tags.push(encodeTagWithSize("astm", Math.floor(metadata.duration * 1e3), 4));
|
|
163
|
+
if (metadata.trackNumber !== void 0) tags.push(encodeTagWithSize("astn", metadata.trackNumber, 2));
|
|
164
|
+
if (metadata.trackCount !== void 0) tags.push(encodeTagWithSize("astc", metadata.trackCount, 2));
|
|
165
|
+
if (metadata.discNumber !== void 0) tags.push(encodeTagWithSize("asdn", metadata.discNumber, 2));
|
|
166
|
+
if (metadata.discCount !== void 0) tags.push(encodeTagWithSize("asdc", metadata.discCount, 2));
|
|
167
|
+
if (metadata.year !== void 0) tags.push(encodeTagWithSize("asyr", metadata.year, 2));
|
|
168
|
+
if (metadata.bitrate !== void 0) tags.push(encodeTagWithSize("asbr", metadata.bitrate, 2));
|
|
169
|
+
if (metadata.sampleRate !== void 0) tags.push(encodeTagWithSize("assr", metadata.sampleRate, 4));
|
|
170
|
+
if (metadata.size !== void 0) tags.push(encodeTagWithSize("assz", metadata.size, 4));
|
|
171
|
+
return encodeContainer("mlit", Buffer.concat(tags));
|
|
172
|
+
}
|
|
173
|
+
function decode$3(buffer) {
|
|
174
|
+
const tags = [];
|
|
175
|
+
let remaining = buffer;
|
|
176
|
+
while (remaining.length > 0) {
|
|
177
|
+
const result = decodeTag(remaining);
|
|
178
|
+
if (!result) break;
|
|
179
|
+
const [tag, rest] = result;
|
|
180
|
+
tags.push(tag);
|
|
181
|
+
remaining = rest;
|
|
182
|
+
}
|
|
183
|
+
return tags;
|
|
184
|
+
}
|
|
185
|
+
function decodeTag(buffer) {
|
|
186
|
+
if (buffer.length < 8) return null;
|
|
187
|
+
const tag = buffer.subarray(0, 4).toString("ascii");
|
|
188
|
+
const length = buffer.readUInt32BE(4);
|
|
189
|
+
if (buffer.length < 8 + length) return null;
|
|
190
|
+
const value = buffer.subarray(8, 8 + length);
|
|
191
|
+
const remaining = buffer.subarray(8 + length);
|
|
192
|
+
return [{
|
|
193
|
+
tag,
|
|
194
|
+
length,
|
|
195
|
+
value
|
|
196
|
+
}, remaining];
|
|
197
|
+
}
|
|
198
|
+
function decodeToObject(buffer) {
|
|
199
|
+
const result = {};
|
|
200
|
+
const tags = decode$3(buffer);
|
|
201
|
+
for (const { tag, value } of tags) {
|
|
202
|
+
const tagType = TagType[tag];
|
|
203
|
+
if (tagType === void 0) result[tag] = value;
|
|
204
|
+
else if (tagType === 12) result[tag] = decodeToObject(value);
|
|
205
|
+
else if (tagType === 9) result[tag] = value.toString("utf8");
|
|
206
|
+
else if (tagType === 1 || tagType === 2) result[tag] = value.readUInt8(0);
|
|
207
|
+
else if (tagType === 3 || tagType === 4) result[tag] = value.readUInt16BE(0);
|
|
208
|
+
else if (tagType === 5 || tagType === 6) result[tag] = value.readUInt32BE(0);
|
|
209
|
+
else if (tagType === 7 || tagType === 8) result[tag] = value.readBigUInt64BE(0);
|
|
210
|
+
else result[tag] = value;
|
|
211
|
+
}
|
|
212
|
+
return result;
|
|
213
|
+
}
|
|
214
|
+
function decodeTrackMetadata(buffer) {
|
|
215
|
+
const obj = decodeToObject(buffer);
|
|
216
|
+
const mlit = obj.mlit ?? obj;
|
|
217
|
+
return {
|
|
218
|
+
title: mlit.minm,
|
|
219
|
+
artist: mlit.asar,
|
|
220
|
+
albumArtist: mlit.asaa,
|
|
221
|
+
album: mlit.asal,
|
|
222
|
+
composer: mlit.ascp,
|
|
223
|
+
genre: mlit.asgn,
|
|
224
|
+
duration: mlit.astm !== void 0 ? mlit.astm / 1e3 : void 0,
|
|
225
|
+
trackNumber: mlit.astn,
|
|
226
|
+
trackCount: mlit.astc,
|
|
227
|
+
discNumber: mlit.asdn,
|
|
228
|
+
discCount: mlit.asdc,
|
|
229
|
+
year: mlit.asyr,
|
|
230
|
+
bitrate: mlit.asbr,
|
|
231
|
+
sampleRate: mlit.assr,
|
|
232
|
+
size: mlit.assz
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
//#endregion
|
|
237
|
+
//#region src/ntp.ts
|
|
238
|
+
var ntp_exports = /* @__PURE__ */ __exportAll({
|
|
239
|
+
decode: () => decode$2,
|
|
240
|
+
encode: () => encode$2,
|
|
241
|
+
now: () => now,
|
|
242
|
+
ns: () => ns,
|
|
243
|
+
parts: () => parts
|
|
244
|
+
});
|
|
245
|
+
const EPOCH$1 = 2208988800n;
|
|
246
|
+
function now() {
|
|
247
|
+
const now = ns() / 1000n;
|
|
248
|
+
const seconds = now / 1000000n;
|
|
249
|
+
const frac = now - seconds * 1000000n;
|
|
250
|
+
return seconds + EPOCH$1 << 32n | (frac << 32n) / 1000000n;
|
|
251
|
+
}
|
|
252
|
+
function ns() {
|
|
253
|
+
return process.hrtime.bigint();
|
|
254
|
+
}
|
|
255
|
+
function parts(ntp) {
|
|
256
|
+
return [Number(ntp >> 32n), Number(ntp & 4294967295n)];
|
|
257
|
+
}
|
|
258
|
+
function decode$2(buffer) {
|
|
259
|
+
if (buffer.length < 24) throw new RangeError(`NTP packet too small: expected at least 24 bytes, got ${buffer.length}`);
|
|
260
|
+
return {
|
|
261
|
+
proto: buffer.readUInt8(0),
|
|
262
|
+
type: buffer.readUInt8(1),
|
|
263
|
+
seqno: buffer.readUInt16BE(2),
|
|
264
|
+
padding: buffer.readUInt32BE(4),
|
|
265
|
+
reftime_sec: buffer.readUInt32BE(8),
|
|
266
|
+
reftime_frac: buffer.readUInt32BE(12),
|
|
267
|
+
recvtime_sec: buffer.readUInt32BE(16),
|
|
268
|
+
recvtime_frac: buffer.readUInt32BE(20),
|
|
269
|
+
sendtime_sec: buffer.length >= 28 ? buffer.readUInt32BE(24) : 0,
|
|
270
|
+
sendtime_frac: buffer.length >= 32 ? buffer.readUInt32BE(28) : 0
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
function encode$2(fields) {
|
|
274
|
+
const buffer = Buffer.allocUnsafe(32);
|
|
275
|
+
buffer.writeUInt8(fields.proto, 0);
|
|
276
|
+
buffer.writeUInt8(fields.type, 1);
|
|
277
|
+
buffer.writeUInt16BE(fields.seqno, 2);
|
|
278
|
+
buffer.writeUInt32BE(fields.padding, 4);
|
|
279
|
+
buffer.writeUInt32BE(fields.reftime_sec, 8);
|
|
280
|
+
buffer.writeUInt32BE(fields.reftime_frac, 12);
|
|
281
|
+
buffer.writeUInt32BE(fields.recvtime_sec, 16);
|
|
282
|
+
buffer.writeUInt32BE(fields.recvtime_frac, 20);
|
|
283
|
+
buffer.writeUInt32BE(fields.sendtime_sec, 24);
|
|
284
|
+
buffer.writeUInt32BE(fields.sendtime_frac, 28);
|
|
285
|
+
return buffer;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
//#endregion
|
|
289
|
+
//#region src/opack.ts
|
|
290
|
+
var opack_exports = /* @__PURE__ */ __exportAll({
|
|
291
|
+
decode: () => decode$1,
|
|
292
|
+
encode: () => encode$1,
|
|
293
|
+
float: () => float,
|
|
294
|
+
int: () => int,
|
|
295
|
+
sizedInteger: () => sizedInteger
|
|
296
|
+
});
|
|
297
|
+
const TAG = {
|
|
298
|
+
TRUE: 1,
|
|
299
|
+
FALSE: 2,
|
|
300
|
+
TERMINATOR: 3,
|
|
301
|
+
NULL: 4,
|
|
302
|
+
UUID: 5,
|
|
303
|
+
TIMESTAMP: 6,
|
|
304
|
+
INT_BASE: 8,
|
|
305
|
+
INT_INLINE_MAX_VALUE: 39,
|
|
306
|
+
INT_MAX_INLINE: 47,
|
|
307
|
+
INT_1BYTE: 48,
|
|
308
|
+
INT_2BYTE: 49,
|
|
309
|
+
INT_4BYTE: 50,
|
|
310
|
+
INT_8BYTE: 51,
|
|
311
|
+
FLOAT32: 53,
|
|
312
|
+
FLOAT64: 54,
|
|
313
|
+
STR_BASE: 64,
|
|
314
|
+
STR_MAX_INLINE: 96,
|
|
315
|
+
STR_1BYTE_LEN: 97,
|
|
316
|
+
STR_2BYTE_LEN: 98,
|
|
317
|
+
STR_3BYTE_LEN: 99,
|
|
318
|
+
STR_4BYTE_LEN: 100,
|
|
319
|
+
BYTES_BASE: 112,
|
|
320
|
+
BYTES_MAX_INLINE: 144,
|
|
321
|
+
BYTES_1BYTE_LEN: 145,
|
|
322
|
+
BYTES_2BYTE_LEN: 146,
|
|
323
|
+
BYTES_4BYTE_LEN: 147,
|
|
324
|
+
REF_BASE: 160,
|
|
325
|
+
REF_MAX_INLINE: 192,
|
|
326
|
+
REF_1BYTE: 193,
|
|
327
|
+
REF_2BYTE: 194,
|
|
328
|
+
REF_4BYTE: 195,
|
|
329
|
+
REF_8BYTE: 196,
|
|
330
|
+
ARRAY_BASE: 208,
|
|
331
|
+
ARRAY_VARIABLE: 223,
|
|
332
|
+
DICT_BASE: 224,
|
|
333
|
+
DICT_VARIABLE: 239,
|
|
334
|
+
DICT_TERMINATOR: 129
|
|
335
|
+
};
|
|
336
|
+
const textDecoder = new TextDecoder();
|
|
337
|
+
const textEncoder = new TextEncoder();
|
|
338
|
+
var Float = class {
|
|
339
|
+
get value() {
|
|
340
|
+
return this.#value;
|
|
341
|
+
}
|
|
342
|
+
#value;
|
|
343
|
+
constructor(value) {
|
|
344
|
+
this.#value = value;
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
var Integer = class {
|
|
348
|
+
get value() {
|
|
349
|
+
return this.#value;
|
|
350
|
+
}
|
|
351
|
+
#value;
|
|
352
|
+
constructor(value) {
|
|
353
|
+
this.#value = value;
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
var SizedInteger = class {
|
|
357
|
+
get size() {
|
|
358
|
+
return this.#size;
|
|
359
|
+
}
|
|
360
|
+
get value() {
|
|
361
|
+
return this.#value;
|
|
362
|
+
}
|
|
363
|
+
#size;
|
|
364
|
+
#value;
|
|
365
|
+
constructor(value, size) {
|
|
366
|
+
this.#size = size;
|
|
367
|
+
this.#value = value;
|
|
368
|
+
}
|
|
369
|
+
valueOf() {
|
|
370
|
+
return this.#value;
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
function float(value) {
|
|
374
|
+
return new Float(value);
|
|
375
|
+
}
|
|
376
|
+
function int(value) {
|
|
377
|
+
return new Integer(value);
|
|
378
|
+
}
|
|
379
|
+
function sizedInteger(value, size) {
|
|
380
|
+
return new SizedInteger(value, size);
|
|
381
|
+
}
|
|
382
|
+
function decode$1(data) {
|
|
383
|
+
return _unpackAt(data, 0, []).value;
|
|
384
|
+
}
|
|
385
|
+
function encode$1(data) {
|
|
386
|
+
return _pack(data, []);
|
|
387
|
+
}
|
|
388
|
+
function u8(b) {
|
|
389
|
+
return Uint8Array.of(b);
|
|
390
|
+
}
|
|
391
|
+
function uintToLEBytes(value, byteLen) {
|
|
392
|
+
const out = new Uint8Array(byteLen);
|
|
393
|
+
let v = BigInt(value);
|
|
394
|
+
for (let i = 0; i < byteLen; i++) {
|
|
395
|
+
out[i] = Number(v & 255n);
|
|
396
|
+
v >>= 8n;
|
|
397
|
+
}
|
|
398
|
+
return out;
|
|
399
|
+
}
|
|
400
|
+
function readLittleEndian(buf, offset, len) {
|
|
401
|
+
if (len === 1) return buf[offset];
|
|
402
|
+
else if (len === 2) return buf[offset] | buf[offset + 1] << 8;
|
|
403
|
+
else if (len === 4) return buf[offset] | buf[offset + 1] << 8 | buf[offset + 2] << 16 | buf[offset + 3] << 24 >>> 0;
|
|
404
|
+
else {
|
|
405
|
+
let v = 0n;
|
|
406
|
+
for (let i = len - 1; i >= 0; i--) v = v << 8n | BigInt(buf[offset + i]);
|
|
407
|
+
return Number(v);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
function _pack(data, objectList) {
|
|
411
|
+
let packed = null;
|
|
412
|
+
if (data === null || data === void 0) packed = u8(TAG.NULL);
|
|
413
|
+
else if (typeof data === "boolean") packed = u8(data ? TAG.TRUE : TAG.FALSE);
|
|
414
|
+
else if (data instanceof Float) {
|
|
415
|
+
packed = new Uint8Array(9);
|
|
416
|
+
packed[0] = TAG.FLOAT64;
|
|
417
|
+
new DataView(packed.buffer, packed.byteOffset + 1, 8).setFloat64(0, data.value, true);
|
|
418
|
+
} else if (data instanceof Integer) {
|
|
419
|
+
const val = data.value;
|
|
420
|
+
if (val <= TAG.INT_INLINE_MAX_VALUE) packed = u8(TAG.INT_BASE + val);
|
|
421
|
+
else if (val <= 255) {
|
|
422
|
+
packed = new Uint8Array(2);
|
|
423
|
+
packed[0] = TAG.INT_1BYTE;
|
|
424
|
+
packed[1] = val;
|
|
425
|
+
} else if (val <= 65535) {
|
|
426
|
+
packed = new Uint8Array(3);
|
|
427
|
+
packed[0] = TAG.INT_2BYTE;
|
|
428
|
+
packed[1] = val & 255;
|
|
429
|
+
packed[2] = val >> 8 & 255;
|
|
430
|
+
} else if (val <= 4294967295) {
|
|
431
|
+
packed = new Uint8Array(5);
|
|
432
|
+
packed[0] = TAG.INT_4BYTE;
|
|
433
|
+
packed[1] = val & 255;
|
|
434
|
+
packed[2] = val >> 8 & 255;
|
|
435
|
+
packed[3] = val >> 16 & 255;
|
|
436
|
+
packed[4] = val >> 24 & 255;
|
|
437
|
+
} else {
|
|
438
|
+
packed = new Uint8Array(9);
|
|
439
|
+
packed[0] = TAG.INT_8BYTE;
|
|
440
|
+
packed.set(uintToLEBytes(val, 8), 1);
|
|
441
|
+
}
|
|
442
|
+
} else if (typeof data === "number") if (!Number.isInteger(data)) {
|
|
443
|
+
packed = new Uint8Array(9);
|
|
444
|
+
packed[0] = TAG.FLOAT64;
|
|
445
|
+
new DataView(packed.buffer, packed.byteOffset + 1, 8).setFloat64(0, data, true);
|
|
446
|
+
} else if (data <= TAG.INT_INLINE_MAX_VALUE) packed = u8(TAG.INT_BASE + data);
|
|
447
|
+
else if (data <= 255) {
|
|
448
|
+
packed = new Uint8Array(2);
|
|
449
|
+
packed[0] = TAG.INT_1BYTE;
|
|
450
|
+
packed[1] = data;
|
|
451
|
+
} else if (data <= 65535) {
|
|
452
|
+
packed = new Uint8Array(3);
|
|
453
|
+
packed[0] = TAG.INT_2BYTE;
|
|
454
|
+
packed[1] = data & 255;
|
|
455
|
+
packed[2] = data >> 8 & 255;
|
|
456
|
+
} else if (data <= 4294967295) {
|
|
457
|
+
packed = new Uint8Array(5);
|
|
458
|
+
packed[0] = TAG.INT_4BYTE;
|
|
459
|
+
packed[1] = data & 255;
|
|
460
|
+
packed[2] = data >> 8 & 255;
|
|
461
|
+
packed[3] = data >> 16 & 255;
|
|
462
|
+
packed[4] = data >> 24 & 255;
|
|
463
|
+
} else {
|
|
464
|
+
packed = new Uint8Array(9);
|
|
465
|
+
packed[0] = TAG.INT_8BYTE;
|
|
466
|
+
packed.set(uintToLEBytes(data, 8), 1);
|
|
467
|
+
}
|
|
468
|
+
else if (data instanceof SizedInteger) {
|
|
469
|
+
const byteSize = data.size;
|
|
470
|
+
packed = new Uint8Array(byteSize + 1);
|
|
471
|
+
packed[0] = TAG.INT_1BYTE + (31 - Math.clz32(byteSize));
|
|
472
|
+
if (byteSize === 1) packed[1] = data.valueOf();
|
|
473
|
+
else if (byteSize === 2) {
|
|
474
|
+
const val = data.valueOf();
|
|
475
|
+
packed[1] = val & 255;
|
|
476
|
+
packed[2] = val >> 8 & 255;
|
|
477
|
+
} else if (byteSize === 4) {
|
|
478
|
+
const val = data.valueOf();
|
|
479
|
+
packed[1] = val & 255;
|
|
480
|
+
packed[2] = val >> 8 & 255;
|
|
481
|
+
packed[3] = val >> 16 & 255;
|
|
482
|
+
packed[4] = val >> 24 & 255;
|
|
483
|
+
} else packed.set(uintToLEBytes(data.valueOf(), 8), 1);
|
|
484
|
+
} else if (typeof data === "string") {
|
|
485
|
+
const b = textEncoder.encode(data);
|
|
486
|
+
const len = b.length;
|
|
487
|
+
if (len <= 32) {
|
|
488
|
+
packed = new Uint8Array(1 + len);
|
|
489
|
+
packed[0] = TAG.STR_BASE + len;
|
|
490
|
+
packed.set(b, 1);
|
|
491
|
+
} else if (len <= 255) {
|
|
492
|
+
packed = new Uint8Array(2 + len);
|
|
493
|
+
packed[0] = TAG.STR_1BYTE_LEN;
|
|
494
|
+
packed[1] = len;
|
|
495
|
+
packed.set(b, 2);
|
|
496
|
+
} else if (len <= 65535) {
|
|
497
|
+
packed = new Uint8Array(3 + len);
|
|
498
|
+
packed[0] = TAG.STR_2BYTE_LEN;
|
|
499
|
+
packed[1] = len & 255;
|
|
500
|
+
packed[2] = len >> 8 & 255;
|
|
501
|
+
packed.set(b, 3);
|
|
502
|
+
} else if (len <= 16777215) {
|
|
503
|
+
packed = new Uint8Array(4 + len);
|
|
504
|
+
packed[0] = TAG.STR_3BYTE_LEN;
|
|
505
|
+
packed[1] = len & 255;
|
|
506
|
+
packed[2] = len >> 8 & 255;
|
|
507
|
+
packed[3] = len >> 16 & 255;
|
|
508
|
+
packed.set(b, 4);
|
|
509
|
+
} else {
|
|
510
|
+
packed = new Uint8Array(5 + len);
|
|
511
|
+
packed[0] = TAG.STR_4BYTE_LEN;
|
|
512
|
+
packed[1] = len & 255;
|
|
513
|
+
packed[2] = len >> 8 & 255;
|
|
514
|
+
packed[3] = len >> 16 & 255;
|
|
515
|
+
packed[4] = len >> 24 & 255;
|
|
516
|
+
packed.set(b, 5);
|
|
517
|
+
}
|
|
518
|
+
} else if (data instanceof Uint8Array || Buffer.isBuffer(data)) {
|
|
519
|
+
const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);
|
|
520
|
+
const len = bytes.length;
|
|
521
|
+
if (len <= 32) {
|
|
522
|
+
packed = new Uint8Array(1 + len);
|
|
523
|
+
packed[0] = TAG.BYTES_BASE + len;
|
|
524
|
+
packed.set(bytes, 1);
|
|
525
|
+
} else if (len <= 255) {
|
|
526
|
+
packed = new Uint8Array(2 + len);
|
|
527
|
+
packed[0] = TAG.BYTES_1BYTE_LEN;
|
|
528
|
+
packed[1] = len;
|
|
529
|
+
packed.set(bytes, 2);
|
|
530
|
+
} else if (len <= 65535) {
|
|
531
|
+
packed = new Uint8Array(3 + len);
|
|
532
|
+
packed[0] = TAG.BYTES_2BYTE_LEN;
|
|
533
|
+
packed[1] = len & 255;
|
|
534
|
+
packed[2] = len >> 8 & 255;
|
|
535
|
+
packed.set(bytes, 3);
|
|
536
|
+
} else {
|
|
537
|
+
packed = new Uint8Array(5 + len);
|
|
538
|
+
packed[0] = TAG.BYTES_4BYTE_LEN;
|
|
539
|
+
packed[1] = len & 255;
|
|
540
|
+
packed[2] = len >> 8 & 255;
|
|
541
|
+
packed[3] = len >> 16 & 255;
|
|
542
|
+
packed[4] = len >> 24 & 255;
|
|
543
|
+
packed.set(bytes, 5);
|
|
544
|
+
}
|
|
545
|
+
} else if (Array.isArray(data)) {
|
|
546
|
+
const parts = data.map((d) => _pack(d, objectList));
|
|
547
|
+
const bodyLen = parts.reduce((sum, p) => sum + p.length, 0);
|
|
548
|
+
const len = data.length;
|
|
549
|
+
if (len < 15) {
|
|
550
|
+
packed = new Uint8Array(1 + bodyLen);
|
|
551
|
+
packed[0] = TAG.ARRAY_BASE + len;
|
|
552
|
+
let pos = 1;
|
|
553
|
+
for (const part of parts) {
|
|
554
|
+
packed.set(part, pos);
|
|
555
|
+
pos += part.length;
|
|
556
|
+
}
|
|
557
|
+
} else {
|
|
558
|
+
packed = new Uint8Array(2 + bodyLen);
|
|
559
|
+
packed[0] = TAG.ARRAY_VARIABLE;
|
|
560
|
+
let pos = 1;
|
|
561
|
+
for (const part of parts) {
|
|
562
|
+
packed.set(part, pos);
|
|
563
|
+
pos += part.length;
|
|
564
|
+
}
|
|
565
|
+
packed[pos] = TAG.TERMINATOR;
|
|
566
|
+
}
|
|
567
|
+
} else if (typeof data === "object") {
|
|
568
|
+
const keys = Object.keys(data);
|
|
569
|
+
const len = keys.length;
|
|
570
|
+
const parts = [];
|
|
571
|
+
let bodyLen = 0;
|
|
572
|
+
for (const k of keys) {
|
|
573
|
+
const keyPacked = _pack(k, objectList);
|
|
574
|
+
const valPacked = _pack(data[k], objectList);
|
|
575
|
+
parts.push(keyPacked, valPacked);
|
|
576
|
+
bodyLen += keyPacked.length + valPacked.length;
|
|
577
|
+
}
|
|
578
|
+
const needsTerminator = len >= 15;
|
|
579
|
+
packed = new Uint8Array(1 + bodyLen + (needsTerminator ? 1 : 0));
|
|
580
|
+
packed[0] = len <= 15 ? TAG.DICT_BASE + len : TAG.DICT_VARIABLE;
|
|
581
|
+
let pos = 1;
|
|
582
|
+
for (const part of parts) {
|
|
583
|
+
packed.set(part, pos);
|
|
584
|
+
pos += part.length;
|
|
585
|
+
}
|
|
586
|
+
if (needsTerminator) packed[pos] = TAG.DICT_TERMINATOR;
|
|
587
|
+
} else throw new TypeError(typeof data);
|
|
588
|
+
const idx = objectList.findIndex((v) => v.length === packed.length && v.every((x, i) => x === packed[i]));
|
|
589
|
+
if (idx >= 0) if (idx < 33) packed = u8(TAG.REF_BASE + idx);
|
|
590
|
+
else if (idx <= 255) {
|
|
591
|
+
packed = new Uint8Array(2);
|
|
592
|
+
packed[0] = TAG.REF_1BYTE;
|
|
593
|
+
packed[1] = idx;
|
|
594
|
+
} else if (idx <= 65535) {
|
|
595
|
+
packed = new Uint8Array(3);
|
|
596
|
+
packed[0] = TAG.REF_2BYTE;
|
|
597
|
+
packed[1] = idx & 255;
|
|
598
|
+
packed[2] = idx >> 8 & 255;
|
|
599
|
+
} else if (idx <= 4294967295) {
|
|
600
|
+
packed = new Uint8Array(5);
|
|
601
|
+
packed[0] = TAG.REF_4BYTE;
|
|
602
|
+
packed[1] = idx & 255;
|
|
603
|
+
packed[2] = idx >> 8 & 255;
|
|
604
|
+
packed[3] = idx >> 16 & 255;
|
|
605
|
+
packed[4] = idx >> 24 & 255;
|
|
606
|
+
} else {
|
|
607
|
+
packed = new Uint8Array(9);
|
|
608
|
+
packed[0] = TAG.REF_8BYTE;
|
|
609
|
+
packed.set(uintToLEBytes(idx, 8), 1);
|
|
610
|
+
}
|
|
611
|
+
else if (packed.length > 1) objectList.push(packed);
|
|
612
|
+
return packed;
|
|
613
|
+
}
|
|
614
|
+
function _unpackAt(data, offset, objectList) {
|
|
615
|
+
if (offset >= data.length) throw new TypeError("No data to unpack");
|
|
616
|
+
const tag = data[offset];
|
|
617
|
+
let addToObjectList = true;
|
|
618
|
+
let value;
|
|
619
|
+
let newOffset;
|
|
620
|
+
if (tag === TAG.TRUE) {
|
|
621
|
+
value = true;
|
|
622
|
+
newOffset = offset + 1;
|
|
623
|
+
} else if (tag === TAG.FALSE) {
|
|
624
|
+
value = false;
|
|
625
|
+
newOffset = offset + 1;
|
|
626
|
+
} else if (tag === TAG.NULL) {
|
|
627
|
+
value = null;
|
|
628
|
+
newOffset = offset + 1;
|
|
629
|
+
} else if (tag === TAG.UUID) {
|
|
630
|
+
value = data.subarray(offset + 1, offset + 17);
|
|
631
|
+
newOffset = offset + 17;
|
|
632
|
+
} else if (tag === TAG.TIMESTAMP) {
|
|
633
|
+
value = readLittleEndian(data, offset + 1, 8);
|
|
634
|
+
newOffset = offset + 9;
|
|
635
|
+
} else if (tag >= TAG.INT_BASE && tag <= TAG.INT_MAX_INLINE) {
|
|
636
|
+
value = tag - TAG.INT_BASE;
|
|
637
|
+
newOffset = offset + 1;
|
|
638
|
+
} else if (tag === TAG.FLOAT32) {
|
|
639
|
+
value = new DataView(data.buffer, data.byteOffset + offset + 1, 4).getFloat32(0, true);
|
|
640
|
+
newOffset = offset + 5;
|
|
641
|
+
} else if (tag === TAG.FLOAT64) {
|
|
642
|
+
value = new DataView(data.buffer, data.byteOffset + offset + 1, 8).getFloat64(0, true);
|
|
643
|
+
newOffset = offset + 9;
|
|
644
|
+
} else if ((tag & 240) === TAG.INT_1BYTE) {
|
|
645
|
+
const noOfBytes = 1 << (tag & 15);
|
|
646
|
+
value = sizedInteger(readLittleEndian(data, offset + 1, noOfBytes), noOfBytes);
|
|
647
|
+
newOffset = offset + 1 + noOfBytes;
|
|
648
|
+
} else if (tag >= TAG.STR_BASE && tag <= TAG.STR_MAX_INLINE) {
|
|
649
|
+
const length = tag - TAG.STR_BASE;
|
|
650
|
+
value = textDecoder.decode(data.subarray(offset + 1, offset + 1 + length));
|
|
651
|
+
newOffset = offset + 1 + length;
|
|
652
|
+
} else if (tag >= TAG.STR_1BYTE_LEN && tag <= TAG.STR_4BYTE_LEN) {
|
|
653
|
+
const lenBytes = tag & 15;
|
|
654
|
+
const length = readLittleEndian(data, offset + 1, lenBytes);
|
|
655
|
+
const start = offset + 1 + lenBytes;
|
|
656
|
+
value = textDecoder.decode(data.subarray(start, start + length));
|
|
657
|
+
newOffset = start + length;
|
|
658
|
+
} else if (tag >= TAG.BYTES_BASE && tag <= TAG.BYTES_MAX_INLINE) {
|
|
659
|
+
const length = tag - TAG.BYTES_BASE;
|
|
660
|
+
value = data.subarray(offset + 1, offset + 1 + length);
|
|
661
|
+
newOffset = offset + 1 + length;
|
|
662
|
+
} else if (tag >= TAG.BYTES_1BYTE_LEN && tag <= TAG.BYTES_4BYTE_LEN) {
|
|
663
|
+
const noOfBytes = 1 << (tag & 15) - 1;
|
|
664
|
+
const length = readLittleEndian(data, offset + 1, noOfBytes);
|
|
665
|
+
const start = offset + 1 + noOfBytes;
|
|
666
|
+
value = data.subarray(start, start + length);
|
|
667
|
+
newOffset = start + length;
|
|
668
|
+
} else if ((tag & 240) === TAG.ARRAY_BASE) {
|
|
669
|
+
const count = tag & 15;
|
|
670
|
+
let pos = offset + 1;
|
|
671
|
+
if (count === 15) {
|
|
672
|
+
const arr = [];
|
|
673
|
+
while (data[pos] !== TAG.TERMINATOR) {
|
|
674
|
+
const result = _unpackAt(data, pos, objectList);
|
|
675
|
+
arr.push(result.value);
|
|
676
|
+
pos = result.offset;
|
|
677
|
+
}
|
|
678
|
+
pos++;
|
|
679
|
+
value = arr;
|
|
680
|
+
} else {
|
|
681
|
+
const arr = new Array(count);
|
|
682
|
+
for (let i = 0; i < count; i++) {
|
|
683
|
+
const result = _unpackAt(data, pos, objectList);
|
|
684
|
+
arr[i] = result.value;
|
|
685
|
+
pos = result.offset;
|
|
686
|
+
}
|
|
687
|
+
value = arr;
|
|
688
|
+
}
|
|
689
|
+
newOffset = pos;
|
|
690
|
+
addToObjectList = false;
|
|
691
|
+
} else if ((tag & 240) === TAG.DICT_BASE) {
|
|
692
|
+
const count = tag & 15;
|
|
693
|
+
const obj = {};
|
|
694
|
+
let pos = offset + 1;
|
|
695
|
+
if (count === 15) {
|
|
696
|
+
while (data[pos] !== TAG.TERMINATOR) {
|
|
697
|
+
const keyResult = _unpackAt(data, pos, objectList);
|
|
698
|
+
const valResult = _unpackAt(data, keyResult.offset, objectList);
|
|
699
|
+
obj[keyResult.value] = valResult.value;
|
|
700
|
+
pos = valResult.offset;
|
|
701
|
+
}
|
|
702
|
+
pos++;
|
|
703
|
+
} else for (let i = 0; i < count; i++) {
|
|
704
|
+
const keyResult = _unpackAt(data, pos, objectList);
|
|
705
|
+
const valResult = _unpackAt(data, keyResult.offset, objectList);
|
|
706
|
+
obj[keyResult.value] = valResult.value;
|
|
707
|
+
pos = valResult.offset;
|
|
708
|
+
}
|
|
709
|
+
value = obj;
|
|
710
|
+
newOffset = pos;
|
|
711
|
+
addToObjectList = false;
|
|
712
|
+
} else if (tag >= TAG.REF_BASE && tag <= TAG.REF_MAX_INLINE) {
|
|
713
|
+
const idx = tag - TAG.REF_BASE;
|
|
714
|
+
if (idx >= objectList.length) throw new TypeError(`Reference index ${idx} out of range`);
|
|
715
|
+
value = objectList[idx];
|
|
716
|
+
newOffset = offset + 1;
|
|
717
|
+
addToObjectList = false;
|
|
718
|
+
} else if (tag >= TAG.REF_1BYTE && tag <= TAG.REF_8BYTE) {
|
|
719
|
+
const len = tag - TAG.REF_MAX_INLINE;
|
|
720
|
+
const uid = readLittleEndian(data, offset + 1, len);
|
|
721
|
+
if (uid >= objectList.length) throw new TypeError(`UID ${uid} out of range`);
|
|
722
|
+
value = objectList[uid];
|
|
723
|
+
newOffset = offset + 1 + len;
|
|
724
|
+
addToObjectList = false;
|
|
725
|
+
} else throw new TypeError(`Unknown tag 0x${tag.toString(16)}`);
|
|
726
|
+
if (addToObjectList) objectList.push(value);
|
|
727
|
+
return {
|
|
728
|
+
value,
|
|
729
|
+
offset: newOffset
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
//#endregion
|
|
734
|
+
//#region ../../node_modules/.bun/@plist+common@1.1.0/node_modules/@plist/common/lib/esm/constants.js
|
|
735
|
+
const EPOCH = 9783072e5;
|
|
736
|
+
const HEADER_BINARY = "bplist00";
|
|
737
|
+
var PlistFormat;
|
|
738
|
+
(function(PlistFormat) {
|
|
739
|
+
PlistFormat[PlistFormat["BINARY"] = 0] = "BINARY";
|
|
740
|
+
PlistFormat[PlistFormat["XML"] = 1] = "XML";
|
|
741
|
+
PlistFormat[PlistFormat["OPENSTEP"] = 2] = "OPENSTEP";
|
|
742
|
+
})(PlistFormat || (PlistFormat = {}));
|
|
743
|
+
|
|
744
|
+
//#endregion
|
|
745
|
+
//#region ../../node_modules/.bun/@plist+binary.parse@1.1.0/node_modules/@plist/binary.parse/lib/esm/index.js
|
|
746
|
+
const maxObjectSize = 100 * 1e3 * 1e3;
|
|
747
|
+
const maxObjectCount = 32768;
|
|
748
|
+
const DECODER_UTF8 = new TextDecoder("utf-8");
|
|
749
|
+
const DECODER_UTF16 = new TextDecoder("utf-16");
|
|
750
|
+
function readDouble(buffer, start = 0) {
|
|
751
|
+
return new DataView(buffer).getFloat64(start, false);
|
|
752
|
+
}
|
|
753
|
+
function readFloat(buffer, start = 0) {
|
|
754
|
+
return new DataView(buffer).getFloat32(start, false);
|
|
755
|
+
}
|
|
756
|
+
function readUInt8(buffer, start = 0) {
|
|
757
|
+
return new DataView(buffer).getUint8(start);
|
|
758
|
+
}
|
|
759
|
+
function readUInt16(buffer, start = 0) {
|
|
760
|
+
return new DataView(buffer).getUint16(start, false);
|
|
761
|
+
}
|
|
762
|
+
function readUInt32(buffer, start = 0) {
|
|
763
|
+
return new DataView(buffer).getUint32(start, false);
|
|
764
|
+
}
|
|
765
|
+
function readUInt64(buffer, start = 0) {
|
|
766
|
+
return new DataView(buffer).getBigUint64(start, false);
|
|
767
|
+
}
|
|
768
|
+
function readUInt(buffer) {
|
|
769
|
+
switch (buffer.byteLength) {
|
|
770
|
+
case 1: return readUInt8(buffer);
|
|
771
|
+
case 2: return readUInt16(buffer);
|
|
772
|
+
case 4: return readUInt32(buffer);
|
|
773
|
+
case 8: return readUInt64(buffer);
|
|
774
|
+
case 16: return readUInt64(buffer, 8);
|
|
775
|
+
}
|
|
776
|
+
throw new Error(`Invalid unsigned int length: ${buffer.byteLength}`);
|
|
777
|
+
}
|
|
778
|
+
function readInt8(buffer, start = 0) {
|
|
779
|
+
return new DataView(buffer).getInt8(start);
|
|
780
|
+
}
|
|
781
|
+
function readInt16(buffer, start = 0) {
|
|
782
|
+
return new DataView(buffer).getInt16(start, false);
|
|
783
|
+
}
|
|
784
|
+
function readInt32(buffer, start = 0) {
|
|
785
|
+
return new DataView(buffer).getInt32(start, false);
|
|
786
|
+
}
|
|
787
|
+
function readInt64(buffer, start = 0) {
|
|
788
|
+
return new DataView(buffer).getBigInt64(start, false);
|
|
789
|
+
}
|
|
790
|
+
function readInt(buffer) {
|
|
791
|
+
switch (buffer.byteLength) {
|
|
792
|
+
case 1: return readInt8(buffer);
|
|
793
|
+
case 2: return readInt16(buffer);
|
|
794
|
+
case 4: return readInt32(buffer);
|
|
795
|
+
case 8: return readInt64(buffer);
|
|
796
|
+
case 16: return readUInt64(buffer, 8);
|
|
797
|
+
}
|
|
798
|
+
throw new Error(`Invalid int length: ${buffer.byteLength}`);
|
|
799
|
+
}
|
|
800
|
+
function swapBytes(buffer) {
|
|
801
|
+
const array = new Uint8Array(buffer);
|
|
802
|
+
for (let i = 0; i < array.length; i += 2) {
|
|
803
|
+
const a = array[i];
|
|
804
|
+
array[i] = array[i + 1];
|
|
805
|
+
array[i + 1] = a;
|
|
806
|
+
}
|
|
807
|
+
return array.buffer;
|
|
808
|
+
}
|
|
809
|
+
const parse = (buffer) => {
|
|
810
|
+
const headerBytes = buffer.slice(0, HEADER_BINARY.length);
|
|
811
|
+
if (DECODER_UTF8.decode(headerBytes) !== HEADER_BINARY) throw new Error(`Invalid binary plist. Expected '${HEADER_BINARY}' at offset 0.`);
|
|
812
|
+
const trailer = buffer.slice(buffer.byteLength - 32, buffer.byteLength);
|
|
813
|
+
const offsetSize = readUInt8(trailer, 6);
|
|
814
|
+
const objectRefSize = readUInt8(trailer, 7);
|
|
815
|
+
const numObjects = Number(readUInt64(trailer, 8));
|
|
816
|
+
const topObject = Number(readUInt64(trailer, 16));
|
|
817
|
+
const offsetTableOffset = Number(readUInt64(trailer, 24));
|
|
818
|
+
if (numObjects > maxObjectCount) throw new Error("maxObjectCount exceeded");
|
|
819
|
+
const offsetTable = [];
|
|
820
|
+
for (let i = 0; i < numObjects; i++) {
|
|
821
|
+
const offsetBytes = buffer.slice(offsetTableOffset + i * offsetSize, offsetTableOffset + (i + 1) * offsetSize);
|
|
822
|
+
offsetTable[i] = Number(readUInt(offsetBytes));
|
|
823
|
+
}
|
|
824
|
+
function parseObject(tableOffset) {
|
|
825
|
+
const offset = offsetTable[tableOffset];
|
|
826
|
+
const type = readUInt8(buffer, offset);
|
|
827
|
+
const objType = (type & 240) >> 4;
|
|
828
|
+
const objInfo = type & 15;
|
|
829
|
+
switch (objType) {
|
|
830
|
+
case 0: return parseSimple();
|
|
831
|
+
case 1: return parseInteger();
|
|
832
|
+
case 8: return parseUID();
|
|
833
|
+
case 2: return parseReal();
|
|
834
|
+
case 3: return parseDate();
|
|
835
|
+
case 4: return parseData();
|
|
836
|
+
case 5: return parsePlistString();
|
|
837
|
+
case 6: return parsePlistString(true);
|
|
838
|
+
case 10: return parseArray();
|
|
839
|
+
case 13: return parseDictionary();
|
|
840
|
+
default: throw new Error("Unhandled type 0x" + objType.toString(16));
|
|
841
|
+
}
|
|
842
|
+
function parseSimple() {
|
|
843
|
+
switch (objInfo) {
|
|
844
|
+
case 0: return null;
|
|
845
|
+
case 8: return false;
|
|
846
|
+
case 9: return true;
|
|
847
|
+
case 15: return null;
|
|
848
|
+
default: throw new Error("Unhandled simple type 0x" + objType.toString(16));
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
function parseInteger() {
|
|
852
|
+
const length = Math.pow(2, objInfo);
|
|
853
|
+
if (length < maxObjectSize) return readInt(buffer.slice(offset + 1, offset + 1 + length));
|
|
854
|
+
throw new Error("Too little heap space available! Wanted to read " + length + " bytes, but only 100000000 are available.");
|
|
855
|
+
}
|
|
856
|
+
function parseUID() {
|
|
857
|
+
const length = objInfo + 1;
|
|
858
|
+
if (length < maxObjectSize) return { CF$UID: readUInt(buffer.slice(offset + 1, offset + 1 + length)) };
|
|
859
|
+
throw new Error("Too little heap space available! Wanted to read " + length + " bytes, but only 100000000 are available.");
|
|
860
|
+
}
|
|
861
|
+
function parseReal() {
|
|
862
|
+
const length = Math.pow(2, objInfo);
|
|
863
|
+
if (length < maxObjectSize) {
|
|
864
|
+
const realBuffer = buffer.slice(offset + 1, offset + 1 + length);
|
|
865
|
+
if (length === 4) return readFloat(realBuffer);
|
|
866
|
+
else if (length === 8) return readDouble(realBuffer);
|
|
867
|
+
throw new Error(`Invalid real length: ${length}`);
|
|
868
|
+
} else throw new Error("Too little heap space available! Wanted to read " + length + " bytes, but only 100000000 are available.");
|
|
869
|
+
}
|
|
870
|
+
function parseDate() {
|
|
871
|
+
if (objInfo != 3) console.error("Unknown date type :" + objInfo + ". Parsing anyway...");
|
|
872
|
+
const dateBuffer = buffer.slice(offset + 1, offset + 9);
|
|
873
|
+
return new Date(EPOCH + 1e3 * readDouble(dateBuffer));
|
|
874
|
+
}
|
|
875
|
+
function parseData() {
|
|
876
|
+
let dataoffset = 1;
|
|
877
|
+
let length = objInfo;
|
|
878
|
+
if (objInfo == 15) {
|
|
879
|
+
const int_type = readInt8(buffer, offset + 1);
|
|
880
|
+
const intType = (int_type & 240) / 16;
|
|
881
|
+
if (intType != 1) console.error("0x4: UNEXPECTED LENGTH-INT TYPE! " + intType);
|
|
882
|
+
const intInfo = int_type & 15;
|
|
883
|
+
const intLength = Math.pow(2, intInfo);
|
|
884
|
+
dataoffset = 2 + intLength;
|
|
885
|
+
length = Number(readUInt(buffer.slice(offset + 2, offset + 2 + intLength)));
|
|
886
|
+
}
|
|
887
|
+
if (length < maxObjectSize) return buffer.slice(offset + dataoffset, offset + dataoffset + Number(length));
|
|
888
|
+
throw new Error("Too little heap space available! Wanted to read " + length + " bytes, but only 100000000 are available.");
|
|
889
|
+
}
|
|
890
|
+
function parsePlistString(isUtf16 = false) {
|
|
891
|
+
let length = objInfo;
|
|
892
|
+
let stroffset = 1;
|
|
893
|
+
if (objInfo == 15) {
|
|
894
|
+
const int_type = readUInt8(buffer, offset + 1);
|
|
895
|
+
const intType = (int_type & 240) / 16;
|
|
896
|
+
if (intType != 1) console.error("UNEXPECTED LENGTH-INT TYPE! " + intType);
|
|
897
|
+
const intInfo = int_type & 15;
|
|
898
|
+
const intLength = Math.pow(2, intInfo);
|
|
899
|
+
stroffset = 2 + intLength;
|
|
900
|
+
length = Number(readUInt(buffer.slice(offset + 2, offset + 2 + intLength)));
|
|
901
|
+
}
|
|
902
|
+
length *= isUtf16 ? 2 : 1;
|
|
903
|
+
if (length < maxObjectSize) {
|
|
904
|
+
let plistString = buffer.slice(offset + stroffset, offset + stroffset + length);
|
|
905
|
+
if (isUtf16) {
|
|
906
|
+
plistString = swapBytes(plistString);
|
|
907
|
+
return DECODER_UTF16.decode(plistString);
|
|
908
|
+
} else return DECODER_UTF8.decode(plistString);
|
|
909
|
+
}
|
|
910
|
+
throw new Error("Too little heap space available! Wanted to read " + length + " bytes, but only 100000000 are available.");
|
|
911
|
+
}
|
|
912
|
+
function parseArray() {
|
|
913
|
+
let length = objInfo;
|
|
914
|
+
let arrayoffset = 1;
|
|
915
|
+
if (objInfo == 15) {
|
|
916
|
+
const int_type = readUInt8(buffer, offset + 1);
|
|
917
|
+
const intType = (int_type & 240) / 16;
|
|
918
|
+
if (intType != 1) console.error("0xa: UNEXPECTED LENGTH-INT TYPE! " + intType);
|
|
919
|
+
const intInfo = int_type & 15;
|
|
920
|
+
const intLength = Math.pow(2, intInfo);
|
|
921
|
+
arrayoffset = 2 + intLength;
|
|
922
|
+
length = Number(readUInt(buffer.slice(offset + 2, offset + 2 + intLength)));
|
|
923
|
+
}
|
|
924
|
+
if (length * objectRefSize > maxObjectSize) throw new Error("Too little heap space available!");
|
|
925
|
+
const array = [];
|
|
926
|
+
for (let i = 0; i < length; i++) array[i] = parseObject(Number(readUInt(buffer.slice(offset + arrayoffset + i * objectRefSize, offset + arrayoffset + (i + 1) * objectRefSize))));
|
|
927
|
+
return array;
|
|
928
|
+
}
|
|
929
|
+
function parseDictionary() {
|
|
930
|
+
let length = objInfo;
|
|
931
|
+
let dictoffset = 1;
|
|
932
|
+
if (objInfo == 15) {
|
|
933
|
+
const int_type = readUInt8(buffer, offset + 1);
|
|
934
|
+
const intType = (int_type & 240) / 16;
|
|
935
|
+
if (intType != 1) console.error("0xD: UNEXPECTED LENGTH-INT TYPE! " + intType);
|
|
936
|
+
const intInfo = int_type & 15;
|
|
937
|
+
const intLength = Math.pow(2, intInfo);
|
|
938
|
+
dictoffset = 2 + intLength;
|
|
939
|
+
length = Number(readUInt(buffer.slice(offset + 2, offset + 2 + intLength)));
|
|
940
|
+
}
|
|
941
|
+
if (length * 2 * objectRefSize > maxObjectSize) throw new Error("Too little heap space available!");
|
|
942
|
+
const dict = {};
|
|
943
|
+
for (let i = 0; i < length; i++) {
|
|
944
|
+
const keyRef = Number(readUInt(buffer.slice(offset + dictoffset + i * objectRefSize, offset + dictoffset + (i + 1) * objectRefSize)));
|
|
945
|
+
const valRef = Number(readUInt(buffer.slice(offset + dictoffset + length * objectRefSize + i * objectRefSize, offset + dictoffset + length * objectRefSize + (i + 1) * objectRefSize)));
|
|
946
|
+
const key = parseObject(keyRef);
|
|
947
|
+
if (typeof key !== "string") throw new Error("Invalid key type.");
|
|
948
|
+
if (key === "__proto__") throw new Error("Attempted prototype pollution");
|
|
949
|
+
dict[key] = parseObject(valRef);
|
|
950
|
+
}
|
|
951
|
+
return dict;
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
return parseObject(topObject);
|
|
955
|
+
};
|
|
956
|
+
|
|
957
|
+
//#endregion
|
|
958
|
+
//#region ../../node_modules/.bun/@plist+binary.serialize@1.1.0/node_modules/@plist/binary.serialize/lib/esm/index.js
|
|
959
|
+
const encoder = new TextEncoder();
|
|
960
|
+
const nullBytes = new Uint8Array([
|
|
961
|
+
0,
|
|
962
|
+
0,
|
|
963
|
+
0,
|
|
964
|
+
0,
|
|
965
|
+
0,
|
|
966
|
+
0
|
|
967
|
+
]);
|
|
968
|
+
const fromHexString = (hexString) => Uint8Array.from(hexString.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
|
|
969
|
+
const isUID = (value) => !!value && typeof value === "object" && Object.keys(value).length == 1 && typeof value.CF$UID === "number";
|
|
970
|
+
const toUTF16 = (string) => {
|
|
971
|
+
const buf = /* @__PURE__ */ new ArrayBuffer(string.length * 2);
|
|
972
|
+
const bufView = new Uint16Array(buf);
|
|
973
|
+
for (let i = 0, strLen = string.length; i < strLen; i++) bufView[i] = string.charCodeAt(i);
|
|
974
|
+
return new Uint8Array(buf);
|
|
975
|
+
};
|
|
976
|
+
const concat = (first, second) => {
|
|
977
|
+
const third = new Uint8Array(first.length + second.length);
|
|
978
|
+
third.set(first);
|
|
979
|
+
third.set(second, first.length);
|
|
980
|
+
return third;
|
|
981
|
+
};
|
|
982
|
+
const writeUInt = (buffer, int, size) => {
|
|
983
|
+
const output = new Uint8Array(buffer.length + size);
|
|
984
|
+
const dataView = new DataView(output.buffer);
|
|
985
|
+
output.set(buffer);
|
|
986
|
+
switch (size) {
|
|
987
|
+
case 1:
|
|
988
|
+
dataView.setUint8(buffer.length, Number(int));
|
|
989
|
+
break;
|
|
990
|
+
case 2:
|
|
991
|
+
dataView.setUint16(buffer.length, Number(int), false);
|
|
992
|
+
break;
|
|
993
|
+
case 4:
|
|
994
|
+
dataView.setUint32(buffer.length, Number(int), false);
|
|
995
|
+
break;
|
|
996
|
+
case 8:
|
|
997
|
+
dataView.setBigUint64(buffer.length, BigInt(int), false);
|
|
998
|
+
break;
|
|
999
|
+
default: throw new Error("Unsupported int size");
|
|
1000
|
+
}
|
|
1001
|
+
return output;
|
|
1002
|
+
};
|
|
1003
|
+
const writeInt = (buffer, int, size) => {
|
|
1004
|
+
const output = new Uint8Array(buffer.length + size);
|
|
1005
|
+
const dataView = new DataView(output.buffer);
|
|
1006
|
+
output.set(buffer);
|
|
1007
|
+
switch (size) {
|
|
1008
|
+
case 1:
|
|
1009
|
+
dataView.setInt8(buffer.length, Number(int));
|
|
1010
|
+
break;
|
|
1011
|
+
case 2:
|
|
1012
|
+
dataView.setInt16(buffer.length, Number(int), false);
|
|
1013
|
+
break;
|
|
1014
|
+
case 4:
|
|
1015
|
+
dataView.setInt32(buffer.length, Number(int), false);
|
|
1016
|
+
break;
|
|
1017
|
+
case 8:
|
|
1018
|
+
dataView.setBigInt64(buffer.length, BigInt(int), false);
|
|
1019
|
+
break;
|
|
1020
|
+
default: throw new Error("Unsupported int size");
|
|
1021
|
+
}
|
|
1022
|
+
return output;
|
|
1023
|
+
};
|
|
1024
|
+
const writeDouble = (buffer, double) => {
|
|
1025
|
+
const output = new Uint8Array(buffer.length + 8);
|
|
1026
|
+
const dataView = new DataView(output.buffer);
|
|
1027
|
+
output.set(buffer);
|
|
1028
|
+
dataView.setFloat64(buffer.length, double);
|
|
1029
|
+
return output;
|
|
1030
|
+
};
|
|
1031
|
+
const serialize = (value) => {
|
|
1032
|
+
let buffer = encoder.encode(HEADER_BINARY);
|
|
1033
|
+
if (value instanceof Array && value.length === 1) value = value[0];
|
|
1034
|
+
let entries = toEntries(value);
|
|
1035
|
+
const idSizeInBytes = computeIdSizeInBytes(entries.length);
|
|
1036
|
+
const offsets = [];
|
|
1037
|
+
let offsetSizeInBytes;
|
|
1038
|
+
let offsetTableOffset;
|
|
1039
|
+
updateEntryIds();
|
|
1040
|
+
entries.forEach((entry, entryIdx) => {
|
|
1041
|
+
offsets[entryIdx] = buffer.byteLength;
|
|
1042
|
+
if (typeof entry === "undefined" || entry === null) buffer = writeUInt(buffer, 0, 1);
|
|
1043
|
+
else write(entry);
|
|
1044
|
+
});
|
|
1045
|
+
writeOffsetTable();
|
|
1046
|
+
writeTrailer();
|
|
1047
|
+
return buffer.buffer;
|
|
1048
|
+
function updateEntryIds() {
|
|
1049
|
+
const strings = {};
|
|
1050
|
+
let entryId = 0;
|
|
1051
|
+
entries.forEach((entry) => {
|
|
1052
|
+
if (entry.id) return;
|
|
1053
|
+
if (typeof entry.value === "string") if (strings.hasOwnProperty(entry.value)) {
|
|
1054
|
+
entry.type = "stringref";
|
|
1055
|
+
entry.id = strings[entry.value];
|
|
1056
|
+
} else strings[entry.value] = entry.id = entryId++;
|
|
1057
|
+
else entry.id = entryId++;
|
|
1058
|
+
});
|
|
1059
|
+
entries = entries.filter((entry) => {
|
|
1060
|
+
return entry.type !== "stringref";
|
|
1061
|
+
});
|
|
1062
|
+
}
|
|
1063
|
+
function writeTrailer() {
|
|
1064
|
+
buffer = concat(buffer, nullBytes);
|
|
1065
|
+
buffer = concat(buffer, new Uint8Array([offsetSizeInBytes, idSizeInBytes]));
|
|
1066
|
+
buffer = writeUInt(buffer, BigInt(entries.length), 8);
|
|
1067
|
+
buffer = writeUInt(buffer, BigInt("0"), 8);
|
|
1068
|
+
buffer = writeUInt(buffer, BigInt(offsetTableOffset), 8);
|
|
1069
|
+
}
|
|
1070
|
+
function writeOffsetTable() {
|
|
1071
|
+
offsetTableOffset = buffer.byteLength;
|
|
1072
|
+
offsetSizeInBytes = computeOffsetSizeInBytes(offsetTableOffset);
|
|
1073
|
+
offsets.forEach((offset) => {
|
|
1074
|
+
buffer = writeUInt(buffer, offset, offsetSizeInBytes);
|
|
1075
|
+
});
|
|
1076
|
+
}
|
|
1077
|
+
function write(entry) {
|
|
1078
|
+
if (entry.type === "primitive") {
|
|
1079
|
+
const value = entry.value;
|
|
1080
|
+
switch (typeof value) {
|
|
1081
|
+
case "number":
|
|
1082
|
+
case "bigint":
|
|
1083
|
+
writeNumber(value);
|
|
1084
|
+
break;
|
|
1085
|
+
case "string":
|
|
1086
|
+
writeString(value);
|
|
1087
|
+
break;
|
|
1088
|
+
case "boolean":
|
|
1089
|
+
writeBoolean(value);
|
|
1090
|
+
break;
|
|
1091
|
+
}
|
|
1092
|
+
if (value instanceof Date) writeDate(value);
|
|
1093
|
+
else if (value instanceof ArrayBuffer) writeData(value);
|
|
1094
|
+
else if (isUID(value)) writeUID(value.CF$UID);
|
|
1095
|
+
return;
|
|
1096
|
+
}
|
|
1097
|
+
switch (entry.type) {
|
|
1098
|
+
case "dict":
|
|
1099
|
+
writeDict(entry);
|
|
1100
|
+
break;
|
|
1101
|
+
case "array":
|
|
1102
|
+
writeArray(entry);
|
|
1103
|
+
break;
|
|
1104
|
+
default: throw new Error("unhandled entry type: " + entry.type);
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
function writeDate(value) {
|
|
1108
|
+
buffer = writeUInt(buffer, 51, 1);
|
|
1109
|
+
const date = (value.getTime() - EPOCH) / 1e3;
|
|
1110
|
+
buffer = writeDouble(buffer, date);
|
|
1111
|
+
}
|
|
1112
|
+
function writeDict(entry) {
|
|
1113
|
+
writeIntHeader(13, entry.entryKeys.length);
|
|
1114
|
+
entry.entryKeys.forEach((entry) => {
|
|
1115
|
+
writeID(entry.id);
|
|
1116
|
+
});
|
|
1117
|
+
entry.entryValues.forEach((entry) => {
|
|
1118
|
+
writeID(entry.id);
|
|
1119
|
+
});
|
|
1120
|
+
}
|
|
1121
|
+
function writeNumber(value) {
|
|
1122
|
+
if (typeof value === "bigint") {
|
|
1123
|
+
const width = 16;
|
|
1124
|
+
const buf = fromHexString(value.toString(16).padStart(width * 2, "0").slice(0, width * 2));
|
|
1125
|
+
buffer = writeUInt(buffer, 20, 1);
|
|
1126
|
+
buffer = concat(buffer, buf);
|
|
1127
|
+
} else if (Number.isInteger(value)) if (value < 0) {
|
|
1128
|
+
buffer = writeUInt(buffer, 19, 1);
|
|
1129
|
+
buffer = writeInt(buffer, value, 8);
|
|
1130
|
+
} else if (value <= 255) {
|
|
1131
|
+
buffer = writeUInt(buffer, 16, 1);
|
|
1132
|
+
buffer = writeUInt(buffer, value, 1);
|
|
1133
|
+
} else if (value <= 65535) {
|
|
1134
|
+
buffer = writeUInt(buffer, 17, 1);
|
|
1135
|
+
buffer = writeUInt(buffer, value, 2);
|
|
1136
|
+
} else if (value <= 4294967295) {
|
|
1137
|
+
buffer = writeUInt(buffer, 18, 1);
|
|
1138
|
+
buffer = writeUInt(buffer, value, 4);
|
|
1139
|
+
} else {
|
|
1140
|
+
buffer = writeUInt(buffer, 19, 1);
|
|
1141
|
+
buffer = writeUInt(buffer, value, 8);
|
|
1142
|
+
}
|
|
1143
|
+
else {
|
|
1144
|
+
buffer = writeUInt(buffer, 35, 1);
|
|
1145
|
+
buffer = writeDouble(buffer, value);
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
function writeUID(uid) {
|
|
1149
|
+
writeIntHeader(8, 0);
|
|
1150
|
+
writeID(uid);
|
|
1151
|
+
}
|
|
1152
|
+
function writeArray(entry) {
|
|
1153
|
+
writeIntHeader(10, entry.entries.length);
|
|
1154
|
+
entry.entries.forEach((e) => {
|
|
1155
|
+
writeID(e.id);
|
|
1156
|
+
});
|
|
1157
|
+
}
|
|
1158
|
+
function writeBoolean(value) {
|
|
1159
|
+
buffer = writeUInt(buffer, value ? 9 : 8, 1);
|
|
1160
|
+
}
|
|
1161
|
+
function writeString(value) {
|
|
1162
|
+
if (mustBeUtf16(value)) {
|
|
1163
|
+
const utf16 = toUTF16(value);
|
|
1164
|
+
writeIntHeader(6, utf16.length / 2);
|
|
1165
|
+
for (let i = 0; i < utf16.length; i += 2) {
|
|
1166
|
+
const t = utf16[i + 0];
|
|
1167
|
+
utf16[i + 0] = utf16[i + 1];
|
|
1168
|
+
utf16[i + 1] = t;
|
|
1169
|
+
}
|
|
1170
|
+
buffer = concat(buffer, utf16);
|
|
1171
|
+
} else {
|
|
1172
|
+
const utf8 = encoder.encode(value);
|
|
1173
|
+
writeIntHeader(5, utf8.length);
|
|
1174
|
+
buffer = concat(buffer, utf8);
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
function writeData(data) {
|
|
1178
|
+
writeIntHeader(4, data.byteLength);
|
|
1179
|
+
buffer = concat(buffer, new Uint8Array(data));
|
|
1180
|
+
}
|
|
1181
|
+
function writeIntHeader(kind, value) {
|
|
1182
|
+
if (value < 15) buffer = writeUInt(buffer, (kind << 4) + value, 1);
|
|
1183
|
+
else {
|
|
1184
|
+
buffer = writeUInt(buffer, (kind << 4) + 15, 1);
|
|
1185
|
+
writeNumber(value);
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
function writeID(id) {
|
|
1189
|
+
buffer = writeUInt(buffer, id, idSizeInBytes);
|
|
1190
|
+
}
|
|
1191
|
+
function mustBeUtf16(string) {
|
|
1192
|
+
return encoder.encode(string).byteLength != string.length;
|
|
1193
|
+
}
|
|
1194
|
+
};
|
|
1195
|
+
const typeofPrimitive = [
|
|
1196
|
+
"string",
|
|
1197
|
+
"number",
|
|
1198
|
+
"boolean",
|
|
1199
|
+
"bigint"
|
|
1200
|
+
];
|
|
1201
|
+
function toEntries(value) {
|
|
1202
|
+
if (typeofPrimitive.includes(typeof value) || value instanceof ArrayBuffer || value instanceof Date || isUID(value)) return [{
|
|
1203
|
+
type: "primitive",
|
|
1204
|
+
value
|
|
1205
|
+
}];
|
|
1206
|
+
if (value != null && typeof value === "object") return Array.isArray(value) ? toEntriesArray(value) : toEntriesObject(value);
|
|
1207
|
+
throw new Error("unhandled entry: " + value);
|
|
1208
|
+
}
|
|
1209
|
+
function toEntriesArray(array) {
|
|
1210
|
+
const entries = array.map(toEntries);
|
|
1211
|
+
return [{
|
|
1212
|
+
type: "array",
|
|
1213
|
+
value: void 0,
|
|
1214
|
+
entries: entries.map((entries) => entries[0])
|
|
1215
|
+
}, ...entries.flat()];
|
|
1216
|
+
}
|
|
1217
|
+
function toEntriesObject(dict) {
|
|
1218
|
+
const entryKeys = Object.keys(dict).map(toEntries).flat(1);
|
|
1219
|
+
const entryValues = Object.values(dict).map(toEntries);
|
|
1220
|
+
return [
|
|
1221
|
+
{
|
|
1222
|
+
type: "dict",
|
|
1223
|
+
value: void 0,
|
|
1224
|
+
entryKeys,
|
|
1225
|
+
entryValues: entryValues.map((entries) => entries[0])
|
|
1226
|
+
},
|
|
1227
|
+
...entryKeys,
|
|
1228
|
+
...entryValues.flat()
|
|
1229
|
+
];
|
|
1230
|
+
}
|
|
1231
|
+
function computeOffsetSizeInBytes(maxOffset) {
|
|
1232
|
+
if (maxOffset < 256) return 1;
|
|
1233
|
+
if (maxOffset < 65536) return 2;
|
|
1234
|
+
if (maxOffset < 4294967296) return 4;
|
|
1235
|
+
return 8;
|
|
1236
|
+
}
|
|
1237
|
+
function computeIdSizeInBytes(numberOfIds) {
|
|
1238
|
+
if (numberOfIds < 256) return 1;
|
|
1239
|
+
if (numberOfIds < 65536) return 2;
|
|
1240
|
+
return 4;
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
//#endregion
|
|
1244
|
+
//#region src/plist.ts
|
|
1245
|
+
var plist_exports = /* @__PURE__ */ __exportAll({
|
|
1246
|
+
parse: () => parse,
|
|
1247
|
+
serialize: () => serialize
|
|
1248
|
+
});
|
|
1249
|
+
|
|
1250
|
+
//#endregion
|
|
1251
|
+
//#region src/rtsp.ts
|
|
1252
|
+
var rtsp_exports = /* @__PURE__ */ __exportAll({
|
|
1253
|
+
makeHeader: () => makeHeader,
|
|
1254
|
+
makeRequest: () => makeRequest,
|
|
1255
|
+
makeResponse: () => makeResponse
|
|
1256
|
+
});
|
|
1257
|
+
function makeHeader(method, path, headers, cseq, activeRemote, dacpId, sessionId) {
|
|
1258
|
+
const lines = [];
|
|
1259
|
+
lines.push(`${method} ${path} RTSP/1.0`);
|
|
1260
|
+
lines.push(`CSeq: ${cseq}`);
|
|
1261
|
+
lines.push(`Active-Remote: ${activeRemote}`);
|
|
1262
|
+
lines.push(`Client-Instance: ${dacpId}`);
|
|
1263
|
+
lines.push(`DACP-ID: ${dacpId}`);
|
|
1264
|
+
lines.push("User-Agent: AirPlay/320.20");
|
|
1265
|
+
lines.push("X-Apple-ProtocolVersion: 1");
|
|
1266
|
+
lines.push(`X-Apple-Session-ID: ${sessionId}`);
|
|
1267
|
+
lines.push("X-ProtocolVersion: 1");
|
|
1268
|
+
for (const [name, value] of Object.entries(headers)) lines.push(`${name}: ${value}`);
|
|
1269
|
+
lines.push("");
|
|
1270
|
+
lines.push("");
|
|
1271
|
+
return lines.join("\r\n");
|
|
1272
|
+
}
|
|
1273
|
+
function makeRequest(buffer) {
|
|
1274
|
+
const headerLength = buffer.indexOf("\r\n\r\n");
|
|
1275
|
+
const { headers, method, path } = parseRequestHeaders(buffer.subarray(0, headerLength));
|
|
1276
|
+
let contentLength = headers["Content-Length"] ? Number(headers["Content-Length"]) : 0;
|
|
1277
|
+
if (isNaN(contentLength)) contentLength = 0;
|
|
1278
|
+
const requestLength = headerLength + 4 + contentLength;
|
|
1279
|
+
if (buffer.byteLength < requestLength) return null;
|
|
1280
|
+
return {
|
|
1281
|
+
headers,
|
|
1282
|
+
method,
|
|
1283
|
+
path,
|
|
1284
|
+
body: buffer.subarray(headerLength + 4, requestLength),
|
|
1285
|
+
requestLength
|
|
1286
|
+
};
|
|
1287
|
+
}
|
|
1288
|
+
function makeResponse(buffer) {
|
|
1289
|
+
const headerLength = buffer.indexOf("\r\n\r\n");
|
|
1290
|
+
const { headers, status, statusText } = parseResponseHeaders(buffer.subarray(0, headerLength));
|
|
1291
|
+
let contentLength = headers["Content-Length"] ? Number(headers["Content-Length"]) : 0;
|
|
1292
|
+
if (isNaN(contentLength)) contentLength = 0;
|
|
1293
|
+
const responseLength = headerLength + 4 + contentLength;
|
|
1294
|
+
if (buffer.byteLength < responseLength) return null;
|
|
1295
|
+
const body = buffer.subarray(headerLength + 4, responseLength);
|
|
1296
|
+
return {
|
|
1297
|
+
response: new Response(body, {
|
|
1298
|
+
status,
|
|
1299
|
+
statusText,
|
|
1300
|
+
headers
|
|
1301
|
+
}),
|
|
1302
|
+
responseLength
|
|
1303
|
+
};
|
|
1304
|
+
}
|
|
1305
|
+
function parseHeaders(lines) {
|
|
1306
|
+
const headers = {};
|
|
1307
|
+
for (let i = 0; i < lines.length; i++) {
|
|
1308
|
+
const colon = lines[i].indexOf(":");
|
|
1309
|
+
if (colon <= 0) continue;
|
|
1310
|
+
const name = lines[i].substring(0, colon).trim();
|
|
1311
|
+
headers[name] = lines[i].substring(colon + 1).trim();
|
|
1312
|
+
}
|
|
1313
|
+
return headers;
|
|
1314
|
+
}
|
|
1315
|
+
function parseRequestHeaders(buffer) {
|
|
1316
|
+
const lines = buffer.toString("utf8").split("\r\n");
|
|
1317
|
+
const rawRequest = lines[0].match(/^(\S+)\s+(\S+)\s+RTSP\/1\.0$/);
|
|
1318
|
+
const method = rawRequest[1];
|
|
1319
|
+
const path = rawRequest[2];
|
|
1320
|
+
return {
|
|
1321
|
+
headers: parseHeaders(lines.slice(1)),
|
|
1322
|
+
method,
|
|
1323
|
+
path
|
|
1324
|
+
};
|
|
1325
|
+
}
|
|
1326
|
+
function parseResponseHeaders(buffer) {
|
|
1327
|
+
const lines = buffer.toString("utf8").split("\r\n");
|
|
1328
|
+
const rawStatus = lines[0].match(/(HTTP|RTSP)\/[\d.]+\s+(\d+)\s+(.+)/);
|
|
1329
|
+
const status = Number(rawStatus[2]);
|
|
1330
|
+
const statusText = rawStatus[3];
|
|
1331
|
+
return {
|
|
1332
|
+
headers: parseHeaders(lines.slice(1)),
|
|
1333
|
+
status,
|
|
1334
|
+
statusText
|
|
1335
|
+
};
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
//#endregion
|
|
1339
|
+
//#region src/tlv8.ts
|
|
1340
|
+
var tlv8_exports = /* @__PURE__ */ __exportAll({
|
|
1341
|
+
ErrorCode: () => ErrorCode,
|
|
1342
|
+
Flags: () => Flags,
|
|
1343
|
+
Method: () => Method,
|
|
1344
|
+
State: () => State,
|
|
1345
|
+
Value: () => Value,
|
|
1346
|
+
bail: () => bail,
|
|
1347
|
+
decode: () => decode,
|
|
1348
|
+
encode: () => encode
|
|
1349
|
+
});
|
|
1350
|
+
const Flags = { TransientPairing: 16 };
|
|
1351
|
+
const ErrorCode = {
|
|
1352
|
+
Unknown: 1,
|
|
1353
|
+
Authentication: 2,
|
|
1354
|
+
BackOff: 3,
|
|
1355
|
+
MaxPeers: 4,
|
|
1356
|
+
MaxTries: 5,
|
|
1357
|
+
Unavailable: 6,
|
|
1358
|
+
Busy: 7
|
|
1359
|
+
};
|
|
1360
|
+
const Method = {
|
|
1361
|
+
PairSetup: 0,
|
|
1362
|
+
PairSetupWithAuth: 1,
|
|
1363
|
+
PairVerify: 2,
|
|
1364
|
+
AddPairing: 3,
|
|
1365
|
+
RemovePairing: 4,
|
|
1366
|
+
ListPairing: 5
|
|
1367
|
+
};
|
|
1368
|
+
const State = {
|
|
1369
|
+
M1: 1,
|
|
1370
|
+
M2: 2,
|
|
1371
|
+
M3: 3,
|
|
1372
|
+
M4: 4,
|
|
1373
|
+
M5: 5,
|
|
1374
|
+
M6: 6
|
|
1375
|
+
};
|
|
1376
|
+
const Value = {
|
|
1377
|
+
Method: 0,
|
|
1378
|
+
Identifier: 1,
|
|
1379
|
+
Salt: 2,
|
|
1380
|
+
PublicKey: 3,
|
|
1381
|
+
Proof: 4,
|
|
1382
|
+
EncryptedData: 5,
|
|
1383
|
+
State: 6,
|
|
1384
|
+
Error: 7,
|
|
1385
|
+
BackOff: 8,
|
|
1386
|
+
Certificate: 9,
|
|
1387
|
+
Signature: 10,
|
|
1388
|
+
Permissions: 11,
|
|
1389
|
+
FragmentData: 12,
|
|
1390
|
+
FragmentLast: 13,
|
|
1391
|
+
Name: 17,
|
|
1392
|
+
Flags: 19
|
|
1393
|
+
};
|
|
1394
|
+
function bail(data) {
|
|
1395
|
+
if (data.has(Value.BackOff)) {
|
|
1396
|
+
const buffer = data.get(Value.BackOff);
|
|
1397
|
+
const time = buffer.readUintLE(0, buffer.length);
|
|
1398
|
+
throw new Error(`Device is busy, try again in ${time} seconds.`);
|
|
1399
|
+
}
|
|
1400
|
+
if (data.has(Value.Error)) {
|
|
1401
|
+
const errorCode = Object.entries(ErrorCode).find(([_, code]) => code === data.get(Value.Error).readUint8());
|
|
1402
|
+
if (!errorCode) throw new Error(`Device returned an unknown error code: ${data.get(Value.Error).readUint8()}`);
|
|
1403
|
+
throw new Error(`Device returned an error code: ${errorCode[0]}`);
|
|
1404
|
+
}
|
|
1405
|
+
throw new Error("Invalid response");
|
|
1406
|
+
}
|
|
1407
|
+
function encode(entries) {
|
|
1408
|
+
let totalSize = 0;
|
|
1409
|
+
for (const [, valueRaw] of entries) {
|
|
1410
|
+
const len = typeof valueRaw === "number" ? 1 : valueRaw.length;
|
|
1411
|
+
const chunks = Math.max(1, Math.ceil(len / 255));
|
|
1412
|
+
totalSize += chunks * 2 + len;
|
|
1413
|
+
}
|
|
1414
|
+
const result = Buffer.allocUnsafe(totalSize);
|
|
1415
|
+
let pos = 0;
|
|
1416
|
+
for (const [type, valueRaw] of entries) {
|
|
1417
|
+
let value;
|
|
1418
|
+
let valueLen;
|
|
1419
|
+
if (typeof valueRaw === "number") {
|
|
1420
|
+
value = Buffer.allocUnsafe(1);
|
|
1421
|
+
value[0] = valueRaw;
|
|
1422
|
+
valueLen = 1;
|
|
1423
|
+
} else {
|
|
1424
|
+
value = valueRaw;
|
|
1425
|
+
valueLen = value.length;
|
|
1426
|
+
}
|
|
1427
|
+
let offset = 0;
|
|
1428
|
+
do {
|
|
1429
|
+
const len = Math.min(valueLen - offset, 255);
|
|
1430
|
+
result[pos++] = type;
|
|
1431
|
+
result[pos++] = len;
|
|
1432
|
+
if (len > 0) {
|
|
1433
|
+
if (value instanceof Buffer) value.copy(result, pos, offset, offset + len);
|
|
1434
|
+
else result.set(value.subarray(offset, offset + len), pos);
|
|
1435
|
+
pos += len;
|
|
1436
|
+
}
|
|
1437
|
+
offset += len;
|
|
1438
|
+
} while (offset < valueLen);
|
|
1439
|
+
}
|
|
1440
|
+
return result;
|
|
1441
|
+
}
|
|
1442
|
+
function decode(buf) {
|
|
1443
|
+
const map = /* @__PURE__ */ new Map();
|
|
1444
|
+
let i = 0;
|
|
1445
|
+
while (i < buf.length) {
|
|
1446
|
+
const type = buf[i++];
|
|
1447
|
+
const len = buf[i++];
|
|
1448
|
+
const existing = map.get(type);
|
|
1449
|
+
if (existing) {
|
|
1450
|
+
const newBuf = Buffer.allocUnsafe(existing.length + len);
|
|
1451
|
+
existing.copy(newBuf, 0);
|
|
1452
|
+
buf.copy(newBuf, existing.length, i, i + len);
|
|
1453
|
+
map.set(type, newBuf);
|
|
1454
|
+
} else map.set(type, buf.subarray(i, i + len));
|
|
1455
|
+
i += len;
|
|
1456
|
+
}
|
|
1457
|
+
return map;
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
//#endregion
|
|
1461
|
+
export { daap_exports as DAAP, ntp_exports as NTP, opack_exports as OPack, plist_exports as Plist, rtsp_exports as RTSP, tlv8_exports as TLV8 };
|
|
9
1462
|
//# sourceMappingURL=index.mjs.map
|