exceeddata-sdk-vdata 2.10.5-2 → 2.10.8
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.
|
@@ -17,4 +17,4 @@
|
|
|
17
17
|
* let values = frame.objects();
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
|
-
const pako=require("pako");const fzstd=require("fzstd");class VDataRow{constructor(time,values){this._time=time;this._values=values}get[Symbol.toStringTag](){return"{time="+String(this._time)+", values="+String(this._values)+"}"}time(){return this._time}values(){return this._values}}class VDataRecord{constructor(time,values){this._time=time;this._values=values}get[Symbol.toStringTag](){return"{time="+String(this._time)+", values="+String(this._values)+"}"}time(){return this._time}values(){return this._values}}class VDataSeriesPair{constructor(time,value){this._time=time;this._value=value}get[Symbol.toStringTag](){return"{time="+String(this._time)+", value="+String(this._value)+"}"}time(){return this._time}value(){return this._value}}class VDataByteReader{constructor(_uint8array){this._data=_uint8array;this._length=this._data.length;this._pos=0}read(length){let _end=this._pos+length;if(_end>=this._length){_end=this._length}const _bb=this._data.slice(this._pos,_end);this._pos=_end;return _bb}seek(pos){if(pos>0){if(pos>=this._length){this._pos=this._length}else{this._pos=pos}}else{this._pos=0}}skip(length){if(length>0){let pos=this._pos+length;if(pos>=this._length){this._pos=this._length}else{this._pos=pos}}}close(){}}class VDataMeta{constructor(formatVersion=0,compressMethod=0,encryptMethod=0,blocksCount=0,storageStartTime=0,storageEndTime=0,queryStartTime=0,queryEndTime=0,extendedInfo=new Uint8Array(0),pageSizeCode=0,keyTypeCode=0,flag=0){this._formatVersion=formatVersion;this._compressMethod=compressMethod;this._encryptMethod=encryptMethod;this._blocksCount=blocksCount;this._storageStartTime=storageStartTime;this._storageEndTime=storageEndTime;this._queryStartTime=queryStartTime;this._queryEndTime=queryEndTime;this._extendedInfo=extendedInfo;this._pageSizeCode=pageSizeCode;this._keyTypeCode=keyTypeCode;this._flag=flag}formatVersion(){return this._formatVersion}compressMethod(){return this._compressMethod}encryptMethod(){return this._encryptMethod}blocksCount(){return this._blocksCount}storageStartTime(){return this._storageStartTime}storageEndTime(){return this._storageEndTime}queryStartTime(){return this._queryStartTime}queryEndTime(){return this._queryEndTime}extendedInfo(){return this._extendedInfo}pageSize(){var pageSizeCode=this._pageSizeCode&15;switch(pageSizeCode){case 1:return 32768;case 2:return 16384;case 3:return 8192;case 4:return 131072;default:return 65536}}storageIdLength(){var storageIdLengthCode=(this._pageSizeCode&240)>>4;var pageSizeCode=this._pageSizeCode&15;if(pageSizeCode!=1){return 8}switch(storageIdLengthCode){case 1:return 6;default:return 5}}seriesTimestampLength(){var tsLengthCode=this._keyTypeCode&15;switch(tsLengthCode){case 1:return(this._keyTypeCode>>4&15)==0&&this._flag==0?43:41;default:return 41}}}class VDataBucket{constructor(){this.startTime=0;this.endTime=0;this.living=0;this.notime=0;this.cycle=0;this.crc=0;this.seriesBuckets=[]}get[Symbol.toStringTag](){return"{cycle="+String(this.cycle)+", start="+String(this.startTime)+", end="+String(this.endTime)+", living="+String(this.living)+", notime="+String(this.notime)+"}"}getStartTime(){return this.startTime}setStartTime(time){let t=String(time);if(t.length>13){this.startTime=Math.floor(time/Math.round(Math.pow(10,t.length-13)))}else{this.startTime=time}}getEndTime(){return this.endTime}setEndTime(time){let t=String(time);if(t.length>13){this.endTime=Math.floor(time/Math.round(Math.pow(10,t.length-13)))}else{this.endTime=time}}getCycle(){return this.cycle}setCycle(cycle){this.cycle=cycle}isLiving(){return this.living}setLiving(living){this.living=living}getCrc(){return this.crc}setCrc(crc){this.crc=crc}setNotime(notime){this.notime=notime}getSeriesBuckets(){return this.seriesBuckets}addSeriesBucket(seriesBucket){this.seriesBuckets.push(seriesBucket)}intersects(b){let st=b.startTime;let et=b.endTime;if(this.startTime==0||st==0){return false}if(this.endTime==0||et==0){return this.startTime==st}return this.startTime>=st&&this.startTime<=et||this.endTime>=st&&this.endTime<=et||st>=this.startTime&&st<=this.endTime||et>=this.startTime&&et<=this.endTime}merge(b){if(b.seriesBuckets.length>0){let sset=new Set;for(let i=0;i<this.seriesBuckets.length;i++){sset.add(this.seriesBuckets[i].name)}for(let i=0;i<b.seriesBuckets.length;i++){if(!sset.has(b.seriesBuckets[i].name)){this.seriesBuckets.push(b.seriesBuckets[i])}}}return this}}class VDataFormulaNone{constructor(name){this._name=name}name(){return this._name}apply(val){return val}}class VDataFormulaBlob{constructor(name){this._name=name;this._signalDecoder=undefined}name(){return this._name}setSignalDeocder(signalDecoder){this._signalDecoder=signalDecoder}apply(val){if(this._signalDecoder){return this._signalDecoder.decode(val)}else{return val}}}class VDataSignalDecoder{decode(data){return data}getSubNames(){return""}getSubValues(object){return object}}class VDataFormulaLinear{constructor(name,factor,offset){this._name=name;this._factor=factor;this._offset=offset}name(){return this._name}apply(val){return this._factor*val+this._offset}}class VDataFormulaPolynomial{constructor(name,p0,p1,p2,p3,p4,p5){this._name=name;this._p0=p0;this._p1=p1;this._p2=p2;this._p3=p3;this._p4=p4;this._p5=p5}name(){return this._name}apply(val){let numer=this._p1-this._p3*(val-this._p4-this._p5);let denom=this._p2*(val-this._p4-this._p5)-this._p0;let result=numer/denom;return Number.isFinite(result)?result:NaN}}class VDataFormulaExponential{constructor(name,p0,p1,p2,p3,p4,p5,p6){this._name=name;this._p0=p0;this._p1=p1;this._p2=p2;this._p3=p3;this._p4=p4;this._p5=p5;this._p6=p6;this._p3zero=this._p3==0;this._p0zero=this._p0==0;if(this._p3zero){if(this._p0zero){throw"FORMAT_VDATA_FORMULA_EXPONENTIAL_P3_P0_BOTH_ZERO"}if(this._p1==0){throw"FORMAT_VDATA_FORMULA_EXPONENTIAL_P3_P1_BOTH_ZERO"}}if(this._p0zero&&this._p4==0){throw"FORMAT_VDATA_FORMULA_EXPONENTIAL_P0_P4_BOTH_ZERO"}}name(){return this._name}apply(val){if(this._p3zero){let result=Math.log(((val-this._p6)*this._p5-this._p2)/this._p0)/this._p1;return Number.isFinite(result)?result:NaN}if(this._p0zero){let denom=val-this._p6;let result=this._p2/denom;if(!Number.isFinite(result)){return NaN}result=Math.log((result-this._p5)/this._p3)/this._p4;return Number.isFinite(result)?result:NaN}return NaN}}class VDataFormulaLogarithmic{constructor(name,p0,p1,p2,p3,p4,p5,p6){this._name=name;this._p0=p0;this._p1=p1;this._p2=p2;this._p3=p3;this._p4=p4;this._p5=p5;this._p6=p6;this._p3zero=this._p3==0;this._p0zero=this._p0==0;if(this._p3zero){if(this._p0zero){throw"FORMAT_VDATA_FORMULA_EXPONENTIAL_P3_P0_BOTH_ZERO"}if(this._p1==0){throw"FORMAT_VDATA_FORMULA_EXPONENTIAL_P3_P1_BOTH_ZERO"}}if(this._p0zero&&this._p4==0){throw"FORMAT_VDATA_FORMULA_EXPONENTIAL_P0_P4_BOTH_ZERO"}}name(){return this._name}apply(val){if(this._p3zero){let result=Math.exp(((val-this._p6)*this._p5-this._p2)/this._p0)/this._p1;return Number.isFinite(result)?result:NaN}if(this._p0zero){let denom=val-this._p6;let result=this._p2/denom;if(!Number.isFinite(result)){return NaN}result=Math.exp((result-this._p5)/this._p3)/this._p4;return Number.isFinite(result)?result:NaN}return NaN}}class VDataFormulaRational{constructor(name,p0,p1,p2,p3,p4,p5){this._name=name;this._p0=p0;this._p1=p1;this._p2=p2;this._p3=p3;this._p4=p4;this._p5=p5}name(){return this._name}apply(val){let numer=val*val*this._p0+val*this._p1+this._p2;let denom=val*val*this._p3+val*this._p4+this._p5;let result=numer/denom;return Number.isFinite(result)?result:NaN}}class VDataFormulaDecode{constructor(name,_list){this._name=name;if(_list==null||Array.isArray(_list)==false||_list.length==0){throw"FORMAT_VDATA_FORMULA_DECODE_LIST_EMPTY"}if(_list.length%2!=0){throw"FORMAT_VDATA_FORMULA_DECODE_LIST_ODD_SIZE"}this._list=_list;this._lsize=Math.floor(this._list.length/2)}name(){return this._name}apply(val){let x=this._list[0];let y=this._list[1];let compare=x-val;if(compare>=0){return y}for(let i=0;i<this._lsize;i++){compare=this._list[2*i]-val;if(compare<0){x=this._list[2*i];y=this._list[2*i+1]}else if(compare==0){return this._list[2*i+1]}else{if(this._list[2*i]-val-(val-x)>=0){return y}else{return this._list[2*i+1]}}}return this._list[2*this._lsize-1]}}class VDataFormulaInterpolate{constructor(name,_list){this._name=name;if(_list==null||Array.isArray(_list)==false||_list.length==0){throw"FORMAT_VDATA_FORMULA_INTERPOLATE_LIST_EMPTY"}if(_list.length%2!=0){throw"FORMAT_VDATA_FORMULA_INTERPOLATE_LIST_ODD_SIZE"}this._list=_list;this._lsize=Math.floor(this._list.length/2)}name(){return this._name}apply(val){let x1=this._list[0];let y1=this._list[1];let x2=0;let y2=0;let a=0;let compare=x1-val;if(compare>0){x2=this._list[2];y2=this._list[3];a=(y2-y1)/(x2-x1);if(!Number.isFinite(a)){return NaN}return y1+a*(val-x1)}else if(compare==0){return y1}for(let i=0;i<this._lsize-1;i++){x1=this._list[2*i];y1=this._list[2*i+1];compare=x1-val;if(compare>0){x2=this._list[2*i+2];y2=this._list[2*i+3];a=(y2-y1)/(x2-x1);if(!Number.isFinite(a)){return NaN}return y1+a*(val-x1)}else if(compare==0){return y1}}x2=this._list[2*this._lsize-2];y2=this._list[2*this._lsize-1];compare=x2-val;if(compare==0){return y2}else{a=(y2-y1)/(x2-x1);if(!Number.isFinite(a)){return NaN}return y1+a*(val-x1)}}}class VDataFormulaArray{constructor(name,formulas){this._name=name;this._formulas=formulas}name(){return this._name}apply(val){let vals=[];if(!isNaN(val)){vals.push(val);return vals}for(let i=0,s=this._formulas.length;i<s;++i){vals.push(this._formulas[i].apply(val))}return vals}}class VDataFormulaNamedArray extends VDataFormulaArray{constructor(name,formulas){super(name,formulas)}}class VDataFormulaStruct{constructor(name,formulas){this._name=name;this._formulas=formulas}name(){return this._name}apply(val){let vals=new Map;for(let i=0,s=this._formulas.length;i<s;++i){vals.set(this._formulas[i]._name,this._formulas[i].apply(val))}return vals}}class VDataFormulaFactory{build(desc,insensitiveCase=false){if(desc.length==0){throw"FORMAT_VDATA_KEY_DESC_EMPTY"}let idx=desc.indexOf("|");if(idx==0){throw"FORMAT_VDATA_KEY_DESC_INVALID: "+desc}else if(idx<0){let name=insensitiveCase?desc.trim().toLowerCase():desc.trim();return new VDataFormulaNone(name)}let name=desc.substring(0,idx).trim();if(name.length==0){throw"FORMAT_VDATA_KEY_DESC_INVALID: "+desc}if(insensitiveCase){name=name.toLowerCase()}let formula=desc.substring(idx+1).trim();if(formula.length==0){return new VDataFormulaNone(name)}let code=formula;idx=formula.indexOf(":");if(idx==0){throw"FORMAT_VDATA_KEY_DESC_INVALID: "+desc}else if(idx>0){code=formula.substring(0,idx)}if("8"==code){if(idx<0){return this.buildArrayFormula(name,"",insensitiveCase)}else if(idx>0){formula=formula.substring(idx+1).trim();if(formula.length==0){return this.buildArrayFormula(name,"",insensitiveCase)}}if(formula[0]!="["||formula[formula.length-1]!="]"){throw"FORMAT_VDATA_KEY_DESC_INVALID_ARRAY: "+desc}formula=formula.substring(1,formula.length-1).trim();if(formula.length==0){throw"FORMAT_VDATA_KEY_DESC_INVALID_ARRAY: "+desc}return this.buildArrayFormula(name,formula,insensitiveCase)}if("9"==code){if(idx<0){throw"FORMAT_VDATA_KEY_DESC_INVALID_STRUCT: "+desc}else if(idx>0){formula=formula.substring(idx+1).trim();if(formula.length==0){throw"FORMAT_VDATA_KEY_DESC_INVALID_STRUCT: "+desc}}if(formula[0]!="{"||formula[formula.length-1]!="}"){throw"FORMAT_VDATA_KEY_DESC_INVALID_STRUCT: "+desc}formula=formula.substring(1,formula.length-1).trim();if(formula.length==0){throw"FORMAT_VDATA_KEY_DESC_INVALID_STRUCT: "+desc}return this.buildStructFormula(name,formula,insensitiveCase)}return this.buildSimpleFormula(name,formula)}buildArrayFormula(name,formula,insensitiveCase=false){let descs=formula.split(",");let formulas=[];let namedArray=false;let names=new Set;for(let i=0,s=descs.length;i<s;++i){let desc=descs[i].trim();if(desc.length==0){if(namedArray&&i!=0){throw"FORMAT_VDATA_KEY_DESC_ARRAY_MIXED_NAMES_NOT_ALLOWED: "+name}formulas.push(new VDataFormulaNone(name));continue}let idx=desc.indexOf("|");if(idx<0){if(desc.indexOf(":")<0&&"0"!=desc){if(!namedArray&&i!=0){throw"FORMAT_VDATA_KEY_DESC_ARRAY_MIXED_NAMES_NOT_ALLOWED: "+name}if(insensitiveCase){desc=desc.toLowerCase()}if(names.has(desc)){throw"FORMAT_VDATA_KEY_DESC_ARRAY_DUPLICATE_NAMES_NOT_ALLOWED: "+name+" - "+desc}formulas.push(new VDataFormulaNone(desc));names.add(desc);namedArray=true}else{if(namedArray&&i!=0){throw"FORMAT_VDATA_KEY_DESC_ARRAY_MIXED_NAMES_NOT_ALLOWED: "+name+" - "+desc}formulas.push(this.buildSimpleFormula(name,desc))}continue}if(idx==0){if(namedArray&&i!=0){throw"FORMAT_VDATA_KEY_DESC_ARRAY_MIXED_NAMES_NOT_ALLOWED: "+name}desc=desc.substring(1).trim();if(desc.length()==0){formulas.push(new VDataFormulaNone(name))}else{formulas.push(this.buildSimpleFormula(name,desc))}continue}let itemname=desc.substring(0,idx).trim();if(itemname.length==0){throw"FORMAT_VDATA_KEY_DESC_INVALID_ARRAY_ITEM: "+name+" - "+desc}if(insensitiveCase){itemname=itemname.toLowerCase()}let itemformula=desc.substring(idx+1).trim();if(names.has(itemname)){throw"FORMAT_VDATA_KEY_DESC_ARRAY_DUPLICATE_NAMES_NOT_ALLOWED: "+name+" - "+itemname}else{names.add(itemname);namedArray=true}if(itemformula.length==0){formulas.push(new VDataFormulaNone(itemname))}else{formulas.push(this.buildSimpleFormula(itemname,itemformula))}}if(namedArray){return new VDataFormulaNamedArray(name,formulas)}else{return new VDataFormulaArray(name,formulas)}}buildStructFormula(name,formula,insensitiveCase=false){let descs=formula.split(",");let formulas=[];for(let i=0,s=descs.length;i<s;++i){let desc=descs[i].trim();let idx=desc.indexOf("|");if(idx==0){throw"FORMAT_VDATA_KEY_DESC_INVALID_STRUCT_ITEM: "+name}else if(idx<0){let itemname=insensitiveCase?desc.trim().toLowerCase():desc.trim();formulas.push(new VDataFormulaNone(itemname));continue}let itemname=desc.substring(0,idx).trim();if(itemname.length==0){throw"FORMAT_VDATA_KEY_DESC_INVALID_STRUCT_ITEM: "+name}if(insensitiveCase){itemname=itemname.toLowerCase()}let itemformula=desc.substring(idx+1).trim();if(itemformula.length==0){formulas.push(new VDataFormulaNone(itemname))}else{formulas.push(this.buildSimpleFormula(itemname,itemformula))}}return new VDataFormulaStruct(name,formulas)}buildSimpleFormula(fname,formula){let fitems=formula.split(/[:]/);let formulaType=fitems[0].trim();let flen=fitems.length;if("0"==formulaType){if(flen==1){return new VDataFormulaNone(fname)}throw"FORMAT_VDATA_KEY_DESC_INVALID: "+fname+"|"+formula}if("1"==formulaType){if(flen==3){let factor=parseFloat(fitems[1].trim());let offset=parseFloat(fitems[2].trim());if(Number.isInteger(factor)&&Math.floor(factor)==1&&Number.isInteger(offset)&&Math.floor(offset)==0){return new VDataFormulaNone(fname)}else{return new VDataFormulaLinear(fname,factor,offset)}}throw"FORMAT_VDATA_KEY_DESC_INVALID: "+fname+"|"+formula}if("2"==formulaType){if(flen==7){let p0=parseFloat(fitems[1].trim());let p1=parseFloat(fitems[2].trim());let p2=parseFloat(fitems[3].trim());let p3=parseFloat(fitems[4].trim());let p4=parseFloat(fitems[5].trim());let p5=parseFloat(fitems[6].trim());return new VDataFormulaPolynomial(fname,p0,p1,p2,p3,p4,p5)}throw"FORMAT_VDATA_KEY_DESC_INVALID: "+fname+"|"+formula}if("3"==formulaType){if(flen==8){let p0=parseFloat(fitems[1].trim());let p1=parseFloat(fitems[2].trim());let p2=parseFloat(fitems[3].trim());let p3=parseFloat(fitems[4].trim());let p4=parseFloat(fitems[5].trim());let p5=parseFloat(fitems[6].trim());let p6=parseFloat(fitems[7].trim());return new VDataFormulaExponential(fname,p0,p1,p2,p3,p4,p5,p6)}throw"FORMAT_VDATA_KEY_DESC_INVALID: "+fname+"|"+formula}if("4"==formulaType){if(flen==8){let p0=parseFloat(fitems[1].trim());let p1=parseFloat(fitems[2].trim());let p2=parseFloat(fitems[3].trim());let p3=parseFloat(fitems[4].trim());let p4=parseFloat(fitems[5].trim());let p5=parseFloat(fitems[6].trim());let p6=parseFloat(fitems[7].trim());return new VDataFormulaLogarithmic(fname,p0,p1,p2,p3,p4,p5,p6)}throw"FORMAT_VDATA_KEY_DESC_INVALID: "+fname+"|"+formula}if("5"==formulaType){if(flen==7){let p0=parseFloat(fitems[1].trim());let p1=parseFloat(fitems[2].trim());let p2=parseFloat(fitems[3].trim());let p3=parseFloat(fitems[4].trim());let p4=parseFloat(fitems[5].trim());let p5=parseFloat(fitems[6].trim());return new VDataFormulaRational(fname,p0,p1,p2,p3,p4,p5)}throw"FORMAT_VDATA_KEY_DESC_INVALID: "+fname+"|"+formula}if("6"==formulaType){if(flen>=3){let plist=[];for(let i=1;i<flen;i++){plist.push(parseFloat(fitems[i].trim()))}return new VDataFormulaDecode(fname,plist)}throw"FORMAT_VDATA_KEY_DESC_INVALID: "+fname+"|"+formula}if("7"==formulaType){if(flen>=5){let plist=[];for(let i=1;i<flen;i++){plist.push(parseFloat(fitems[i].trim()))}return new VDataFormulaInterpolate(fname,plist)}throw"FORMAT_VDATA_KEY_DESC_INVALID: "+fname+"|"+formula}if("11"==formulaType){return new VDataFormulaBlob(fname)}throw"FORMAT_VDATA_KEY_DESC_INVALID: "+fname+"|"+formula}}class VDataSeriesMeta{constructor(formula,storageid_high,storageid_low,pageSize,storageIdLength){this._name=formula.name();this._formula=formula;const _high=storageid_high;const _low=storageid_low;if(pageSize!=32768){this._pageIndex=_high>>16;this._pageOffset=_high&65535;this._dataLength=(_low>>31&1)!=0?(_low>>16&32767)+32768:_low>>16&32767;this._itemCount=(_low>>15&1)!=0?(_low&32767)+32768:_low&32767}else if(storageIdLength==5){this._pageIndex=_high>>3&31;this._pageOffset=(_low>>20&4095)+((_high&7)<<12);this._dataLength=_low>>9&2047;this._itemCount=_low&511}else{this._pageIndex=_high>>8&255;this._pageOffset=(_low>>25&127)+((_high&255)<<7);this._dataLength=_low>>10&32767;this._itemCount=_low&1023}}get[Symbol.toStringTag](){return"{name:"+String(this._name)+", items:"+String(this._itemCount)+", length:"+String(this._dataLength)+"}"}name(){return this._name}formula(){return this._formula}pageIndex(){return this._pageIndex}pageOffset(){return this._pageOffset}dataLength(){return this._dataLength}itemCount(){return this._itemCount}setItemCount(cnt){this._itemCount=cnt}}class BitTracker{constructor(){this._numBits=0}getNumBits(){return this._numBits}setNumBits(bits){this._numBits=bits}getByteIndex(){return this._numBits>>3}getNumBytes(){return(this._numBits&7)!=0?(this._numBits>>3)+1:this._numBits>>3}incrementBit(){this._numBits++}incrementBits(bits){this._numBits=this._numBits+bits}}const VDataConstants={PAGE_LENGTH:65536,BIT_MASKS:[-128,64,32,16,8,4,2,1],FIRST_BYTE_BIT_MASKS:[255,127,63,31,15,7,3,1],BIT_POWER2:[1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912,1073741824,2147483648],BIGINT_POWER2:[1n,2n,4n,8n,16n,32n,64n,128n,256n],TIMESTAMP_INIT_DELTA:60,TIMESTAMP_VALUE_ENCODING:[7,9,12,32],TIMESTAMP_FIRST_VALUE_BITS:41,MICROSECOND_BITS:10,XOR_LEADING_ZERO_LENGTH_BITS:5,XOR_BLOCK_SIZE_LENGTH_BITS:6,XOR_BLOCK_SIZE_ADJUSTMENTS:1,ENCODE_LEADING_BITS:[0,8,12,16,18,20,22,24],POLL_QUEUE_MIN_SIZE:10};const DType={Float64:0,String:1,Boolean:2,Int8:3,UInt8:4,Int16:5,Int32:6,Int64:7,Array:8,Struct:9,Float32:10,Blob:11,Uint64:12};const DEncoder={NONE:0,XOR:1,GZIP:2,DELTA:3,CHIMP:4,ERASURE:5,PLAIN:6};const DExpand={NONE:0,FLAT:1,FULL:2};class VDataUtils{static getColumnExpandMode(mode){if(mode!=null){let m=mode;if(typeof m=="string"){m=m.toLowerCase().trim();if(m=="none"){return DExpand.NONE}else if(m=="flat"){return DExpand.FLAT}else if(m=="full"){return DExpand.FULL}}m=parseInt(mode);if(Number.isInteger(m)){if(m==DExpand.NONE){return DExpand.NONE}else if(m==DExpand.FULL){return DExpand.FULL}}}return DExpand.FLAT}static getSignalQueueMode(mode){if(mode!=null){let m=String(mode).trim().toLowerCase();if(m=="first"){return"first"}if(m=="all"){return"all"}}return"last"}static isQualifiedExpandName(mode){return VDataUtils.getColumnExpandMode(mode)==DExpand.FULL}static isAllSignalQueueMode(mode){return"all"==VDataUtils.getSignalQueueMode(mode)}static insertion_order_set_list(names){if(names==null||names.length==0){return[]}let st=new Set(names);let ns=[];for(let nm of names){if(st.has(nm)){ns.push(nm);st.delete(nm)}}return ns}}class VDataDecodeUtils{static sortAddDecoder(decoders,decoder){let size=decoders.length;if(size==0){console.log("Add decoder "+String(decoder));decoders.push(decoder);return}let decoderStartTime=decoder._meta.storageStartTime();for(let i=size-1;i>=0;--i){let dc=decoders[i];let st=dc._meta.storageStartTime();if(st<=decoderStartTime){console.log("Add decoder "+String(decoder));decoders.splice(i+1,0,decoder);return}}console.log("Add decoder "+String(decoder));decoders.splice(0,0,decoder)}static readValueFromBitOne(page,bitpos){return(page[bitpos>>3]&VDataConstants.BIT_MASKS[bitpos&7])==0?0:1}static readValueFromBitString(page,bitsToRead,bitpos){let bitsEnd=bitpos+bitsToRead-1;let bitMaskFirstByte=bitpos&7;let bitsLastByte=(bitsEnd&7)+1;let byteFirst=bitpos>>3;let byteLast=bitsEnd>>3;let value=page[byteFirst]&255&VDataConstants.FIRST_BYTE_BIT_MASKS[bitMaskFirstByte];if(byteFirst==byteLast){value=value>>8-bitsLastByte}else{let bytepos=byteFirst+1;while(bytepos<byteLast){value=value*256+(page[bytepos++]&255)}value=value*VDataConstants.BIT_POWER2[bitsLastByte]+((page[byteLast]&255)>>8-bitsLastByte)}return value}static readBigIntFromBitString(page,bitsToRead,bitpos){if(bitsToRead<=32){return BigInt(this.readValueFromBitString(page,bitsToRead,bitpos))}let bitsEnd=bitpos+bitsToRead-1;let bitMaskFirstByte=bitpos&7;let bitsLastByte=(bitsEnd&7)+1;let byteFirst=bitpos>>3;let byteLast=bitsEnd>>3;let fbyte=page[byteFirst]&255&VDataConstants.FIRST_BYTE_BIT_MASKS[bitMaskFirstByte];let value;if(byteFirst==byteLast){value=BigInt(fbyte>>8-bitsLastByte)}else{value=BigInt(fbyte);let bytepos=byteFirst+1;while(bytepos<byteLast){value=value*256n+BigInt(page[bytepos++]&255)}value=value*VDataConstants.BIGINT_POWER2[bitsLastByte]+BigInt((page[byteLast]&255)>>8-bitsLastByte)}return value}static intBitsToFloat(bits){let sign=bits>>>31==0?1:-1;let e=bits>>>23&255;let m=e==0?(bits&8388607)<<1:bits&8388607|8388608;let f=sign*m*Math.pow(2,e-150);return f}static longBitsToDouble(bits){let _buf=new ArrayBuffer(8);let _view=new DataView(_buf);_view.setBigInt64(0,bits,false);return new DataView(_buf).getFloat64(0)}static longBitsToUint64(bits){let _buf=new ArrayBuffer(8);let _view=new DataView(_buf);_view.setBigUint64(0,bits,false);return new DataView(_buf).getBigInt64(0)}}class VDataFloat32NoneDecode{constructor(_page,_formula,_bitTracker){this.page=_page;this.bitTracker=_bitTracker;this.formula=_formula;this.hasFormula=_formula!=null&&!(_formula instanceof VDataFormulaNone);this.bitValue=0}first(){this.next()}next(){let bitpos=this.bitTracker.getNumBits();this.bitValue=VDataDecodeUtils.readValueFromBitString(this.page,32,bitpos);this.bitTracker.setNumBits(bitpos+32)}get(){return this.hasFormula?this.formula.apply(VDataDecodeUtils.intBitsToFloat(this.bitValue)):VDataDecodeUtils.intBitsToFloat(this.bitValue)}raw(){return VDataDecodeUtils.intBitsToFloat(this.bitValue)}bits(){return this.bitValue}}class VDataFloat64NoneDecode{constructor(_page,_formula,_bitTracker){this.page=_page;this.bitTracker=_bitTracker;this.formula=_formula;this.hasFormula=_formula!=null&&!(_formula instanceof VDataFormulaNone);this.bitValue=0n}first(){this.next()}next(){let bitpos=this.bitTracker.getNumBits();this.bitValue=VDataDecodeUtils.readBigIntFromBitString(this.page,64,bitpos);this.bitTracker.setNumBits(bitpos+64)}get(){return this.hasFormula?this.formula.apply(VDataDecodeUtils.longBitsToDouble(this.bitValue)):VDataDecodeUtils.longBitsToDouble(this.bitValue)}raw(){return VDataDecodeUtils.longBitsToDouble(this.bitValue)}bits(){return this.bitValue}}class VDataFloat64ChimpDecode{constructor(_page,_formula,_bitTracker){this.page=_page;this.bitTracker=_bitTracker;this.formula=_formula;this.hasFormula=_formula!=null&&!(_formula instanceof VDataFormulaNone);this.bitValue=0n;this.leadingZeros=0;this.trailingZeros=0;this.signalValue=0;this.updatedBits=false}first(){this.next()}next(){let bitpos=this.bitTracker.getNumBits();let xorValue=0n;if(VDataDecodeUtils.readValueFromBitOne(this.page,bitpos++)==0){if(VDataDecodeUtils.readValueFromBitOne(this.page,bitpos++)==0){this.bitTracker.setNumBits(bitpos);return}this.leadingZeros=VDataConstants.ENCODE_LEADING_BITS[VDataDecodeUtils.readValueFromBitString(this.page,3,bitpos)];bitpos=bitpos+3;let significantBits=VDataDecodeUtils.readValueFromBitString(this.page,6,bitpos);bitpos=bitpos+6;if(significantBits==0){significantBits=64}this.trailingZeros=64-significantBits-this.leadingZeros;xorValue=VDataDecodeUtils.readBigIntFromBitString(this.page,significantBits,bitpos);xorValue=xorValue*BigInt(Math.pow(2,this.trailingZeros));bitpos+=significantBits}else{if(VDataDecodeUtils.readValueFromBitOne(this.page,bitpos++)==0){let bits=64-this.leadingZeros;xorValue=VDataDecodeUtils.readBigIntFromBitString(this.page,bits,bitpos);bitpos=bitpos+bits}else{this.leadingZeros=VDataConstants.ENCODE_LEADING_BITS[VDataDecodeUtils.readValueFromBitString(this.page,3,bitpos)];bitpos=bitpos+3;let bits=64-this.leadingZeros;xorValue=VDataDecodeUtils.readBigIntFromBitString(this.page,bits,bitpos);bitpos=bitpos+bits}}this.bitValue=xorValue^this.bitValue;this.updatedBits=true;this.bitTracker.setNumBits(bitpos)}get(){return this.hasFormula?this.formula.apply(this.raw()):this.raw()}raw(){if(this.updatedBits){this.signalValue=VDataDecodeUtils.longBitsToDouble(this.bitValue);this.updatedBits=false}return this.signalValue}bits(){return this.bitValue}}class VDataFloat64ErasureDecode{static POWER_P10=Object.freeze([1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10]);static POWER_N10=Object.freeze([1,.1,.01,.001,1e-4,1e-5,1e-6,1e-7,1e-8,1e-9,1e-10]);static POWER_P20=Object.freeze([1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13,1e14,1e15,1e16,1e17,1e18,1e19,1e20]);static POWER_N20=Object.freeze([1,.1,.01,.001,1e-4,1e-5,1e-6,1e-7,1e-8,1e-9,1e-10,1e-11,1e-12,1e-13,1e-14,1e-15,1e-16,1e-17,1e-18,1e-19,1e-20]);constructor(_page,_formula,_bitTracker){this.page=_page;this.bitTracker=_bitTracker;this.formula=_formula;this.hasFormula=_formula!=null&&!(_formula instanceof VDataFormulaNone);this.bitValue=0n;this.signalValue=0;this.leadingZeros=0;this.trailingZeros=0;this.beta=Number.MAX_VALUE}first(){let bitpos=this.bitTracker.getNumBits()+2;this.trailingZeros=VDataDecodeUtils.readValueFromBitString(this.page,7,bitpos);bitpos=bitpos+7;if(this.trailingZeros<64){let bits=63-this.trailingZeros;let value=VDataDecodeUtils.readBigIntFromBitString(this.page,bits,bitpos);value=value*2n+1n;this.bitValue=value*BigInt(Math.pow(2,this.trailingZeros));bitpos=bitpos+bits}this.bitTracker.setNumBits(bitpos)}next(){let bitpos=this.bitTracker.getNumBits();if(VDataDecodeUtils.readValueFromBitOne(this.page,bitpos++)==0){this.bitTracker.setNumBits(bitpos);this.decodeToPower()}else if(VDataDecodeUtils.readValueFromBitOne(this.page,bitpos++)==0){this.bitTracker.setNumBits(bitpos);this.decodeBase()}else{this.beta=VDataDecodeUtils.readValueFromBitString(this.page,4,bitpos);this.bitTracker.setNumBits(bitpos+4);this.decodeToPower()}}decodeBase(){let bitpos=this.bitTracker.getNumBits();let bits=VDataDecodeUtils.readValueFromBitString(this.page,2,bitpos);bitpos=bitpos+2;if(bits!=1){let xorValue=0n;if(bits==0){let centerBits=64-this.leadingZeros-this.trailingZeros;xorValue=VDataDecodeUtils.readBigIntFromBitString(this.page,centerBits,bitpos);xorValue=xorValue*BigInt(Math.pow(2,this.trailingZeros));bitpos=bitpos+centerBits}else if(bits==2){let leadCenter=VDataDecodeUtils.readValueFromBitString(this.page,7,bitpos);bitpos=bitpos+7;this.leadingZeros=VDataConstants.ENCODE_LEADING_BITS[leadCenter>>>4];let centerBits=15&leadCenter;if(centerBits==0){centerBits=16}this.trailingZeros=64-this.leadingZeros-centerBits;xorValue=VDataDecodeUtils.readBigIntFromBitString(this.page,centerBits-1,bitpos);xorValue=xorValue*2n+1n;xorValue=xorValue*BigInt(Math.pow(2,this.trailingZeros));bitpos=bitpos+centerBits-1}else if(bits==3){let leadCenter=VDataDecodeUtils.readValueFromBitString(this.page,9,bitpos);bitpos=bitpos+9;this.leadingZeros=VDataConstants.ENCODE_LEADING_BITS[leadCenter>>>6];let centerBits=63&leadCenter;if(centerBits==0){centerBits=64}this.trailingZeros=64-this.leadingZeros-centerBits;xorValue=VDataDecodeUtils.readBigIntFromBitString(this.page,centerBits-1,bitpos);xorValue=xorValue*2n+1n;xorValue=xorValue*BigInt(Math.pow(2,this.trailingZeros));bitpos=bitpos+centerBits-1}this.bitValue=xorValue^this.bitValue}this.bitTracker.setNumBits(bitpos)}decodeToPower(){this.decodeBase();let base=VDataDecodeUtils.longBitsToDouble(this.bitValue);let power=this.getTensPower(Math.abs(base));let value=0;if(this.beta==0){value=this.toTenthPower(-power-1);if(base<0){value=-value}}else{let scale=this.beta-power-1;value=this.roundToDigits(base,scale)}this.signalValue=value}roundToDigits(value,digits=0){const multiplier=Math.pow(10,digits);return Math.round(value*multiplier)/multiplier}getTensPower(v){if(v>=1){for(let i=1,s=VDataFloat64ErasureDecode.POWER_P10.length;i<s;++i){if(v<VDataFloat64ErasureDecode.POWER_P10[i]){return i-1}}}else{for(let i=1,s=VDataFloat64ErasureDecode.POWER_N10.length;i<s;++i){if(v>=VDataFloat64ErasureDecode.POWER_N10[i]){return-i}}}return Math.floor(Math.log10(v))}toTenthPower(i){if(i>=VDataFloat64ErasureDecode.POWER_N20.length){return Math.pow(10,i)}else{return VDataFloat64ErasureDecode.POWER_N20[i]}}toTenPower(i){if(i>=VDataFloat64ErasureDecode.POWER_P20.length){return Math.round(Math.pow(10,i))}else{return VDataFloat64ErasureDecode.POWER_P20[i]}}get(){return this.hasFormula?this.formula.apply(this.signalValue):this.signalValue}raw(){return this.signalValue}bits(){return this.bitValue}}class VDataFloat64XorDecode{constructor(_page,_formula,_bitTracker){this.page=_page;this.bitTracker=_bitTracker;this.formula=_formula;this.hasFormula=_formula!=null&&!(_formula instanceof VDataFormulaNone);this.bitValue=0n;this.leadingZeros=0;this.trailingZeros=0;this.signalValue=0;this.updatedBits=false}first(){this.next()}next(){let bitpos=this.bitTracker.getNumBits();if((this.page[bitpos>>3]&VDataConstants.BIT_MASKS[bitpos++&7])!=0){let xorValue;if((this.page[bitpos>>3]&VDataConstants.BIT_MASKS[bitpos++&7])!=0){let bits=64-this.leadingZeros-this.trailingZeros;xorValue=VDataDecodeUtils.readBigIntFromBitString(this.page,bits,bitpos);xorValue=xorValue*BigInt(Math.pow(2,this.trailingZeros));bitpos=bitpos+bits}else{this.leadingZeros=VDataDecodeUtils.readValueFromBitString(this.page,VDataConstants.XOR_LEADING_ZERO_LENGTH_BITS,bitpos);bitpos=bitpos+VDataConstants.XOR_LEADING_ZERO_LENGTH_BITS;let blockSize=VDataDecodeUtils.readValueFromBitString(this.page,VDataConstants.XOR_BLOCK_SIZE_LENGTH_BITS,bitpos)+VDataConstants.XOR_BLOCK_SIZE_ADJUSTMENTS;bitpos=bitpos+VDataConstants.XOR_BLOCK_SIZE_LENGTH_BITS;this.trailingZeros=64-blockSize-this.leadingZeros;xorValue=VDataDecodeUtils.readBigIntFromBitString(this.page,blockSize,bitpos);xorValue=xorValue*BigInt(Math.pow(2,this.trailingZeros));bitpos=bitpos+blockSize}this.bitValue=xorValue^this.bitValue;this.updatedBits=true}this.bitTracker.setNumBits(bitpos)}get(){return this.hasFormula?this.formula.apply(this.raw()):this.raw()}raw(){if(this.updatedBits){this.signalValue=VDataDecodeUtils.longBitsToDouble(this.bitValue);this.updatedBits=false}return this.signalValue}bits(){return this.bitValue}}class VDataUint64XorDecode{constructor(_page,_formula,_bitTracker){this.page=_page;this.bitTracker=_bitTracker;this.formula=_formula;this.hasFormula=_formula!=null&&!(_formula instanceof VDataFormulaNone);this.bitValue=0n;this.leadingZeros=0;this.trailingZeros=0;this.updatedBits=false}first(){this.next()}next(){let bitpos=this.bitTracker.getNumBits();if(VDataDecodeUtils.readValueFromBitOne(this.page,bitpos++)!=0){let xorValue;if(VDataDecodeUtils.readValueFromBitOne(this.page,bitpos++)!=0){let bits=64-this.leadingZeros-this.trailingZeros;xorValue=VDataDecodeUtils.readBigIntFromBitString(this.page,bits,bitpos);xorValue=xorValue*BigInt(Math.pow(2,this.trailingZeros));bitpos=bitpos+bits}else{this.leadingZeros=VDataDecodeUtils.readValueFromBitString(this.page,VDataConstants.XOR_LEADING_ZERO_LENGTH_BITS,bitpos);bitpos=bitpos+VDataConstants.XOR_LEADING_ZERO_LENGTH_BITS;let blockSize=VDataDecodeUtils.readValueFromBitString(this.page,VDataConstants.XOR_BLOCK_SIZE_LENGTH_BITS,bitpos)+VDataConstants.XOR_BLOCK_SIZE_ADJUSTMENTS;bitpos=bitpos+VDataConstants.XOR_BLOCK_SIZE_LENGTH_BITS;this.trailingZeros=64-blockSize-this.leadingZeros;xorValue=VDataDecodeUtils.readBigIntFromBitString(this.page,blockSize,bitpos);bitpos=bitpos+blockSize;xorValue=xorValue*BigInt(Math.pow(2,this.trailingZeros))}this.bitValue=xorValue^this.bitValue;this.updatedBits=true}this.bitTracker.setNumBits(bitpos)}get(){return this.hasFormula?this.formula.apply(this.raw()):this.raw()}raw(){if(this.updatedBits){this.updatedBits=false}return this.bitValue}bits(){return this.bitValue}}class VDataInt64XorDecode extends VDataUint64XorDecode{constructor(_page,_formula,_bitTracker){super(_page,_formula,_bitTracker);this.signalValue=0n}raw(){if(this.updatedBits){this.signalValue=VDataDecodeUtils.longBitsToUint64(this.bitValue);this.updatedBits=false}return this.signalValue}}class VDataUInt8NoneDecode{constructor(_page,_formula,_bitTracker){this.page=_page;this.bitTracker=_bitTracker;this.formula=_formula;this.hasFormula=_formula!=null&&!(_formula instanceof VDataFormulaNone);this.bitValue=0}first(){this.next()}next(){let bitpos=this.bitTracker.getNumBits();if((this.page[bitpos>>3]&VDataConstants.BIT_MASKS[bitpos++&7])!=0){this.bitValue=VDataDecodeUtils.readValueFromBitString(this.page,8,bitpos);bitpos=bitpos+8}this.bitTracker.setNumBits(bitpos)}get(){return this.hasFormula?this.formula.apply(this.bitValue):this.bitValue}raw(){return this.bitValue}bits(){return this.bitValue}}class VDataUInt8PlainDecode{constructor(_page,_formula,_bitTracker){this.page=_page;this.bitTracker=_bitTracker;this.formula=_formula;this.hasFormula=_formula!=null&&!(_formula instanceof VDataFormulaNone);this.bitValue=0}first(){this.next()}next(){let bitpos=this.bitTracker.getNumBits();this.bitValue=VDataDecodeUtils.readValueFromBitString(this.page,8,bitpos);this.bitTracker.setNumBits(bitpos+8)}get(){return this.hasFormula?this.formula.apply(this.bitValue):this.bitValue}raw(){return this.bitValue}bits(){return this.bitValue}}class VDataUInt8XorDecode{constructor(_page,_formula,_bitTracker){this.page=_page;this.bitTracker=_bitTracker;this.formula=_formula;this.hasFormula=_formula!=null&&!(_formula instanceof VDataFormulaNone);this.bitValue=0}first(){this.next()}next(){let bitpos=this.bitTracker.getNumBits();if(VDataDecodeUtils.readValueFromBitOne(this.page,bitpos++)!=0){let diff=0;if(VDataDecodeUtils.readValueFromBitOne(this.page,bitpos++)==0){diff=VDataDecodeUtils.readValueFromBitString(this.page,3,bitpos)+1;bitpos=bitpos+3}else{diff=VDataDecodeUtils.readValueFromBitString(this.page,8,bitpos);bitpos=bitpos+8}this.bitValue=diff^this.bitValue}this.bitTracker.setNumBits(bitpos)}get(){return this.hasFormula?this.formula.apply(this.bitValue):this.bitValue}raw(){return this.bitValue}bits(){return this.bitValue}}class VDataInt8NoneDecode{constructor(_page,_formula,_bitTracker){this.page=_page;this.bitTracker=_bitTracker;this.formula=_formula;this.hasFormula=_formula!=null&&!(_formula instanceof VDataFormulaNone);this.bitValue=0}first(){this.next()}next(){let bitpos=this.bitTracker.getNumBits();if(VDataDecodeUtils.readValueFromBitOne(this.page,bitpos++)!=0){let value=VDataDecodeUtils.readValueFromBitString(this.page,8,bitpos);if(value>127){value=value-256}this.bitValue=value;bitpos=bitpos+8}this.bitTracker.setNumBits(bitpos)}get(){return this.hasFormula?this.formula.apply(this.bitValue):this.bitValue}raw(){return this.bitValue}bits(){return this.bitValue}}class VDataInt32DeltaDecode{constructor(_page,_formula,_bitTracker){this.page=_page;this.bitTracker=_bitTracker;this.formula=_formula;this.hasFormula=_formula!=null&&!(_formula instanceof VDataFormulaNone);this.bitValue=0;this.deltaSigBits=0}first(){this.next()}next(){let bitpos=this.bitTracker.getNumBits();if(VDataDecodeUtils.readValueFromBitOne(this.page,bitpos++)!=0){if(VDataDecodeUtils.readValueFromBitOne(this.page,bitpos++)==0){this.deltaSigBits=VDataDecodeUtils.readValueFromBitString(this.page,VDataConstants.XOR_LEADING_ZERO_LENGTH_BITS,bitpos);bitpos=bitpos+VDataConstants.XOR_LEADING_ZERO_LENGTH_BITS}let neg=VDataDecodeUtils.readValueFromBitOne(this.page,bitpos++)!=0;let deltaValue=VDataDecodeUtils.readValueFromBitString(this.page,this.deltaSigBits,bitpos);bitpos=bitpos+this.deltaSigBits;let value=0;if(neg){value=this.bitValue-deltaValue;if(-value>2147483648){value=value+4294967296}}else{value=this.bitValue+deltaValue;if(value>2147483647){value=value-4294967296}}this.bitValue=value}this.bitTracker.setNumBits(bitpos)}get(){return this.hasFormula?this.formula.apply(this.bitValue):this.bitValue}raw(){return this.bitValue}bits(){return this.bitValue}}class VDataBlobDecode{constructor(_page,_formula,_bitTracker,_blobBuffer){this.blobBuffer=_blobBuffer;this.blobView=new DataView(new Uint8Array(_blobBuffer).buffer);this.formula=_formula;this.hasFormula=_formula!=null&&!(_formula instanceof VDataFormulaNone);this.offsetDecode=new VDataInt32DeltaDecode(_page,new VDataFormulaNone(_formula.name()+"_offset"),_bitTracker)}first(){this.next()}next(){this.offsetDecode.next()}get(){let offset=this.offsetDecode.get();let data=this.getBlobData(offset);return this.hasFormula?this.formula.apply(data):data}raw(){let offset=this.offsetDecode.get();let data=this.getBlobData(offset);return data}bits(){return this.raw()}getBlobData(offset){let header_length=this.blobView.getUint16(offset,true);let data_length=this.blobView.getInt32(offset+4,true);return this.blobBuffer.slice(offset+header_length,offset+header_length+data_length)}}class VDataBooleanNoneDecode{constructor(_page,_formula,_bitTracker){this.page=_page;this.bitTracker=_bitTracker;this.formula=_formula;this.hasFormula=_formula!=null&&!(_formula instanceof VDataFormulaNone);this.bitValue=0}first(){this.next()}next(){let bitpos=this.bitTracker.getNumBits();this.bitValue=VDataDecodeUtils.readValueFromBitOne(this.page,bitpos);this.bitTracker.setNumBits(bitpos+1)}get(){return this.hasFormula?this.formula.apply(this.bitValue):this.bitValue}raw(){return this.bitValue}bits(){return this.bitValue}}class VDataStringNoneDecode{constructor(_page,_formula,_bitTracker){this.page=_page;this.bitTracker=_bitTracker;this.formula=_formula;this.hasFormula=_formula!=null&&!(_formula instanceof VDataFormulaNone);this.bitValue=[]}first(){this.next()}next(){let bitpos=this.bitTracker.getNumBits();let bb=[];let b;do{b=VDataDecodeUtils.readValueFromBitString(this.page,8,bitpos);bitpos=bitpos+8;if(b==0){break}bb.push(b)}while(true);this.bitValue=bb;this.bitTracker.setNumBits(bitpos)}get(){return this.hasFormula?this.formula.apply(this.raw()):this.raw()}raw(){return this.bitValue.length==0?"":(new TextDecoder).decode(new Uint8Array(this.bitValue))}bits(){return this.bitValue}}class VDataNumberArrayDecode{constructor(_page,_dtype,_encoder,_length,_matchLength,_formula,_bitTracker){this.page=_page;this.decoders=[];this.bitTracker=_bitTracker;if(_formula instanceof VDataFormulaArray){let formulas=_formula._formulas;let flen=formulas.length;if(flen==0){let fn=new VDataFormulaNone(_formula._name);for(let i=0;i<_length;++i){this.decoders.push(this.buildDecoder(_page,_dtype,_encoder,fn,_bitTracker))}}else{if(_length!=flen&&_matchLength){throw"FORMAT_VDATA_ARRAY_LENGTH_MISMATCH: length="+String(_length)+", formula is "+_formula.name()}let s=_length<flen?_length:flen;for(let i=0;i<s;++i){this.decoders.push(this.buildDecoder(_page,_dtype,_encoder,formulas[i],_bitTracker))}for(let i=flen;i<_length;++i){this.decoders.push(this.buildDecoder(_page,_dtype,_encoder,formulas[flen-1],_bitTracker))}}}else{for(let i=0;i<_length;++i){this.decoders.push(this.buildDecoder(_page,_dtype,_encoder,_formula,_bitTracker))}}}buildDecoder(_page,_dtype,_encoder,_formula,_bitTracker){if(_dtype==DType.UInt8){if(_encoder==DEncoder.XOR){return new VDataUInt8XorDecode(_page,_formula,_bitTracker)}else if(_encoder==DEncoder.PLAIN){return new VDataUInt8PlainDecode(_page,_formula,_bitTracker)}else{return new VDataUInt8NoneDecode(_page,_formula,_bitTracker)}}if(_dtype==DType.Float64){if(_encoder==DEncoder.CHIMP){return new VDataFloat64ChimpDecode(_page,_formula,_bitTracker)}else if(_encoder==DEncoder.ERASURE){return new VDataFloat64ErasureDecode(_page,_formula,_bitTracker)}else if(_encoder==DEncoder.NONE){return new VDataFloat64NoneDecode(_page,_formula,_bitTracker)}else{return new VDataFloat64XorDecode(_page,_formula,_bitTracker)}}if(_dtype==DType.Int8){return new VDataInt8NoneDecode(_page,_formula,_bitTracker)}if(_dtype==DType.Int16||_dtype==DType.Int32){return new VDataInt32DeltaDecode(_page,_formula,_bitTracker)}if(_dtype==DType.Boolean){return new VDataBooleanNoneDecode(_page,_formula,_bitTracker)}if(_dtype==DType.Float32){return new VDataFloat32NoneDecode(_page,_formula,_bitTracker)}if(_dtype==DType.Uint64){return new VDataUint64XorDecode(_page,_formula,_bitTracker)}if(_dtype==DType.Int64){return new VDataInt64XorDecode(_page,_formula,_bitTracker)}throw"FORMAT_VDATA_DATA_TYPE_NOT_SUPPORTED: "+String(_dtype)}first(){this.next()}next(){for(let i=0,s=this.decoders.length;i<s;++i){this.decoders[i].next()}}get(){let vals=[];for(let i=0,s=this.decoders.length;i<s;++i){vals.push(this.decoders[i].get())}return vals}raw(){let vals=[];for(let i=0,s=this.decoders.length;i<s;++i){vals.push(this.decoders[i].raw())}return vals}bits(){let vals=[];for(let i=0,s=this.decoders.length;i<s;++i){vals.push(this.decoders[i].bits())}return vals}}class VDataStringArrayDecode{constructor(_page,_dtype,_encoder,_length,_matchLength,_formula,_bitTracker){this.page=_page;this.decoders=[];this.bitTracker=_bitTracker;if(_formula instanceof VDataFormulaArray){let formulas=_formula._formulas;let flen=formulas.length;if(flen==0){let fn=new VDataFormulaNone(_formula._name);for(let i=0;i<_length;++i){this.decoders.push(this.buildDecoder(_page,_dtype,_encoder,fn,_bitTracker))}}else{if(_length!=flen&&_matchLength){throw"FORMAT_VDATA_ARRAY_LENGTH_MISMATCH: length="+String(_length)+", formula is "+_formula.name()}let s=_length<flen?_length:flen;for(let i=0;i<s;++i){this.decoders.push(this.buildDecoder(_page,_dtype,_encoder,formulas[i],_bitTracker))}for(let i=flen;i<_length;++i){this.decoders.push(this.buildDecoder(_page,_dtype,_encoder,formulas[flen-1],_bitTracker))}}}else{for(let i=0;i<_length;++i){this.decoders.push(this.buildDecoder(_page,_dtype,_encoder,_formula,_bitTracker))}}}buildDecoder(_page,_dtype,_encoder,_formula,_bitTracker){return new VDataStringNoneDecode(_page,_formula,_bitTracker)}first(){this.next()}next(){for(let i=0,s=this.decoders.length;i<s;++i){this.decoders[i].next()}}get(){let vals=[];for(let i=0,s=this.decoders.length;i<s;++i){vals.push(this.decoders[i].get())}return vals}raw(){let vals=[];for(let i=0,s=this.decoders.length;i<s;++i){vals.push(this.decoders[i].raw())}return vals}bits(){let vals=[];for(let i=0,s=this.decoders.length;i<s;++i){vals.push(this.decoders[i].bits())}return vals}}class VDataNullDecode{constructor(_page,_bitTracker){this.page=_page;this.bitTracker=_bitTracker}isNull(){const bitpos=this.bitTracker.getNumBits();let check=VDataDecodeUtils.readValueFromBitOne(this.page,bitpos)==1;this.bitTracker.setNumBits(bitpos+1);return check}isNotNull(){const bitpos=this.bitTracker.getNumBits();let check=VDataDecodeUtils.readValueFromBitOne(this.page,bitpos)==0;this.bitTracker.setNumBits(bitpos+1);return check}}class VDataStructDecode{constructor(_page,_dtypes,_encoders,_length,_formula,_bitTracker){this.page=_page;this.decoders=[];this.notnulls=[];this.bitTracker=_bitTracker;this.nullDecoder=new VDataNullDecode(_page,_bitTracker);if(!(_formula instanceof VDataFormulaStruct)){throw"FORMAT_VDATA_STRUCT_FORMULA_MISMATCH: "+_formula._name}let formulas=_formula._formulas;let flen=formulas.length;if(_length!=flen){throw"FORMAT_VDATA_STRUCT_LENGTH_MISMATCH: "+_formula._name}this.subLength=flen;for(let i=0;i<flen;++i){this.decoders.push(this.buildDecoder(_page,_dtypes[i],_encoders[i],formulas[i],_bitTracker));this.notnulls.push(true)}}buildDecoder(_page,_dtype,_encoder,_formula,_bitTracker){if(_dtype==DType.UInt8){if(_encoder==DEncoder.XOR){return new VDataUInt8XorDecode(_page,_formula,_bitTracker)}else{return new VDataUInt8NoneDecode(_page,_formula,_bitTracker)}}if(_dtype==DType.Float64){if(_encoder==DEncoder.CHIMP){return new VDataFloat64ChimpDecode(_page,_formula,_bitTracker)}else if(_encoder==DEncoder.ERASURE){return new VDataFloat64ErasureDecode(_page,_formula,_bitTracker)}else if(_encoder==DEncoder.NONE){return new VDataFloat64NoneDecode(_page,_formula,_bitTracker)}else{return new VDataFloat64XorDecode(_page,_formula,_bitTracker)}}if(_dtype==DType.Int8){return new VDataInt8NoneDecode(_page,_formula,_bitTracker)}if(_dtype==DType.Int16||_dtype==DType.Int32){return new VDataInt32DeltaDecode(_page,_formula,_bitTracker)}if(_dtype==DType.Boolean){return new VDataBooleanNoneDecode(_page,_formula,_bitTracker)}if(_dtype==DType.String){return new VDataStringNoneDecode(_page,_formula,_bitTracker)}if(_dtype==DType.Float32){return new VDataFloat32NoneDecode(_page,_formula,_bitTracker)}if(_dtype==DType.Uint64){return new VDataUint64XorDecode(_page,_formula,_bitTracker)}if(_dtype==DType.Int64){return new VDataInt64XorDecode(_page,_formula,_bitTracker)}throw"FORMAT_VDATA_DATA_TYPE_NOT_SUPPORTED: "+String(_dtype)}first(){this.next()}next(){for(let i=0,s=this.decoders.length;i<s;++i){this.notnulls[i]=this.nullDecoder.isNotNull();if(this.notnulls[i]){this.decoders[i].next()}}}get(){let vals=[];for(let i=0,s=this.decoders.length;i<s;++i){vals.push(this.notnulls[i]?this.decoders[i].get():null)}return vals}raw(){let vals=[];for(let i=0,s=this.decoders.length;i<s;++i){vals.push(this.notnulls[i]?this.decoders[i].raw():null)}return vals}bits(){let vals=[];for(let i=0,s=this.decoders.length;i<s;++i){vals.push(this.notnulls[i]?this.decoders[i].bits():null)}return vals}}class VDataTimeDeltaDecode{constructor(_page,_bitTracker,_timestampLength){this.page=_page;this.bitTracker=_bitTracker;this.timestampLength=_timestampLength;this.millis=0;this.millisDelta=0}first(){let bitpos=this.bitTracker.getNumBits();this.millis=VDataDecodeUtils.readValueFromBitString(this.page,this.timestampLength,bitpos);this.millisDelta=VDataConstants.TIMESTAMP_INIT_DELTA;this.bitTracker.setNumBits(bitpos+this.timestampLength)}next(){let bitpos=this.bitTracker.getNumBits();if((this.page[bitpos>>3]&VDataConstants.BIT_MASKS[bitpos++&7])!=0){let ttype;if((this.page[bitpos>>3]&VDataConstants.BIT_MASKS[bitpos++&7])==0){ttype=1}else if((this.page[bitpos>>3]&VDataConstants.BIT_MASKS[bitpos++&7])==0){ttype=2}else if((this.page[bitpos>>3]&VDataConstants.BIT_MASKS[bitpos++&7])==0){ttype=3}else{ttype=4}let bitsForValue=VDataConstants.TIMESTAMP_VALUE_ENCODING[ttype-1];let decodedValue=VDataDecodeUtils.readValueFromBitString(this.page,bitsForValue,bitpos)-VDataConstants.BIT_POWER2[bitsForValue-1];this.millisDelta=this.millisDelta+(decodedValue>=0?decodedValue+1:decodedValue);bitpos=bitpos+bitsForValue}this.millis=this.millis+this.millisDelta;this.bitTracker.setNumBits(bitpos)}get(){return this.millis}raw(){return this.millis}timestamp(){return this.millis}}class VDataTimeMicrosDecode{constructor(_page,_bitTracker,_timestampLength){this.page=_page;this.bitTracker=_bitTracker;this.timestampLength=_timestampLength;this.millis=0;this.millisDelta=0;this.micros=0}first(){let bitpos=this.bitTracker.getNumBits();this.millis=VDataDecodeUtils.readValueFromBitString(this.page,this.timestampLength,bitpos);this.millisDelta=VDataConstants.TIMESTAMP_INIT_DELTA;bitpos=bitpos+this.timestampLength;if(VDataDecodeUtils.readValueFromBitOne(this.page,bitpos++)!=0){this.micros=VDataDecodeUtils.readValueFromBitString(this.page,VDataConstants.MICROSECOND_BITS,bitpos);bitpos=bitpos+VDataConstants.MICROSECOND_BITS}else{this.micros=0}this.bitTracker.setNumBits(bitpos)}next(){let bitpos=this.bitTracker.getNumBits();if((this.page[bitpos>>3]&VDataConstants.BIT_MASKS[bitpos++&7])!=0){let ttype;if((this.page[bitpos>>3]&VDataConstants.BIT_MASKS[bitpos++&7])==0){ttype=1}else if((this.page[bitpos>>3]&VDataConstants.BIT_MASKS[bitpos++&7])==0){ttype=2}else if((this.page[bitpos>>3]&VDataConstants.BIT_MASKS[bitpos++&7])==0){ttype=3}else{ttype=4}let bitsForValue=VDataConstants.TIMESTAMP_VALUE_ENCODING[ttype-1];let decodedValue=VDataDecodeUtils.readValueFromBitString(this.page,bitsForValue,bitpos)-VDataConstants.BIT_POWER2[bitsForValue-1];this.millisDelta=this.millisDelta+(decodedValue>=0?decodedValue+1:decodedValue);bitpos=bitpos+bitsForValue}this.millis=this.millis+this.millisDelta;if((this.page[bitpos>>3]&VDataConstants.BIT_MASKS[bitpos++&7])!=0){this.micros=VDataDecodeUtils.readValueFromBitString(this.page,VDataConstants.MICROSECOND_BITS,bitpos);bitpos=bitpos+VDataConstants.MICROSECOND_BITS}else{this.micros=0}this.bitTracker.setNumBits(bitpos)}get(){if(this.micros==0){return this.millis}return this.millis+this.micros/1e3}raw(){if(this.micros==0){return this.millis}return this.millis+this.micros/1e3}timestamp(){return this.millis}}class VDataObjectValueArray{constructor(time,colsize){this._time=time;this._colsize=colsize}getTime(){return this._time}}class VDataDenseArray extends VDataObjectValueArray{constructor(time,colsize){super(time,colsize);this._values=new Array(colsize);this._values[0]=this._time}isEmptyAt(position){return this._values[position]==null}add(position,value){this._values[position]=value}toObjects(){return this._values}}class VDataDenseArrayFirstMode extends VDataDenseArray{constructor(time,colsize){super(time,colsize)}add(position,value){if(this._values[position]==null){this._values[position]=value}}}class VDataSparseArray extends VDataObjectValueArray{constructor(time,colsize){super(time,colsize);this._posits=new Array;this._values=new Array;this._posits.push(0);this._values.push(time)}isEmptyAt(position){for(let i=1,s=this._posits.length;i<s;++i){if(this._posits[i]==position){return this._values[i]==null}}return true}add(position,value){this._posits.push(position);this._values.push(value)}toObjects(){let vals=new Array(this._colsize);for(let i=0,s=this._posits.length;i<s;++i){vals[this._posits[i]]=this._values[i]}return vals}}class VDataSparseArrayFirstMode extends VDataSparseArray{constructor(time,colsize){super(time,colsize)}toObjects(){let vals=new Array(this._colsize);for(let i=0,s=this._posits.length;i<s;++i){let pos=this._posits[i];if(vals[pos]==null){vals[pos]=this._values[i]}}return vals}}class VDataSparseArrayAllMode extends VDataSparseArray{constructor(time,colsize){super(time,colsize)}isEmptyAt(position){let low=1;let high=this._posits.length-1;let mid=Math.floor((low+high)/2);let pos=0;while(low<high){pos=this._posits[mid];if(position==pos){return false}else if(position<pos){high=mid-1}else{low=mid+1}mid=Math.floor((low+high)/2)}if(high==low&&position==this._posits[low]){return false}return true}add(position,value){if(position==0){return}let low=1;let high=this._posits.length-1;let mid=Math.floor((low+high)/2);let pos=0;while(low<high){pos=this._posits[mid];if(position==pos){this._values[mid]=value;return}else if(position<pos){high=mid-1}else{low=mid+1}mid=Math.floor((low+high)/2)}if(low==high){pos=this._posits[low];if(position==pos){this._values[low]=value}else if(position<pos){this._posits.splice(low,0,position);this._values.splice(low,0,value)}else{this._posits.splice(low+1,0,position);this._values.splice(low+1,0,value)}}else{this._posits.splice(low,0,position);this._values.splice(low,0,value)}}}class VDataSeriesDecodeBuilder{static build(_data){let _version=_data.getFormatVersion();if(_version<26){return new VDataSeriesDecodeNumber(_data,0,DType.Float64,DEncoder.XOR)}let _bt=_data.getPage();let btreader=new VDataByteReader(_bt);let firstbyte=btreader.read(1)[0];let _type=firstbyte>>4&15;let _offset=8;if(_type==DType.Array){let high_len=btreader.read(1)[0];let low_len=btreader.read(1)[0];let _length=(high_len&255)<<8|low_len&255;let sub=btreader.read(1)[0];let _subtype=sub>>4&15;let _encoder=sub&15;_offset=32;let element_exist_array=new Array(_length);if(_version>27){for(var i=0;i<_length;i++){element_exist_array[i]=true;var byte_index=i/8;var bit_index=7-i%8;element_exist_array[i]=(_data[4+byte_index]>>bit_index&1)==1;_offset=32+(_length<=16?2:Math.ceil(_length/8))*8}}else{for(var i=0;i<_length;i++){element_exist_array[i]=true}_offset=32}if(_data.getFormula()instanceof VDataFormulaNamedArray){return new VDataSeriesDecodeNamedArray(_data,_offset,_subtype,_encoder,_length)}else if(_subtype==DType.String){return new VDataSeriesDecodeStringArray(_data,_offset,_subtype,_encoder,_length)}else{return new VDataSeriesDecodeNumberArray(_data,_offset,_subtype,_encoder,_length,false)}}if(_type==DType.Struct){let high_len=btreader.read(1)[0];let low_len=btreader.read(1)[0];let _length=(high_len&255)<<8|low_len&255;let _subtypes=[];let _encoders=[];_offset=8+16+8*_length;for(let i=0;i<_length;++i){let sub=btreader.read(1)[0];_subtypes.push(sub>>4&15);_encoders.push(sub&15)}return new VDataSeriesDecodeStruct(_data,_offset,_subtypes,_encoders,_length)}let _encoder=firstbyte&15;if(_type==DType.String){return new VDataSeriesDecodeString(_data,_offset,_type,_encoder)}if(_type==DType.Blob){return new VDataSeriesDecodeBlob(_data,_offset,_type,_encoder)}return new VDataSeriesDecodeNumber(_data,_offset,_type,_encoder)}static builds(_datas){let decoders=[];for(const _data of _datas){decoders.push(VDataSeriesDecodeBuilder.build(_data))}return decoders}}class VDataSeriesBucket{constructor(){this.name=null;this.formatVersion=0;this.bucketCycle=0;this.sstime=0;this.setime=0;this.qstime=0;this.qetime=0;this.page=null;this.formula=null;this.itemCount=0;this.firstTime=null}getFormatVersion(){return this.formatVersion}setFormatVersion(version){this.formatVersion=version}getName(){return this.name}getFormula(){return this.formula}getItemCount(){return this.itemCount}setMeta(meta){this.name=meta.name();this.formula=meta.formula();this.itemCount=meta.itemCount()}getPage(){return this.page}setPage(page){this.page=page}getFirstTime(){return this.firstTime}setFirstTime(time){this.firstTime=time}getBucketCycle(){return this.bucketCycle}setBucketCycle(cycle){this.bucketCycle=cycle}getBucketStartTime(){return this.sstime}setBucketStartTime(time){this.sstime=time}getBucketEndTime(){return this.setime}setBucketEndTime(time){this.setime=time}getQueryStartTime(){return this.qstime}setQueryStartTime(qstime){this.qstime=qstime}getQueryEndTime(){return this.qetime}setQueryEndTime(qetime){this.qetime=qetime}setBlobData(data){this.blobData=data}getBlobData(){return this.blobData}setSeriesTimestampLength(length){this.timestampLenth=length}getSeriesTimestampLength(){return this.timestampLenth}}class VDataSeriesDecode{constructor(data,offset){this.name=data.getName();this.formula=data.getFormula();this.itemCount=data.getItemCount();this.page=data.getPage();this.bucketCycle=data.getBucketCycle();this.qstime=data.getQueryStartTime();this.qetime=data.getQueryEndTime();this.bitTracker=new BitTracker;this.bitTracker.setNumBits(offset);this.timeDecode=new VDataTimeDeltaDecode(this.page,this.bitTracker,data.getSeriesTimestampLength());this.readCount=0;this.emptied=true}getName(){return this.name}getFormula(){return this.formula}getItemCount(){return this.itemCount}getQueryStartTime(){return this.qstime}getQueryEndTime(){return this.qetime}time(){return this.timeDecode.get()}timestamp(){return this.timeDecode.timestamp()}isEmpty(){return this.emptied}getSubNames(){return null}}class VDataSeriesDecodeNumber extends VDataSeriesDecode{constructor(data,offset,dtype,encoder){super(data,offset);if(dtype==DType.UInt8){if(encoder==DEncoder.XOR){this.valueDecode=new VDataUInt8XorDecode(this.page,this.formula,this.bitTracker)}else{this.valueDecode=new VDataUInt8NoneDecode(this.page,this.formula,this.bitTracker)}}else if(dtype==DType.Float64){if(encoder==DEncoder.CHIMP){this.valueDecode=new VDataFloat64ChimpDecode(this.page,this.formula,this.bitTracker)}else if(encoder==DEncoder.ERASURE){this.valueDecode=new VDataFloat64ErasureDecode(this.page,this.formula,this.bitTracker)}else if(encoder==DEncoder.NONE){this.valueDecode=new VDataFloat64NoneDecode(this.page,this.formula,this.bitTracker)}else{this.valueDecode=new VDataFloat64XorDecode(this.page,this.formula,this.bitTracker)}}else if(dtype==DType.Int8){this.valueDecode=new VDataInt8NoneDecode(this.page,this.formula,this.bitTracker)}else if(dtype==DType.Int16||dtype==DType.Int32){this.valueDecode=new VDataInt32DeltaDecode(this.page,this.formula,this.bitTracker)}else if(dtype==DType.Boolean){this.valueDecode=new VDataBooleanNoneDecode(this.page,this.formula,this.bitTracker)}else if(dtype==DType.Float32){this.valueDecode=new VDataFloat32NoneDecode(this.page,this.formula,this.bitTracker)}else if(dtype==DType.Uint64){this.valueDecode=new VDataUint64XorDecode(this.page,this.formula,this.bitTracker)}else if(dtype==DType.Int64){this.valueDecode=new VDataInt64XorDecode(this.page,this.formula,this.bitTracker)}else{throw"FORMAT_VDATA_DATA_TYPE_NOT_SUPPORTED: "+String(dtype)}if(this.readCount<this.itemCount){this.timeDecode.first();this.valueDecode.first();this.emptied=false;this.readCount++}}value(){return this.valueDecode.get()}rawBits(){return this.valueDecode.bits()}pair(){return new VDataSeriesPair(this.time(),this.value())}pollAndAdd(){if(this.readCount<this.itemCount){this.timeDecode.next();this.valueDecode.next();this.readCount++}else{this.emptied=true}}}class VDataSeriesDecodeBlob extends VDataSeriesDecode{constructor(data,offset,dtype,encoder){super(data,offset);this.valueDecode=new VDataBlobDecode(this.page,this.formula,this.bitTracker,data.getBlobData());if(this.readCount<this.itemCount){this.timeDecode.first();this.valueDecode.first();this.emptied=false;this.readCount++}}value(){return this.valueDecode.get()}rawBits(){return this.valueDecode.bits()}pair(){return new VDataSeriesPair(this.time(),this.value())}pollAndAdd(){if(this.readCount<this.itemCount){this.timeDecode.next();this.valueDecode.next();this.readCount++}else{this.emptied=true}}}class VDataSeriesDecodeString extends VDataSeriesDecode{constructor(data,offset,dtype,encoder){super(data,offset);this.valueDecode=new VDataStringNoneDecode(this.page,this.formula,this.bitTracker);if(this.readCount<this.itemCount){this.timeDecode.first();this.valueDecode.first();this.emptied=false;this.readCount++}}value(){return this.valueDecode.get()}rawBits(){return this.valueDecode.bits()}pair(){return new VDataSeriesPair(this.time(),this.value())}pollAndAdd(){if(this.readCount<this.itemCount){this.timeDecode.next();this.valueDecode.next();this.readCount++}else{this.emptied=true}}}class VDataSeriesDecodeNumberArray extends VDataSeriesDecode{constructor(data,offset,dtype,encoder,length,matchLength){super(data,offset);if(encoder==DEncoder.PLAIN){this.timeDecode=new VDataTimeDeltaDecode(this.page,this.bitTracker,data.getSeriesTimestampLength());this.isPlain=true}else{this.timeDecode=new VDataTimeMicrosDecode(this.page,this.bitTracker,data.getSeriesTimestampLength());this.isPlain=false}this.valueDecode=new VDataNumberArrayDecode(this.page,dtype,encoder,length,matchLength,this.formula,this.bitTracker);if(this.readCount<this.itemCount){this.timeDecode.first();if(this.isPlain){if(this.bitTracker.getNumBits()%8!=0){var pos=Math.ceil(this.bitTracker.getNumBits()/8)*8;this.bitTracker.setNumBits(pos)}}this.valueDecode.first();this.emptied=false;this.readCount++}}value(){return this.valueDecode.get()}rawBits(){return this.valueDecode.bits()}pair(){return new VDataSeriesPair(this.time(),this.value())}pollAndAdd(){if(this.readCount<this.itemCount){this.timeDecode.next();if(this.isPlain){if(this.bitTracker.getNumBits()%8!=0){var pos=Math.ceil(this.bitTracker.getNumBits()/8)*8;this.bitTracker.setNumBits(pos)}}this.valueDecode.next();this.readCount++}else{this.emptied=true}}}class VDataSeriesDecodeStringArray extends VDataSeriesDecode{constructor(data,offset,dtype,encoder,length,matchLength){super(data,offset);this.timeDecode=new VDataTimeMicrosDecode(this.page,this.bitTracker,data.getSeriesTimestampLength());this.valueDecode=new VDataStringArrayDecode(this.page,dtype,encoder,length,matchLength,this.formula,this.bitTracker);if(this.readCount<this.itemCount){this.timeDecode.first();this.valueDecode.first();this.emptied=false;this.readCount++}}value(){return this.valueDecode.get()}rawBits(){return this.valueDecode.bits()}pair(){return new VDataSeriesPair(this.time(),this.value())}pollAndAdd(){if(this.readCount<this.itemCount){this.timeDecode.next();this.valueDecode.next();this.readCount++}else{this.emptied=true}}}class VDataSeriesDecodeNamedArray extends VDataSeriesDecode{constructor(data,offset,dtype,encoder,length){super(data,offset);this.timeDecode=new VDataTimeMicrosDecode(this.page,this.bitTracker,data.getSeriesTimestampLength());if(dtype!=DType.String){this.valueDecode=new VDataNumberArrayDecode(this.page,dtype,encoder,length,true,this.formula,this.bitTracker)}else{this.valueDecode=new VDataStringArrayDecode(this.page,dtype,encoder,length,true,this.formula,this.bitTracker)}let formulas=this.formula._formulas;this.subNames=[];for(let i=0,s=formulas.length;i<s;++i){this.subNames.push(formulas[i].name())}if(this.readCount<this.itemCount){this.timeDecode.first();this.valueDecode.first();this.emptied=false;this.readCount++}}value(){return this.valueDecode.get()}rawBits(){return this.valueDecode.bits()}pair(){return new VDataSeriesPair(this.time(),this.value())}pollAndAdd(){if(this.readCount<this.itemCount){this.timeDecode.next();this.valueDecode.next();this.readCount++}else{this.emptied=true}}getSubNames(){return this.subNames}}class VDataSeriesDecodeStruct extends VDataSeriesDecode{constructor(data,offset,dtypes,encoders,length){super(data,offset);this.timeDecode=new VDataTimeMicrosDecode(this.page,this.bitTracker,data.getSeriesTimestampLength());this.valueDecode=new VDataStructDecode(this.page,dtypes,encoders,length,this.formula,this.bitTracker);let formulas=this.formula._formulas;this.subNames=[];for(let i=0,s=formulas.length;i<s;++i){this.subNames.push(formulas[i].name())}if(this.readCount<this.itemCount){this.timeDecode.first();this.valueDecode.first();this.emptied=false;this.readCount++}}value(){return this.valueDecode.get()}rawBits(){return this.valueDecode.bits()}pair(){return new VDataSeriesPair(this.time(),this.value())}pollAndAdd(){if(this.readCount<this.itemCount){this.timeDecode.next();this.valueDecode.next();this.readCount++}else{this.emptied=true}}getSubNames(){return this.subNames}}class VDataSeries{constructor(name,buckets=null,itemCounts=null){this._name=name;this._buckets=buckets==null?[]:buckets;this._itemCounts=itemCounts==null?new Map:itemCounts}get[Symbol.toStringTag](){return"{name="+String(this._name)+", buckets="+String(this._buckets.length)+"}"}name(){return this._name}buckets(){return this._buckets}itemCounts(){return this._itemCounts}numBuckets(){return this._buckets.length}getMaxBucketItemCount(){let maxcnt=0;for(let[_,cnt]of this._itemCounts){if(cnt>maxcnt){maxcnt=cnt}}return maxcnt}updateBucketItemCounts(bucketNum,itemCount){let cnt=this._itemCounts.get(bucketNum);if(cnt==null){this._itemCounts.set(bucketNum,itemCount)}else{this._itemCounts.set(bucketNum,cnt+itemCount)}}addBucket(bucket){if(this._buckets.length==0){this._buckets.push(bucket);return}let bucketStartTime=bucket.getQueryStartTime()>bucket.getBucketStartTime()?bucket.getQueryStartTime():bucket.getBucketStartTime();if(bucketStartTime<=0){this._buckets.push(bucket);return}for(let i=this._buckets.length-1;i>=0;--i){let b=this._buckets[i];let s=b.getQueryStartTime()>b.getBucketStartTime()?b.getQueryStartTime():b.getBucketStartTime();if(s<=0){continue}if(bucketStartTime>s){this._buckets.splice(i+1,0,bucket);return}if(bucketStartTime==s){if(bucket.getBucketCycle()<b.getBucketCycle()){let index=i;while(index-1>=0){let probe=this._buckets[index-1];if(probe.getBucketStartTime()==s&&probe.getBucketCycle()>=b.getBucketCycle()){index=index-1}else{break}}let begin=i;while(begin>index){this._buckets.splice(begin,1);begin=begin-1}this._buckets[index]=b}else if(bucket.getBucketCycle()==b.getBucketCycle()){let index=i;while(index>=0){let probe=this._buckets[index];if(probe.getBucketStartTime()==s&&VDataSeriesUtils.getFirstDataTime(probe)>VDataSeriesUtils.getFirstDataTime(bucket)){index=index-1}else{break}}this._buckets.splice(index+1,0,bucket)}return}}this._buckets.splice(0,0,bucket)}formula(){return this._buckets[0].formula}}class VDataSeriesPoll{constructor(series,qsize=0,qmode=null){this._name=series.name();this._decoders=VDataSeriesDecodeBuilder.builds(series.buckets());this._qsize=qsize>0?qsize:VDataConstants.POLL_QUEUE_MIN_SIZE;this._qstime=0;this._qetime=0;let maxItemCount=series.getMaxBucketItemCount();if(this._qsize<maxItemCount+VDataConstants.POLL_QUEUE_MIN_SIZE){this._qsize=maxItemCount+VDataConstants.POLL_QUEUE_MIN_SIZE}this._decoder=null;this._decoderIndex=0;this._pair=null;this._queue=null;if(this._decoders.length>0){this._queue=this.buildQueue(qmode);this._decoder=this._decoders[0];this._qstime=this.getQueryStartTime(this._decoder);this._qetime=this.getQueryEndTime(this._decoder);let pair=this._decoder.pair();let _time=pair.time();let rcount=0;if(_time>this._qstime&&_time<this._qetime){this._queue.put(pair);rcount++}while(rcount<this._qsize){pair=this.poll();if(pair==null){break}_time=pair.time();if(_time>this._qstime&&_time<this._qetime&&this._queue.put(pair)){rcount++}}if(this._queue.empty()){this._queue=null}else{this._pair=this._queue.poll()}}}get[Symbol.toStringTag](){return"{name="+String(this._name)+", buckets="+String(this._decoders.length)+"}"}buildQueue(qmode){if(qmode==null){return new VDataPairQueueLastIn}switch(String(qmode).toLowerCase().trim()){case"all":return new VDataPairQueueAllIn;case"first":return new VDataPairQueueFirstIn;default:return new VDataPairQueueLastIn}}name(){return this._name}time(){return this._pair.time()}value(){return this._pair.value()}pair(){return this._pair}isEmpty(){return this._queue==null}poll(){if(this._decoder!=null){this._decoder.pollAndAdd();if(this._decoder.isEmpty()){this._decoderIndex+=1;if(this._decoders.length>this._decoderIndex){this._decoder=this._decoders[this._decoderIndex];this._qstime=this.getQueryStartTime(this._decoder);this._qetime=this.getQueryEndTime(this._decoder);return this._decoder.pair()}else{this._decoder=null;return null}}else{return this._decoder.pair()}}return null}pollAndAdd(){while(this._decoder!=null){this._decoder.pollAndAdd();if(this._decoder.isEmpty()){this._decoderIndex+=1;if(this._decoders.length>this._decoderIndex){this._decoder=this._decoders[this._decoderIndex];this._qstime=this.getQueryStartTime(this._decoder);this._qetime=this.getQueryEndTime(this._decoder);let pair=this._decoder.pair();let _time=pair.time();if(_time>this._qstime&&_time<this._qetime&&this._queue.put(pair)){break}}else{this._decoder=null}}else{let pair=this._decoder.pair();let _time=pair.time();if(_time>this._qstime&&_time<this._qetime&&this._queue.put(pair)){break}}}if(this._queue.empty()){this._queue=null}else{this._pair=this._queue.poll()}}getQueryStartTime(_decoder){return _decoder.getQueryStartTime()>0?_decoder.getQueryStartTime()-1:0}getQueryEndTime(_decoder){return _decoder.getQueryEndTime()>0?_decoder.getQueryEndTime()+1:Number.MAX_VALUE}formula(){return this._decoders[0].formula}getSubNames(){return this._decoders[0].getSubNames()}}class VDataPairQueue{constructor(){this.data=[]}empty(){return this.data.length==0}put(item){return false}poll(){if(this.data.length===0){return null}return this.data.shift()}peek(){return this.data[0]}}class VDataPairQueueAllIn extends VDataPairQueue{put(item){let low=0,high=this.data.length;if(high==0){this.data.push(item);return true}let current=this.data[high-1];let l=current.time(),t=item.time();if(t>=l){this.data.push(item);return true}while(low<high){let mid=low+high>>>1;if(this.data[mid].time()<t){low=mid+1}else{high=mid}}if(this.data[low].time()==t){while(this.data[low+1].time()==t){low=low+1}}this.data.splice(low,0,item);return true}}class VDataPairQueueFirstIn extends VDataPairQueue{put(item){let low=0,high=this.data.length;if(high==0){this.data.push(item);return true}let current=this.data[high-1];let l=current.time(),t=item.time();if(t>l){this.data.push(item);return true}else if(t==l){return false}while(low<high){let mid=low+high>>>1;if(this.data[mid].time()<t){low=mid+1}else{high=mid}}if(this.data[low].time()==t){return false}this.data.splice(low,0,item);return true}}class VDataPairQueueLastIn extends VDataPairQueue{put(item){let low=0,high=this.data.length;if(high==0){this.data.push(item);return true}let current=this.data[high-1];let l=current.time(),t=item.time();if(t>l){this.data.push(item);return true}else if(t==l){this.data[high-1]=item;return false}while(low<high){let mid=low+high>>>1;if(this.data[mid].time()<t){low=mid+1}else{high=mid}}if(this.data[low].time()==t){this.data[low]=item;return false}this.data.splice(low,0,item);return true}}class VDataPollQueue{constructor(){this.data=[];this.length=0}empty(){return this.length==0}put(item){this.data.push(item);this._up(this.length++)}poll(){if(this.length===0){return null}const top=this.data[0];const bottom=this.data.pop();if(--this.length>0){this.data[0]=bottom;this._down(0)}return top}peek(){return this.data[0]}pop(){if(this.length===0){return[]}const t=this.peek().time();const grouped=[];while(!this.empty()&&this.peek().time()==t){grouped.push(this.poll())}return grouped}_up(pos){const item=this.data[pos];while(pos>0){const parent=pos-1>>1;const current=this.data[parent];if(item.time()>=current.time()){break}this.data[pos]=current;pos=parent}this.data[pos]=item}_down(pos){const halfLength=this.length>>1;const item=this.data[pos];while(pos<halfLength){let bestChild=(pos<<1)+1;const right=bestChild+1;if(right<this.length&&this.data[right].time()<this.data[bestChild].time()){bestChild=right}if(this.data[bestChild].time()>=item.time()){break}this.data[pos]=this.data[bestChild];pos=bestChild}this.data[pos]=item}}class VDataSignalFilter{constructor(){this._signals=new Set;this._prefixes=new Set;this._signal_names=[]}getSignals(){return this._signals}setSignals(signals){if(signals!=null){this._signal_names=VDataUtils.insertion_order_set_list(signals);this._signals=new Set(this._signal_names)}else{this._signals.clear()}}getPrefixes(){return this._prefixes}setPrefixes(prefixes){if(prefixes!=null){this._prefixes=new Set(prefixes)}else{this._prefixes.clear()}}getSignalNames(){return this._signal_names}isEmpty(){return this._signals.size==0&&this._prefixes.size==0}hasNameFilterOnly(){return this._signals.size>0&&this._prefixes.size==0}}class VDataFrame{constructor(buckets,series,signalFilter=null,columnExpandMode=null,signalQueueMode=null){this._signalFilter=signalFilter!=null?signalFilter:new VDataSignalFilter;this._columnExpandMode=VDataUtils.getColumnExpandMode(columnExpandMode);this._qualifiedExpandName=VDataUtils.isQualifiedExpandName(columnExpandMode);this._signalQueueMode=VDataUtils.getSignalQueueMode(signalQueueMode);this._startTime=0;this._endTime=0;this._buckets=buckets;this._series={};for(const k in series){if(series[k].numBuckets()>0){this._series[series[k].name()]=series[k]}}}get[Symbol.toStringTag](){return Object.keys(this._series)}getSignalFilter(){return this._signalFilter}setSignalFilter(signalFilter){if(signalFilter!=null){this._signalFilter=signalFilter}}getColumnExpandMode(){return this._columnExpandMode}setColumnExpandMode(mode){this._columnExpandMode=VDataUtils.getColumnExpandMode(mode);this._qualifiedExpandName=VDataUtils.isQualifiedExpandName(mode)}getSignalQueueMode(){return this._signalQueueMode}setSignalQueueMode(mode){this._signalQueueMode=VDataUtils.getSignalQueueMode(mode)}getStartTime(){return this._startTime}setStartTime(time){this._startTime=time}getEndTime(){return this._endTime}setEndTime(time){this._endTime=time}cols(includeTime=false){let columns=VDataSeriesUtils.seriesToColumns(this._series,this._signalFilter,this._columnExpandMode,this._qualifiedExpandName);if(includeTime){columns.splice(0,0,"time")}return columns}series(){return this._series}values(densifyRowsAhead=0,densifyOutputItv=0,signalQueueRows=0){let queue=new VDataPollQueue;let templateable=new Map;let data=[];let interval=densifyOutputItv>0?densifyOutputItv:0;let denseitv=interval!=0;let nextTime=0;let columns=VDataSeriesUtils.seriesToColumns(this._series,this._signalFilter,this._columnExpandMode,this._qualifiedExpandName);for(const column of columns){templateable.set(column,null)}let selectall=this._signalFilter.isEmpty();for(const column in this._series){if(selectall||VDataSeriesUtils.serieContainsSignal(templateable,this._series[column].formula(),this._columnExpandMode,this._qualifiedExpandName)){let poll=new VDataSeriesPoll(this._series[column],signalQueueRows,this._signalQueueMode);if(!poll.isEmpty()){queue.put(poll)}}}if(densifyRowsAhead<=0){while(!queue.empty()){let polls=queue.pop();let _time=polls[0].time();let values=new Map(templateable);for(let i=0;i<polls.length;++i){let poll=polls[i];this.put(values,poll);poll.pollAndAdd();if(!poll.isEmpty()){queue.put(poll)}}let row=[_time];row.push.apply(row,[...values.values()]);data.push(row)}}else{let records=[];let cnt=0;while(cnt++<=densifyRowsAhead){if(queue.empty()){break}let values=new Map;let polls=queue.pop();let _time=polls[0].time();for(let i=0;i<polls.length;++i){let poll=polls[i];this.tut(templateable,values,poll);poll.pollAndAdd();if(!poll.isEmpty()){queue.put(poll)}}records.push(new VDataRecord(_time,values))}nextTime=denseitv?this.cutoffInterval(records[0].time(),interval):0;for(const record of records){if(denseitv){let millis=this.cutoffInterval(record.time(),interval);if(millis!=nextTime){let row=[nextTime];row.push.apply(row,[...templateable.values()]);data.push(row);nextTime=nextTime+interval}}let _values=record.values();for(let[_k,_v]of _values){templateable.set(_k,_v)}if(!denseitv){let row=[record.time()];row.push.apply(row,[...templateable.values()]);data.push(row)}}while(!queue.empty()){let polls=queue.pop();let _time=polls[0].time();if(denseitv){let millis=this.cutoffInterval(_time,interval);if(millis!=nextTime){let row=[nextTime];row.push.apply(row,[...templateable.values()]);data.push(row);nextTime=nextTime+interval}}for(let i=0;i<polls.length;++i){let poll=polls[i];this.put(templateable,poll);poll.pollAndAdd();if(!poll.isEmpty()){queue.put(poll)}}if(!denseitv){let row=[_time];row.push.apply(row,[...templateable.values()]);data.push(row)}}}if(denseitv&&nextTime!=0){let row=[nextTime];row.push.apply(row,[...templateable.values()]);data.push(row)}console.log("Data rows: "+String(data.length));return data}put(values,poll){let pname=poll.name();let pval=poll.value();let subNames=poll.getSubNames();if(subNames==null||subNames.length==0){values.set(pname,pval)}else if(this._columnExpandMode==DExpand.NONE){let subValues=pval;let pmap={};for(let i=0,s=subNames.length;i<s;++i){pmap[subNames[i]]=subValues[i]}values.set(pname,pmap)}else{let subValues=pval;for(let i=0,s=subNames.length;i<s;++i){let subName=this._qualifiedExpandName?pname+"."+subNames[i]:subNames[i];if(values.has(subName)){values.set(subName,subValues[i])}}}}tut(templateable,values,poll){let pname=poll.name();let pval=poll.value();let subNames=poll.getSubNames();if(subNames==null||subNames.length==0){if(templateable.get(pname)==null){templateable.set(pname,pval)}values.set(pname,pval)}else if(this._columnExpandMode==DExpand.NONE){let subValues=pval;let pmap={};for(let i=0,s=subNames.length;i<s;++i){pmap[subNames[i]]=subValues[i]}if(templateable.get(pname)==null){templateable.set(pname,pmap)}values.set(pname,pmap)}else{let subValues=pval;for(let i=0,s=subNames.length;i<s;++i){let subName=this._qualifiedExpandName?pname+"."+subNames[i]:subNames[i];if(templateable.has(subName)){if(templateable.get(subName)==null){templateable.set(subName,subValues[i])}values.set(subName,subValues[i])}}}}objects(densifyRowsAhead=0,densifyOutputItv=0){if(this._endTime-this._startTime>36e5){return this.values(densifyRowsAhead,densifyOutputItv)}let oread=null;switch(this._signalQueueMode){case"all":oread=new VDataObjectsSeriesAllMode(this._series,this._signalFilter,this._columnExpandMode,this._qualifiedExpandName,this._startTime,this._endTime);break;case"first":oread=new VDataObjectsSeriesFirstMode(this._series,this._signalFilter,this._columnExpandMode,this._qualifiedExpandName,this._startTime,this._endTime);break;default:oread=new VDataObjectsSeriesReader(this._series,this._signalFilter,this._columnExpandMode,this._qualifiedExpandName,this._startTime,this._endTime)}let objects=oread.read();if(densifyRowsAhead<=0||objects.length<=1){return objects}for(let col=1,cols=objects[0].length;col<cols;++col){if(objects[0][col]==null){for(let row=1;row<densifyRowsAhead;++row){if(objects[row][col]!=null){objects[0][col]=objects[row][col];break}}}}for(let row=1,rows=objects.length;row<rows;++row){for(let col=1,cols=objects[row].length;col<cols;++col){if(objects[row][col]==null){objects[row][col]=objects[row-1][col]}}}if(densifyOutputItv<=0){return objects}let itv=new Array;let nextTime=this.cutoffInterval(objects[0][0],densifyOutputItv);let millis=nextTime;let row=0;let rows=objects.length;let lastpos=-1;let pos=0;do{while(millis==nextTime){if(++row>=rows){break}millis=this.cutoffInterval(objects[row][0],densifyOutputItv)}pos=row-1;if(lastpos!=pos){objects[pos][0]=nextTime;itv.push(objects[pos]);lastpos=pos}else{let objcopy=[...objects[pos]];objcopy[0]=nextTime;itv.push(objcopy)}nextTime=nextTime+densifyOutputItv}while(row<rows);return itv}object1s(){return this.sampling(1e3)}sampling(frequency){if(frequency<=1){throw"Sampling frequency must be greater than 1"}let oread=null;switch(this._signalQueueMode){case"first":oread=new VDataObjectsSeriesFirstMode(this._series,this._signalFilter,this._columnExpandMode,this._qualifiedExpandName,this._startTime,this._endTime);break;default:oread=new VDataObjectsSeriesReader(this._series,this._signalFilter,this._columnExpandMode,this._qualifiedExpandName,this._startTime,this._endTime)}return oread.sampling(frequency)}cutoffInterval(time,interval){let millis=Math.floor(time);let cutoff=Math.floor(millis/interval)*interval;return millis>cutoff?cutoff+interval:cutoff}}class VDataDecoder{static get pako(){return require("pako")}static get fzstd(){return require("fzstd")}constructor(reader,meta){this._reader=reader;this._meta=meta;this._signals=new Set;this._prefixes=new Set;this._insensitiveCase=false;this._readLivingData=true;this._queryFilter=true;this._queryStartTime=0;this._queryEndTime=0;this._columnExpandMode=null;this._qualifiedExpandName=false;this._signalQueueMode=null;this._buckets=null;this._keys=null}get[Symbol.toStringTag](){if(this._meta==null){return"{}"}return"{start="+(this._meta.queryStartTime()>0?String(this._meta.queryStartTime()):String(this._meta.storageStartTime()))+", end="+(this._meta.queryEndTime()>0?String(this._meta.queryEndTime()):String(this._meta.storageEndTime()))+", buckets="+String(this._buckets.length)+", keys="+String(Object.keys(this._keys).length)+"}"}setSignalFilter(signalFilter){if(signalFilter!=null){this._signals=signalFilter.getSignals();this._prefixes=signalFilter.getPrefixes()}else{this._signals.clear();this._prefixes.clear()}}setInsensitiveCase(insensitiveCase){this._insensitiveCase=insensitiveCase}setReadLivingData(readLivingData){this._readLivingData=readLivingData}setQueryFilter(queryFilter){this._queryFilter=queryFilter}setQueryRange(qstime,qetime){this._queryStartTime=qstime;this._queryEndTime=qetime}setColumnExpandMode(columnExpandMode){this._columnExpandMode=columnExpandMode}setSignalQueueMode(signalQueueMode){this._signalQueueMode=signalQueueMode}setSignalDeocders(signalDecoders){this._signalDecoders=signalDecoders}initialize(){const hasSignalFilter=this._signals.size>0||this._prefixes.size>0;let formulas={};this._keys={};this._columnExpandMode=VDataUtils.getColumnExpandMode(this._columnExpandMode);this._qualifiedExpandName=VDataUtils.isQualifiedExpandName(this._columnExpandMode);const formatVersion=this._meta.formatVersion();const compressMethod=this._meta.compressMethod();const encryptMethod=this._meta.encryptMethod();const blocksCount=this._meta.blocksCount();if(this._queryStartTime==0&&this._meta.queryStartTime()==0){this._queryStartTime=this._meta.storageStartTime()}if(this._queryEndTime==0&&this._meta.queryEndTime()==0){this._queryEndTime=this._meta.storageEndTime()}console.log("file format verion: "+formatVersion);console.log("file bucket count: "+blocksCount);if(formatVersion>=26){console.log("file query start time: "+this._meta.queryStartTime());console.log("file query end time: "+this._meta.queryEndTime())}if(this._meta.pageSize()!=32768){this.readKeys()}else{this.readStfKeys()}for(let[_,key]of Object.entries(this._keys)){formulas[key._seriesid]=key._formula;if(this._signalDecoders!=undefined&&this._signalDecoders[key._name]!=undefined){if(key._formula instanceof VDataFormulaBlob){let de=this._signalDecoders[key._name];key._formula.setSignalDeocder(de)}else{key._formula=new VDataFormulaBlob(key._name);key._formula.setSignalDeocder(this._signalDecoders[key._name]);formulas[key._seriesid]=key._formula}}}this._buckets=[];for(let b=0;b<blocksCount;++b){let crc=0;let length=0;let bucketCycle=0;let bucketStartTime=0;let bucketEndTime=0;let living=0;let blobCompressType=0;let position=0;let dataStartTime=0;let dataEndTime=0;let blobCount=0;let blobDataLength=0;let blobCrc=0;if(formatVersion<24){crc=this.readLong(this._reader.read(8));living=this._reader.read(1)&1;this._reader.read(7);length=this.readInt(this._reader.read(4))-24;this._reader.read(4)}else if(formatVersion<27){crc=this.readLong(this._reader.read(8));living=this._reader.read(1)&1;this._reader.read(3);bucketCycle=this.readInt(this._reader.read(4));bucketStartTime=this.readLong(this._reader.read(8));bucketEndTime=this.readLong(this._reader.read(8));length=this.readInt(this._reader.read(4))-40;this._reader.read(4)}else{if(this._meta.pageSize()!=32768){crc=this.readLong(this._reader.read(8));living=this._reader.read(1)&1;this._reader.read(3);bucketCycle=this.readInt(this._reader.read(4));bucketStartTime=this.readLong(this._reader.read(8));bucketEndTime=this.readLong(this._reader.read(8));length=this.readInt(this._reader.read(4))-72;position=this.readInt(this._reader.read(4));dataStartTime=this.readLong(this._reader.read(8));dataEndTime=this.readLong(this._reader.read(8));blobCrc=this.readLong(this._reader.read(8));blobCount=this.readInt(this._reader.read(4));blobDataLength=this.readInt(this._reader.read(4))}else{crc=this.readLong(this._reader.read(8));living=this._reader.read(1)&1;this._reader.read(3);bucketCycle=this.readInt(this._reader.read(4));bucketStartTime=this.readLong(this._reader.read(8));bucketEndTime=this.readLong(this._reader.read(8));length=this.readInt(this._reader.read(4))-48;position=this.readInt(this._reader.read(4));blobCount=this.readInt(this._reader.read(4));blobDataLength=this.readInt(this._reader.read(4))}}if(length<=0){throw"FORMAT_VDATA_BUCKET_LENGTH_INVALID"}let databytes=this.decompress(this._reader.read(length),compressMethod);let blobDatabytes=[];if(blobDataLength>0){blobDatabytes=this.decompress(this._reader.read(blobDataLength),compressMethod)}if(crc!=0){if(crc!=this.crc32(databytes)){throw"FORMAT_VDATA_CRC_MISMATCH"}}if(living!=0&&!this._readLivingData){continue}let seriesCount=0;let activePages=0;let seriesMetas=[];let storageIdHighs=[];let storageIdLows=[];let seriesIds=[];let storageIdLength=this._meta.storageIdLength();seriesCount=this.readInt(databytes.slice(0,4));activePages=this.readInt(databytes.slice(4,8));if(seriesCount<=0){throw"FORMAT_VDATA_SERIES_COUNT_ZERO"}if(activePages<=0){throw"FORMAT_VDATA_ACTIVE_PAGES_ZERO"}let index=8;if(this._meta.pageSize()!=32768){for(let i=0;i<seriesCount;++i,index+=4){seriesIds.push(this.readInt(databytes.slice(index,index+4)))}for(let i=0;i<seriesCount;++i,index+=8){let storageidbt=databytes.slice(index,index+8);storageIdHighs.push(this.readUInt(storageidbt,4));storageIdLows.push(this.readUInt(storageidbt,0))}}else{for(let i=0;i<this._keyIds.length;++i){if((databytes[index+(i>>3)]>>(i&7)&1)==1){seriesIds.push(this._keyIds[i])}}index+=Math.floor((this._keyIds.length+7)/8);for(let i=0;i<seriesCount;++i,index+=storageIdLength){let storageidbt=databytes.slice(index,index+storageIdLength);if(storageIdLength==5){storageIdHighs.push(storageidbt[4]&255)}else{storageIdHighs.push((storageidbt[4]|storageidbt[5]<<8)&65535)}storageIdLows.push(this.readUInt(storageidbt,0))}}let blobSeriesIds=[];let blobOffsetVec=[];let blobLengthVec=[];let sid_to_blob_idx={};for(let i=0;i<blobCount;++i,index+=4){blobSeriesIds.push(this.readInt(databytes.slice(index,index+4)));sid_to_blob_idx[blobSeriesIds[i]]=i}for(let i=0;i<blobCount;++i,index+=4){blobOffsetVec.push(this.readInt(databytes.slice(index,index+4)))}for(let i=0;i<blobCount;++i,index+=4){blobLengthVec.push(this.readInt(databytes.slice(index,index+4)))}for(let i=0;i<seriesCount;++i){if(seriesIds[i]in formulas==false){throw"FORMAT_VDATA_SERIES_NOT_FOUND: "+String(seriesIds[i])}if(hasSignalFilter&&!VDataSeriesUtils.serieMatchSignalFilter(this._signals,this._prefixes,formulas[seriesIds[i]],this._columnExpandMode,this._qualifiedExpandName)){continue}const mt=new VDataSeriesMeta(formulas[seriesIds[i]],storageIdHighs[i],storageIdLows[i],this._meta.pageSize(),storageIdLength);if(mt.dataLength()==0||mt.itemCount()==0){throw"FORMAT_VDATA_SERIES_DATA_EMPTY: "+mt.name()}seriesMetas.push(mt)}let bucket=new VDataBucket;bucket.setStartTime(bucketStartTime);bucket.setEndTime(bucketEndTime);bucket.setCycle(bucketCycle);bucket.setLiving(living);bucket.setCrc(crc);for(let i=0,s=seriesMetas.length;i<s;++i){const mt=seriesMetas[i];let bstart=index+mt.pageIndex()*this._meta.pageSize()+mt.pageOffset();let bend=bstart+mt.dataLength();let bt=databytes.slice(bstart,bend);let seriesBucket=new VDataSeriesBucket;seriesBucket.setFormatVersion(formatVersion);seriesBucket.setMeta(mt);seriesBucket.setPage(bt);seriesBucket.setBucketCycle(bucketCycle);seriesBucket.setBucketStartTime(bucketStartTime);seriesBucket.setBucketEndTime(bucketEndTime);seriesBucket.setSeriesTimestampLength(this._meta.seriesTimestampLength());if(sid_to_blob_idx[i]!=undefined){let idx=sid_to_blob_idx[i];let seriesBlobData=blobDatabytes.slice(blobOffsetVec[idx],blobOffsetVec[idx]+blobLengthVec[idx]);seriesBucket.setBlobData(seriesBlobData)}if(seriesBucket.getItemCount()>0){bucket.addSeriesBucket(seriesBucket)}}if(bucket.getSeriesBuckets().length>0){if(bucket.getStartTime()==0){let serieDecoders=VDataSeriesDecodeBuilder.builds(bucket.getSeriesBuckets());let minSeriesStartTime=serieDecoders[0].time();for(let i=1;i<serieDecoders.length;++i){let tm=serieDecoders[i].time();if(tm<minSeriesStartTime){minSeriesStartTime=tm}}bucket.setStartTime(minSeriesStartTime);bucket.setNotime(1)}VDataBucketUtils.sortAddBucket(this._buckets,bucket,false,this._signalQueueMode)}}VDataBucketUtils.updateBucketQueryRange(this._buckets,this._meta,this._signalQueueMode,this._queryFilter,this._queryStartTime,this._queryEndTime)}readKeys(){const compressMethod=this._meta.compressMethod();const keysCount=this.readInt(this._reader.read(4));let length=this.readInt(this._reader.read(4));if(keysCount<=0){throw"FORMAT_VDATA_KEYS_COUNT_INVALID"}if(length<=0){throw"FORMAT_VDATA_KEYS_LENGTH_INVALID"}let databytes=this.decompress(this._reader.read(length),compressMethod);let fmbulider=new VDataFormulaFactory;let datareader=new VDataByteReader(databytes);for(let i=0;i<keysCount;++i){const keyid=this.readInt(datareader.read(4));let keyname=[];let b=datareader.read(1);while(b[0]!=0){keyname.push(b[0]);b=datareader.read(1)}if(keyname.length==0){throw"FORMAT_VDATA_KEY_NAME_EMPTY"}let desc=(new TextDecoder).decode(new Uint8Array(keyname));let formula=fmbulider.build(desc,this._insensitiveCase);let sname=this.getUniqueName(this._keys,formula._name);if(sname!=formula._name){console.log("Replace series "+String(keyid)+" duplicate name {"+formula._name+"} with name {"+sname+"}");formula._name=sname}this._keys[sname]=new VDataSeriesSpec(sname,keyid,formula,desc)}}readStfKeys(){const keysCount=this.readInt(this._reader.read(4));let length=this.readInt(this._reader.read(4));if(keysCount<=0){throw"FORMAT_VDATA_KEYS_COUNT_INVALID"}if(length<=0){throw"FORMAT_VDATA_KEYS_LENGTH_INVALID"}let formulaNone=new VDataFormulaNone("keys");let databytes=this._reader.read(length);let decode=new VDataInt32DeltaDecode(databytes,formulaNone,new BitTracker);this._keyIds=[];for(var i=0;i<keysCount;i++){decode.next();let keyid=decode.get();let sname="0x"+keyid.toString(16).padStart(8,"0").toUpperCase();this._keyIds.push(keyid);this._keys[sname]=new VDataSeriesSpec(sname,keyid,new VDataFormulaNone(sname),sname)}}readInt(_bytes){return new DataView(new Uint8Array(_bytes).buffer).getInt32(0,true)}readUInt(_bytes,offset){return new DataView(new Uint8Array(_bytes).buffer).getUint32(offset,true)}readLong(_bytes){return Number(new DataView(new Uint8Array(_bytes).buffer).getBigInt64(0,true))}crc32(_bytes){const a_table="00000000 77073096 EE0E612C 990951BA 076DC419 706AF48F E963A535 9E6495A3 0EDB8832 79DCB8A4 E0D5E91E 97D2D988 09B64C2B 7EB17CBD E7B82D07 90BF1D91 1DB71064 6AB020F2 F3B97148 84BE41DE 1ADAD47D 6DDDE4EB F4D4B551 83D385C7 136C9856 646BA8C0 FD62F97A 8A65C9EC 14015C4F 63066CD9 FA0F3D63 8D080DF5 3B6E20C8 4C69105E D56041E4 A2677172 3C03E4D1 4B04D447 D20D85FD A50AB56B 35B5A8FA 42B2986C DBBBC9D6 ACBCF940 32D86CE3 45DF5C75 DCD60DCF ABD13D59 26D930AC 51DE003A C8D75180 BFD06116 21B4F4B5 56B3C423 CFBA9599 B8BDA50F 2802B89E 5F058808 C60CD9B2 B10BE924 2F6F7C87 58684C11 C1611DAB B6662D3D 76DC4190 01DB7106 98D220BC EFD5102A 71B18589 06B6B51F 9FBFE4A5 E8B8D433 7807C9A2 0F00F934 9609A88E E10E9818 7F6A0DBB 086D3D2D 91646C97 E6635C01 6B6B51F4 1C6C6162 856530D8 F262004E 6C0695ED 1B01A57B 8208F4C1 F50FC457 65B0D9C6 12B7E950 8BBEB8EA FCB9887C 62DD1DDF 15DA2D49 8CD37CF3 FBD44C65 4DB26158 3AB551CE A3BC0074 D4BB30E2 4ADFA541 3DD895D7 A4D1C46D D3D6F4FB 4369E96A 346ED9FC AD678846 DA60B8D0 44042D73 33031DE5 AA0A4C5F DD0D7CC9 5005713C 270241AA BE0B1010 C90C2086 5768B525 206F85B3 B966D409 CE61E49F 5EDEF90E 29D9C998 B0D09822 C7D7A8B4 59B33D17 2EB40D81 B7BD5C3B C0BA6CAD EDB88320 9ABFB3B6 03B6E20C 74B1D29A EAD54739 9DD277AF 04DB2615 73DC1683 E3630B12 94643B84 0D6D6A3E 7A6A5AA8 E40ECF0B 9309FF9D 0A00AE27 7D079EB1 F00F9344 8708A3D2 1E01F268 6906C2FE F762575D 806567CB 196C3671 6E6B06E7 FED41B76 89D32BE0 10DA7A5A 67DD4ACC F9B9DF6F 8EBEEFF9 17B7BE43 60B08ED5 D6D6A3E8 A1D1937E 38D8C2C4 4FDFF252 D1BB67F1 A6BC5767 3FB506DD 48B2364B D80D2BDA AF0A1B4C 36034AF6 41047A60 DF60EFC3 A867DF55 316E8EEF 4669BE79 CB61B38C BC66831A 256FD2A0 5268E236 CC0C7795 BB0B4703 220216B9 5505262F C5BA3BBE B2BD0B28 2BB45A92 5CB36A04 C2D7FFA7 B5D0CF31 2CD99E8B 5BDEAE1D 9B64C2B0 EC63F226 756AA39C 026D930A 9C0906A9 EB0E363F 72076785 05005713 95BF4A82 E2B87A14 7BB12BAE 0CB61B38 92D28E9B E5D5BE0D 7CDCEFB7 0BDBDF21 86D3D2D4 F1D4E242 68DDB3F8 1FDA836E 81BE16CD F6B9265B 6FB077E1 18B74777 88085AE6 FF0F6A70 66063BCA 11010B5C 8F659EFF F862AE69 616BFFD3 166CCF45 A00AE278 D70DD2EE 4E048354 3903B3C2 A7672661 D06016F7 4969474D 3E6E77DB AED16A4A D9D65ADC 40DF0B66 37D83BF0 A9BCAE53 DEBB9EC5 47B2CF7F 30B5FFE9 BDBDF21C CABAC28A 53B39330 24B4A3A6 BAD03605 CDD70693 54DE5729 23D967BF B3667A2E C4614AB8 5D681B02 2A6F2B94 B40BBE37 C30C8EA1 5A05DF1B 2D02EF8D";const b_table=a_table.split(" ").map((function(s){return parseInt(s,16)}));let crc=-1;for(let i=0,s=_bytes.length;i<s;++i){crc=crc>>>8^b_table[(crc^_bytes[i])&255]}return(crc^-1)>>>0}getUniqueName(keys,key){if(key in keys==false){return key}let counter=2;let backup=key+"_duplicate_"+String(counter).padStart(5,"0");while(backup in keys&&counter<1e5){counter=counter+1;backup=key+"_duplicate_"+String(counter).padStart(5,"0")}if(counter==1e5){throw"FORMAT_VDATA_KEY_NAME_BACKUP_EXHAUSTED: "+key}return backup}decompress(_bytes,_compressMethod){if(_compressMethod==1){return pako.inflate(_bytes)}if(_compressMethod==3){return fzstd.decompress(_bytes)}return _bytes}buckets(){return this._buckets}keys(){return this._keys}meta(){return this._meta}}class VDataBucketUtils{static sortAddBucket(buckets,bucket,dropMultiFileIntersects,signalQueueMode){if(VDataUtils.isAllSignalQueueMode(signalQueueMode)){VDataBucketUtils.sortAllBucketForAllQueueMode(buckets,bucket,dropMultiFileIntersects)}else{VDataBucketUtils.sortAllBucketForSingleQueueMode(buckets,bucket)}}static _getSeriesNameSet(bucket){let names=new Set;if(bucket==null||bucket.seriesBuckets==null){return names}for(let i=0;i<bucket.seriesBuckets.length;++i){names.add(bucket.seriesBuckets[i].name)}return names}static isStrictlyIdenticalBucket(left,right){if(left==null||right==null){return false}if(left.getCrc()==0||right.getCrc()==0||left.getCrc()!=right.getCrc()){return false}if(left.getStartTime()!=right.getStartTime()||left.getEndTime()!=right.getEndTime()||left.getCycle()!=right.getCycle()||left.isLiving()!=right.isLiving()){return false}if(left.seriesBuckets.length!=right.seriesBuckets.length){return false}let leftSeriesNames=VDataBucketUtils._getSeriesNameSet(left);let rightSeriesNames=VDataBucketUtils._getSeriesNameSet(right);if(leftSeriesNames.size!=rightSeriesNames.size){return false}for(let name of leftSeriesNames){if(!rightSeriesNames.has(name)){return false}}return true}static sortAllBucketForSingleQueueMode(buckets,bucket){let size=buckets.length;if(size==0){console.log("Add bucket "+String(bucket));buckets.push(bucket);return}let bucketStartTime=bucket.getStartTime();for(let i=size-1;i>=0;--i){let bk=buckets[i];let st=bk.getStartTime();if(st==bucketStartTime){if(bucket.getCrc()!=0){for(let j=i;j>=0;--j){let stbk=buckets[j];if(stbk.getStartTime()!=st){break}if(bucket.getCrc()==stbk.getCrc()){let reason="identical";console.warn("Keep "+reason+" bucket "+String(stbk)+" discard bucket "+String(bucket));return}}}console.log("Add bucket "+String(bucket));buckets.splice(i+1,0,bucket);return}else if(st<bucketStartTime){console.log("Add bucket "+String(bucket));buckets.splice(i+1,0,bucket);return}}console.log("Add bucket "+String(bucket));buckets.splice(0,0,bucket)}static sortAllBucketForAllQueueMode(buckets,bucket,dropMultiFileIntersects){let size=buckets.length;if(size==0){console.log("Add bucket "+String(bucket));buckets.push(bucket);return}let bucketStartTime=bucket.getStartTime();for(let i=size-1;i>=0;--i){let bk=buckets[i];let st=bk.getStartTime();if(VDataBucketUtils.isStrictlyIdenticalBucket(bk,bucket)){console.warn("Keep strict-identical bucket "+String(bk)+" discard bucket "+String(bucket));return}if(bk.intersects(bucket)){continue}if(st<bucketStartTime){console.log("Add bucket "+String(bucket));buckets.splice(i+1,0,bucket);return}}console.log("Add bucket "+String(bucket));buckets.splice(0,0,bucket)}static updateBucketQueryRange(buckets,meta,signalQueueMode,queryFilter,queryStartTime,queryEndTime){let _qstime=queryFilter?queryStartTime>0?queryStartTime:meta.queryStartTime():0;if(VDataUtils.isAllSignalQueueMode(signalQueueMode)){let _qetime=queryFilter?queryEndTime>0?queryEndTime:meta.queryEndTime():0;for(let b=0;b<buckets.length;++b){let bucket=buckets[b];let cetime=bucket.isLiving()?Number.MAX_VALUE-1:bucket.getEndTime();let qstime=Math.max(_qstime,bucket.getStartTime());let qetime=_qetime>0?Math.min(_qetime,cetime):cetime;for(let j=0;j<bucket.seriesBuckets.length;++j){let seriesBucket=bucket.seriesBuckets[j];seriesBucket.setQueryStartTime(qstime);seriesBucket.setQueryEndTime(qetime)}}}else{let _qetime=queryFilter?queryEndTime>0?queryEndTime:meta.queryEndTime():Number.MAX_VALUE-1;for(let b=0;b<buckets.length;++b){let bucket=buckets[b];for(let j=0;j<bucket.seriesBuckets.length;++j){let seriesBucket=bucket.seriesBuckets[j];seriesBucket.setQueryStartTime(_qstime);seriesBucket.setQueryEndTime(_qetime)}}}}}class VDataSeriesSpec{constructor(name,seriesid,formula,desc){this._name=name;this._seriesid=seriesid;this._formula=formula;this._desc=desc}}class VDataSeriesUtils{static seriesToColumns(series,signalFilter,columnExpandMode,qualifiedExpandName){if(signalFilter.hasNameFilterOnly()){return Array.from(signalFilter.getSignalNames())}let allcols=[];if(columnExpandMode==DExpand.NONE){allcols=Object.keys(series)}else{for(const k in series){let ss=series[k];if(ss.numBuckets()==0){continue}let formula=ss.formula();if(formula instanceof VDataFormulaStruct||formula instanceof VDataFormulaNamedArray){for(const i in formula._formulas){let f=formula._formulas[i];if(qualifiedExpandName){allcols.push(k+"."+f._name)}else{allcols.push(f._name)}}continue}allcols.push(formula._name)}}if(signalFilter.isEmpty()){return VDataUtils.insertion_order_set_list(allcols)}let selected=[];let smap=signalFilter.getSignals();let spfx=signalFilter.getPrefixes();for(let col of allcols){if(VDataSeriesUtils.containsSignal(smap,spfx,col)){selected.push(col)}}return VDataUtils.insertion_order_set_list(selected)}static serieContainsSignal(signals,formula,columnExpandMode,qualifiedExpandName){if(columnExpandMode==DExpand.NONE){return true}if(formula instanceof VDataFormulaStruct||formula instanceof VDataFormulaNamedArray){let serieName=formula.name();for(const i in formula._formulas){let f=formula._formulas[i];let name=qualifiedExpandName?serieName+"."+f._name:f._name;if(signals.has(name)){return true}}}else{return signals.has(formula.name())}return false}static serieMatchSignalFilter(signals,prefixes,formula,columnExpandMode,qualifiedExpandName){if(columnExpandMode==DExpand.NONE){return VDataSeriesUtils.containsSignal(signals,prefixes,formula.name())}if(formula instanceof VDataFormulaStruct||formula instanceof VDataFormulaNamedArray){let serieName=formula.name();for(const i in formula._formulas){let f=formula._formulas[i];let name=qualifiedExpandName?serieName+"."+f._name:f._name;if(VDataSeriesUtils.containsSignal(signals,prefixes,name)){return true}}}else{return VDataSeriesUtils.containsSignal(signals,prefixes,formula.name())}return false}static containsSignal(signals,prefixes,name){if(signals.has(name)){return true}for(const prefix of prefixes){if(name.startsWith(prefix)){return true}}return false}static getFirstDataTime(bt){let time=bt.getFirstTime();if(time!=null){return time}let decoder=VDataSeriesDecodeBuilder.build(bt);time=decoder.time();bt.setFirstTime(time);return time}}class VDataObjectsSeriesReader{constructor(series,signalFilter,columnExpandMode,qualifiedExpandName,startTime,endTime){this._series=series;this._signalFilter=signalFilter;this._columnExpandMode=columnExpandMode;this._qualifiedExpandName=qualifiedExpandName;this._startTime=startTime;this._endTime=endTime;let timediff=this._endTime-this._startTime+1;if(timediff<=0){throw"invalid negative time range"}if(timediff>Number.MAX_VALUE){throw"time range is too big to use objects() method"}this._columns=VDataSeriesUtils.seriesToColumns(series,signalFilter,columnExpandMode,qualifiedExpandName);this._indices=new Map;for(let i=0,c=this._columns.length;i<c;++i){this._indices.set(this._columns[i],i+1)}this._colsize=this._columns.length+1}read(){if(this._series==null||this._series.length==0){return[]}let hasComplexType=false;if(this._columnExpandMode!=DExpand.NONE){for(let column in this._series){let serie=this._series[column];let fm=serie.buckets()[0].getFormula();if(fm instanceof VDataFormulaArray||fm instanceof VDataFormulaStruct){hasComplexType=true;break}}}let rawobjs=hasComplexType?this.__readComplexRawObjects():this.__readSimpleRawObjects();let objs=[];for(let rowobj of rawobjs){if(rowobj!=null){for(let row of rowobj){objs.push(row.toObjects())}}}return objs}__readComplexRawObjects(){let rows=this._endTime-this._startTime+1;let rawobjs=new Array(rows);let list=null;let vals=null;let decoders;let serie;let pval;let pname;let time;let colidx,rowidx;let millis;let subNames;let subIndices;let comps=new Array(2);let noSubNames;for(pname in this._series){serie=this._series[pname];colidx=this._indices.get(pname);decoders=VDataSeriesDecodeBuilder.builds(serie.buckets());subNames=decoders[0].getSubNames();noSubNames=subNames==null||subNames.length==0;subIndices=null;if(!noSubNames&&this._columnExpandMode!=DExpand.NONE){subIndices=new Array(subNames.length);for(let i=0,s=subNames.length;i<s;++i){let subName=this._qualifiedExpandName?pname+"."+subNames[i]:subNames[i];subIndices[i]=this._indices.get(subName)}}for(let decoder of decoders){let qstime=decoder.getQueryStartTime();let qetime=decoder.getQueryEndTime();let qenzero=qetime!=0;do{millis=decoder.timestamp();if(millis<qstime||qenzero&&millis>qetime){decoder.pollAndAdd();continue}time=decoder.time();rowidx=millis-this._startTime;if(rawobjs[rowidx]==null){list=new Array;vals=this.createValueArray(time);list.push(vals);rawobjs[rowidx]=list}else{list=rawobjs[rowidx];this.comp(list,time,colidx,subNames,subIndices,comps);if(comps[1]==1){vals=list[comps[0]]}else{vals=this.createValueArray(time);list.splice(comps[0],0,vals)}}pval=decoder.value();if(noSubNames){vals.add(colidx,pval)}else{let subValues=pval;for(let i=0,s=subNames.length;i<s;++i){if(subIndices[i]!=null){vals.add(subIndices[i],subValues[i])}}}decoder.pollAndAdd()}while(!decoder.isEmpty())}}return rawobjs}__readSimpleRawObjects(){let rows=this._endTime-this._startTime+1;let rawobjs=new Array(rows);let list=null;let vals=null;let decoders;let serie;let pname;let time;let colidx,rowidx;let millis;let comps=new Array(2);for(pname in this._series){serie=this._series[pname];colidx=this._indices.get(pname);decoders=VDataSeriesDecodeBuilder.builds(serie.buckets());for(let decoder of decoders){let qstime=decoder.getQueryStartTime();let qetime=decoder.getQueryEndTime();let qenzero=qetime!=0;do{millis=decoder.timestamp();if(millis<qstime||qenzero&&millis>qetime){decoder.pollAndAdd();continue}time=decoder.time();rowidx=millis-this._startTime;if(rawobjs[rowidx]==null){list=new Array;vals=this.createValueArray(time);list.push(vals);rawobjs[rowidx]=list}else{list=rawobjs[rowidx];this.comp(list,time,colidx,null,null,comps);if(comps[1]==1){vals=list[comps[0]]}else{vals=this.createValueArray(time);list.splice(comps[0],0,vals)}}vals.add(colidx,decoder.value());decoder.pollAndAdd()}while(!decoder.isEmpty())}}return rawobjs}sampling(frequency){if(this._series==null||this._series.length==0){return new Array}let hasComplexType=false;if(this._columnExpandMode!=DExpand.NONE){for(let column in this._series){let serie=this._series[column];let fm=serie.buckets()[0].getFormula();if(fm instanceof VDataFormulaArray||fm instanceof VDataFormulaStruct){hasComplexType=true;break}}}let objs=hasComplexType?this.__samplingComplex(frequency):this.__samplingSimple(frequency);let nonEmptyIndex=objs.length-1;w:while(nonEmptyIndex>=0){let row=objs[nonEmptyIndex];for(let i=1,s=row.length;i<s;++i){if(row[i]!=null){break w}}nonEmptyIndex--}if(nonEmptyIndex==objs.length-1){return objs}else if(nonEmptyIndex<0){return new Array}else{return objs.slice(0,nonEmptyIndex+1)}}__samplingComplex(frequency){let startFreqBase=Math.floor(this._startTime/frequency);let rows=Math.floor(this._endTime/frequency)-startFreqBase+1;let rawobjs=new Array(rows);for(let i=0;i<rows;++i){rawobjs[i]=new Array(this._colsize);rawobjs[i][0]=(startFreqBase+i)*frequency}let serie;let decoders;let colidx;let rowidx=0;let lastrowidx=-1;let pname;let subNames;let subIndices;let noSubNames;for(pname in this._series){lastrowidx=-1;serie=this._series[pname];colidx=this._indices.get(serie.name());decoders=VDataSeriesDecodeBuilder.builds(serie.buckets());subNames=decoders[0].getSubNames();noSubNames=subNames==null||subNames.length==0;subIndices=null;if(!noSubNames&&this._columnExpandMode!=DExpand.NONE){subIndices=new Array(subNames.length);for(let i=0,s=subNames.length;i<s;++i){let subName=this._qualifiedExpandName?pname+"."+subNames[i]:subNames[i];subIndices[i]=this._indices.get(subName)}}for(let decoder of decoders){do{rowidx=Math.floor(decoder.timestamp()/frequency)-startFreqBase;if(rowidx!=lastrowidx&&rowidx>=0&&rowidx<rows){lastrowidx=rowidx;if(noSubNames){if(rawobjs[rowidx][colidx]==null){rawobjs[rowidx][colidx]=decoder.value()}}else{let subValues=decoder.value();for(let i=0,s=subNames.length;i<s;++i){if(subIndices[i]!=null&&rawobjs[rowidx][subIndices[i]]==null){rawobjs[rowidx][subIndices[i]]=subValues[i]}}}}decoder.pollAndAdd()}while(!decoder.isEmpty())}}return rawobjs}__samplingSimple(frequency){let startFreqBase=Math.floor(this._startTime/frequency);let rows=Math.floor(this._endTime/frequency)-startFreqBase+1;let rawobjs=new Array(rows);for(let i=0;i<rows;++i){rawobjs[i]=new Array(this._colsize);rawobjs[i][0]=(startFreqBase+i)*frequency}let pname;let serie;let decoders;let colidx;let rowidx=0;let lastrowidx=-1;for(pname in this._series){lastrowidx=-1;serie=this._series[pname];colidx=this._indices.get(serie.name());decoders=VDataSeriesDecodeBuilder.builds(serie.buckets());for(let decoder of decoders){do{rowidx=Math.floor(decoder.timestamp()/frequency)-startFreqBase;if(rowidx!=lastrowidx&&rowidx>=0&&rowidx<rows){lastrowidx=rowidx;if(rawobjs[rowidx][colidx]==null){rawobjs[rowidx][colidx]=decoder.value()}}decoder.pollAndAdd()}while(!decoder.isEmpty())}}return rawobjs}createValueArray(time){return new VDataDenseArray(time,this._colsize)}comp(arrs,time,colidx,subNames,subIndices,result){VDataObjectsUtils.compareUniqueMode(arrs,time,result)}}class VDataObjectsSeriesFirstMode extends VDataObjectsSeriesReader{constructor(series,signalFilter,columnExpandMode,qualifiedExpandName,startTime,endTime){super(series,signalFilter,columnExpandMode,qualifiedExpandName,startTime,endTime)}createValueArray(time){return new VDataDenseArrayFirstMode(time,this._colsize)}}class VDataObjectsSeriesAllMode extends VDataObjectsSeriesReader{constructor(series,signalFilter,columnExpandMode,qualifiedExpandName,startTime,endTime){super(series,signalFilter,columnExpandMode,qualifiedExpandName,startTime,endTime)}createValueArray(time){return new VDataDenseArray(time,this._colsize)}comp(arrs,time,colidx,subNames,subIndices,result){VDataObjectsUtils.compareAllMode(arrs,time,this._columnExpandMode,colidx,subNames,subIndices,result)}}class VDataObjectsUtils{static compareUniqueMode(arrs,time,result){let size=arrs.length;let subtime=0;let comp=0;result[0]=result[1]=0;let low=0;let high=size-1;let mid=0;do{mid=Math.floor((low+high)/2);subtime=arrs[mid].getTime();comp=time-subtime;if(comp==0){result[0]=mid;result[1]=1;return}else if(comp<0){high=mid-1}else{low=mid+1}}while(high>low);if(high==low){subtime=arrs[low].getTime();comp=time-subtime;if(comp==0){result[0]=low;result[1]=1}else if(comp<0){result[0]=low}else{result[0]=low+1}}else if(comp<0){result[0]=mid}else{result[0]=mid+1}}static compareAllMode(arrs,time,expand,colidx,subNames,subIndices,result){let size=arrs.length;let subtime=0;let comp=0;result[0]=result[1]=0;let low=0;let high=size-1;let mid=0;do{mid=Math.floor((low+high)/2);subtime=arrs[mid].getTime();comp=time-subtime;if(comp==0){let vals=arrs[mid];if(VDataObjectsUtils.isEmptyAt(vals,expand,colidx,subNames,subIndices)){while(mid-1>=0){vals=arrs[mid-1];if(time!=vals.getTime()){break}if(!VDataObjectsUtils.isEmptyAt(vals,expand,colidx,subNames,subIndices)){break}mid--}result[0]=mid;result[1]=1;return}else{while(mid+1<size){vals=arrs[mid+1];if(time!=vals.getTime()){result[0]=mid+1;return}if(VDataObjectsUtils.isEmptyAt(vals,expand,colidx,subNames,subIndices)){result[0]=mid+1;result[1]=1;return}mid++}result[0]=mid+1;return}}else if(comp<0){high=mid-1}else{low=mid+1}}while(high>low);if(high==low){subtime=arrs[low].getTime();comp=time-subtime;if(comp==0){let vals=arrs[low];if(VDataObjectsUtils.isEmptyAt(vals,expand,colidx,subNames,subIndices)){while(low-1>=0&&time==arrs[low-1].getTime()){low--}result[0]=low;result[1]=1;return}else{while(low+1<size){if(time!=arrs[low+1].getTime()){result[0]=low+1;return}if(VDataObjectsUtils.isEmptyAt(arrs[low+1],expand,colidx,subNames,subIndices)){result[0]=low+1;result[1]=1;return}low++}result[0]=low+1}}else if(comp<0){result[0]=low}else{result[0]=low+1}}else if(comp<0){result[0]=mid}else{result[0]=mid+1}}static isEmptyAt(vals,expand,colidx,subNames,subIndices){if(subNames==null||expand==DExpand.NONE){return vals.isEmptyAt(colidx)}else{for(let i=0,s=subNames.length;i<s;++i){if(subIndices[i]!=null){if(!vals.isEmptyAt(subIndices[i])){return false}}}}return true}}class VDataReaderFactory{constructor(){this._readers=null;this._signals=null;this._insensitiveCase=false;this._readLivingData=true;this._queryFilter=true;this._queryStartTime=0;this._queryEndTime=0;this._columnExpandMode=null;this._signalQueueMode=null;this._signalDecoders=null}setDataReaders(readers){this._readers=readers}setSignals(signals){this._signals=signals}setInsensitiveCase(insensitiveCase){this._insensitiveCase=insensitiveCase}setReadLivingData(readLiving){this._readLivingData=readLiving}setQueryFilter(filter){this._queryFilter=filter}setQueryStartTime(time){this._queryStartTime=time}setQueryEndTime(time){this._queryEndTime=time}setColumnExpandMode(mode){this._columnExpandMode=mode}setSignalQueueMode(mode){this._signalQueueMode=mode}setSignalDeocders(signalDecoders){this._signalDecoders=signalDecoders}open(){return new VDataReader(this._readers,this._signals,this._insensitiveCase,this._queryFilter,this._queryStartTime,this._queryEndTime,this._readLivingData,this._columnExpandMode,this._signalQueueMode,this._signalDecoders)}}class VDataReader{constructor(readers,signals=null,insensitiveCase=false,queryFilter=true,queryStartTime=0,queryEndTime=0,readLivingData=true,columnExpandMode=null,signalQueueMode=null,signalDecoders=null){const signalFilter=this.filterSignals(signals);const ndecoders=Array.isArray(readers)?readers.length:1;this._readers=Array.isArray(readers)?readers:[readers];this._columnExpandMode=VDataUtils.getColumnExpandMode(columnExpandMode);this._signalQueueMode=VDataUtils.getSignalQueueMode(signalQueueMode);this._frame=null;this._decoders=[];this._livingDataBuffer=1e3;let buckets=[];this._signalDecoders=signalDecoders;let livingData=readLivingData;if(readLivingData){if(ndecoders>1&&VDataUtils.isAllSignalQueueMode(this._signalQueueMode)){livingData=false}}for(let i=0;i<ndecoders;++i){let reader=this._readers[i];let meta=VDataReader.getMeta(reader);let decoder=new VDataDecoder(reader,meta);decoder.setSignalFilter(signalFilter);decoder.setInsensitiveCase(insensitiveCase);decoder.setReadLivingData(livingData);decoder.setQueryFilter(queryFilter);decoder.setQueryRange(queryStartTime,queryEndTime);decoder.setColumnExpandMode(this._columnExpandMode);decoder.setSignalQueueMode(this._signalQueueMode);decoder.setSignalDeocders(this._signalDecoders);decoder.initialize();VDataDecodeUtils.sortAddDecoder(this._decoders,decoder)}let series={};if(ndecoders>1){console.log("Sort and Add buckets for "+String(ndecoders)+" files")}for(let i=0;i<ndecoders;++i){let decoder=this._decoders[i];for(const bucket of decoder.buckets()){VDataBucketUtils.sortAddBucket(buckets,bucket,true,this._signalQueueMode)}for(const[name,_]of Object.entries(decoder.keys())){if(name in series==false){series[name]=new VDataSeries(name)}}}for(let b=0;b<buckets.length;++b){let bucket=buckets[b];for(let j=0;j<bucket.seriesBuckets.length;++j){let seriesBucket=bucket.seriesBuckets[j];let serie=series[seriesBucket.name];serie.addBucket(seriesBucket);serie.updateBucketItemCounts(b,seriesBucket.getItemCount())}}this._frame=new VDataFrame(buckets,series,signalFilter,this._columnExpandMode,this._signalQueueMode);let objectStartTime=queryFilter?queryStartTime:0;let objectEndTime=queryFilter?queryEndTime:0;for(let decoder of this._decoders){if(queryStartTime==0){let meta=decoder.meta();let st=meta.queryStartTime()==0?meta.storageStartTime():meta.queryStartTime();if(decoder.buckets().length>0){let bucketst=decoder.buckets()[0].getStartTime();if(bucketst>0&&bucketst>st){st=bucketst}}objectStartTime=objectStartTime==0?st:Math.min(objectStartTime,st)}if(queryEndTime==0){let meta=decoder.meta();let et=meta.queryEndTime()==0?meta.storageEndTime():meta.queryEndTime();objectEndTime=objectEndTime==0?et:Math.max(objectEndTime,et);if(meta.queryEndTime()==0){let dbuckets=decoder.buckets();if(dbuckets.length>0&&dbuckets[dbuckets.length-1].isLiving()){objectEndTime=objectEndTime+this._livingDataBuffer}}}}this._frame.setStartTime(objectStartTime);this._frame.setEndTime(objectEndTime)}filterSignals(signals){let signalFilter=new VDataSignalFilter;if(signals==null||signals.length==0){return signalFilter}if(typeof signals==="string"){signals=signals.split(",")}let fsignals=[];let fprefixes=[];for(const s of signals){if(s==null){continue}let name=s.trim();if(name.length==0){continue}if(name[name.length-1]=="*"){do{name=name.substring(0,name.length-1)}while(name.length>0&&name[name.length-1]=="*");if(name.length==0){return signalFilter}fprefixes.push(name)}else{fsignals.push(name)}}signalFilter.setSignals(fsignals);signalFilter.setPrefixes(fprefixes);return signalFilter}static readInt8(_bytes){return new DataView(new Uint8Array(_bytes).buffer).getUint8(0)}static readUint16(_bytes){return new DataView(new Uint8Array(_bytes).buffer).getUint16(0,true)}static readInt32(_bytes){return new DataView(new Uint8Array(_bytes).buffer).getInt32(0,true)}static readUInt32(_bytes){return new DataView(new Uint8Array(_bytes).buffer).getUint32(0,true)}static readLong(_bytes){return Number(new DataView(new Uint8Array(_bytes).buffer).getBigInt64(0,true))}static readInt64(_bytes){return new DataView(new Uint8Array(_bytes).buffer).getBigInt64(0,true)}df(){return this._frame}static getMeta(_reader){if((new TextDecoder).decode(_reader.read(2))!="SD"){throw"FORMAT_VDATA_MAGIC_NUMBER_INVALID"}const formatFlags=VDataReader.readInt8(_reader.read(1));const compressMethod=formatFlags&15;const encryptMethod=formatFlags>>4&15;const formatVersion=VDataReader.readInt8(_reader.read(1));const blocksCount=VDataReader.readInt32(_reader.read(4));if(blocksCount<=0){throw"FORMAT_VDATA_BLOCKS_COUNT_INVALID"}let sstime=0;let setime=0;let qstime=0;let qetime=0;let extlength=0;let pageSizeCode=0;let keyTypeCode=0;let flag=0;if(formatVersion>0){if(formatVersion<26){sstime=VDataReader.readLong(_reader.read(8));setime=VDataReader.readLong(_reader.read(8))}else{sstime=VDataReader.readLong(_reader.read(8));setime=VDataReader.readLong(_reader.read(8));qstime=VDataReader.readLong(_reader.read(8));qetime=VDataReader.readLong(_reader.read(8))}extlength=VDataReader.readUint16(_reader.read(2));if(formatVersion>26){pageSizeCode=_reader.read(1)[0]&255;keyTypeCode=_reader.read(1)[0]&255;flag=VDataReader.readUInt32(_reader.read(4))}else{_reader.read(6)}}const extbytes=extlength>0?_reader.read(extlength):new Uint8Array(0);return new VDataMeta(formatVersion,compressMethod,encryptMethod,blocksCount,sstime,setime,qstime,qetime,extbytes,pageSizeCode,keyTypeCode,flag)}}module.exports={VDataByteReader:VDataByteReader,VDataReader:VDataReader,VDataReaderFactory:VDataReaderFactory,VDataFrame:VDataFrame,VDataMeta:VDataMeta,DExpand:DExpand,VDataSignalDecoder:VDataSignalDecoder};
|
|
20
|
+
const pako=require("pako");const fzstd=require("fzstd");class VDataRow{constructor(time,values){this._time=time;this._values=values}get[Symbol.toStringTag](){return"{time="+String(this._time)+", values="+String(this._values)+"}"}time(){return this._time}values(){return this._values}}class VDataRecord{constructor(time,values){this._time=time;this._values=values}get[Symbol.toStringTag](){return"{time="+String(this._time)+", values="+String(this._values)+"}"}time(){return this._time}values(){return this._values}}class VDataSeriesPair{constructor(time,value){this._time=time;this._value=value}get[Symbol.toStringTag](){return"{time="+String(this._time)+", value="+String(this._value)+"}"}time(){return this._time}value(){return this._value}}class VDataByteReader{constructor(_uint8array){this._data=_uint8array;this._length=this._data.length;this._pos=0}read(length){let _end=this._pos+length;if(_end>=this._length){_end=this._length}const _bb=this._data.slice(this._pos,_end);this._pos=_end;return _bb}seek(pos){if(pos>0){if(pos>=this._length){this._pos=this._length}else{this._pos=pos}}else{this._pos=0}}skip(length){if(length>0){let pos=this._pos+length;if(pos>=this._length){this._pos=this._length}else{this._pos=pos}}}close(){}}class VDataMeta{constructor(formatVersion=0,compressMethod=0,encryptMethod=0,blocksCount=0,storageStartTime=0,storageEndTime=0,queryStartTime=0,queryEndTime=0,extendedInfo=new Uint8Array(0),pageSizeCode=0,keyTypeCode=0,flag=0){this._formatVersion=formatVersion;this._compressMethod=compressMethod;this._encryptMethod=encryptMethod;this._blocksCount=blocksCount;this._storageStartTime=storageStartTime;this._storageEndTime=storageEndTime;this._queryStartTime=queryStartTime;this._queryEndTime=queryEndTime;this._extendedInfo=extendedInfo;this._pageSizeCode=pageSizeCode;this._keyTypeCode=keyTypeCode;this._flag=flag}formatVersion(){return this._formatVersion}compressMethod(){return this._compressMethod}encryptMethod(){return this._encryptMethod}blocksCount(){return this._blocksCount}storageStartTime(){return this._storageStartTime}storageEndTime(){return this._storageEndTime}queryStartTime(){return this._queryStartTime}queryEndTime(){return this._queryEndTime}extendedInfo(){return this._extendedInfo}pageSize(){var pageSizeCode=this._pageSizeCode&15;switch(pageSizeCode){case 1:return 32768;case 2:return 16384;case 3:return 8192;case 4:return 131072;default:return 65536}}storageIdLength(){var storageIdLengthCode=(this._pageSizeCode&240)>>4;var pageSizeCode=this._pageSizeCode&15;if(pageSizeCode!=1){return 8}switch(storageIdLengthCode){case 1:return 6;default:return 5}}seriesTimestampLength(){var tsLengthCode=this._keyTypeCode&15;switch(tsLengthCode){case 1:return(this._keyTypeCode>>4&15)==0&&this._flag==0?43:41;default:return 41}}}class VDataBucket{constructor(){this.startTime=0;this.endTime=0;this.living=0;this.notime=0;this.cycle=0;this.crc=0;this.seriesBuckets=[]}get[Symbol.toStringTag](){return"{cycle="+String(this.cycle)+", start="+String(this.startTime)+", end="+String(this.endTime)+", living="+String(this.living)+", notime="+String(this.notime)+"}"}getStartTime(){return this.startTime}setStartTime(time){let t=String(time);if(t.length>13){this.startTime=Math.floor(time/Math.round(Math.pow(10,t.length-13)))}else{this.startTime=time}}getEndTime(){return this.endTime}setEndTime(time){let t=String(time);if(t.length>13){this.endTime=Math.floor(time/Math.round(Math.pow(10,t.length-13)))}else{this.endTime=time}}getCycle(){return this.cycle}setCycle(cycle){this.cycle=cycle}isLiving(){return this.living}setLiving(living){this.living=living}getCrc(){return this.crc}setCrc(crc){this.crc=crc}setNotime(notime){this.notime=notime}getSeriesBuckets(){return this.seriesBuckets}addSeriesBucket(seriesBucket){this.seriesBuckets.push(seriesBucket)}intersects(b){let st=b.startTime;let et=b.endTime;if(this.startTime==0||st==0){return false}if(this.endTime==0||et==0){return this.startTime==st}return this.startTime>=st&&this.startTime<=et||this.endTime>=st&&this.endTime<=et||st>=this.startTime&&st<=this.endTime||et>=this.startTime&&et<=this.endTime}merge(b){if(b.seriesBuckets.length>0){let sset=new Set;for(let i=0;i<this.seriesBuckets.length;i++){sset.add(this.seriesBuckets[i].name)}for(let i=0;i<b.seriesBuckets.length;i++){if(!sset.has(b.seriesBuckets[i].name)){this.seriesBuckets.push(b.seriesBuckets[i])}}}return this}}class VDataFormulaNone{constructor(name){this._name=name}name(){return this._name}apply(val){return val}}class VDataFormulaBlob{constructor(name){this._name=name;this._signalDecoder=undefined}name(){return this._name}setSignalDeocder(signalDecoder){this._signalDecoder=signalDecoder}apply(val){if(this._signalDecoder){return this._signalDecoder.decode(val)}else{return val}}}class VDataSignalDecoder{decode(data){return data}getSubNames(){return""}getSubValues(object){return object}}class VDataFormulaLinear{constructor(name,factor,offset){this._name=name;this._factor=factor;this._offset=offset}name(){return this._name}apply(val){return this._factor*val+this._offset}}class VDataFormulaPolynomial{constructor(name,p0,p1,p2,p3,p4,p5){this._name=name;this._p0=p0;this._p1=p1;this._p2=p2;this._p3=p3;this._p4=p4;this._p5=p5}name(){return this._name}apply(val){let numer=this._p1-this._p3*(val-this._p4-this._p5);let denom=this._p2*(val-this._p4-this._p5)-this._p0;let result=numer/denom;return Number.isFinite(result)?result:NaN}}class VDataFormulaExponential{constructor(name,p0,p1,p2,p3,p4,p5,p6){this._name=name;this._p0=p0;this._p1=p1;this._p2=p2;this._p3=p3;this._p4=p4;this._p5=p5;this._p6=p6;this._p3zero=this._p3==0;this._p0zero=this._p0==0;if(this._p3zero){if(this._p0zero){throw"FORMAT_VDATA_FORMULA_EXPONENTIAL_P3_P0_BOTH_ZERO"}if(this._p1==0){throw"FORMAT_VDATA_FORMULA_EXPONENTIAL_P3_P1_BOTH_ZERO"}}if(this._p0zero&&this._p4==0){throw"FORMAT_VDATA_FORMULA_EXPONENTIAL_P0_P4_BOTH_ZERO"}}name(){return this._name}apply(val){if(this._p3zero){let result=Math.log(((val-this._p6)*this._p5-this._p2)/this._p0)/this._p1;return Number.isFinite(result)?result:NaN}if(this._p0zero){let denom=val-this._p6;let result=this._p2/denom;if(!Number.isFinite(result)){return NaN}result=Math.log((result-this._p5)/this._p3)/this._p4;return Number.isFinite(result)?result:NaN}return NaN}}class VDataFormulaLogarithmic{constructor(name,p0,p1,p2,p3,p4,p5,p6){this._name=name;this._p0=p0;this._p1=p1;this._p2=p2;this._p3=p3;this._p4=p4;this._p5=p5;this._p6=p6;this._p3zero=this._p3==0;this._p0zero=this._p0==0;if(this._p3zero){if(this._p0zero){throw"FORMAT_VDATA_FORMULA_EXPONENTIAL_P3_P0_BOTH_ZERO"}if(this._p1==0){throw"FORMAT_VDATA_FORMULA_EXPONENTIAL_P3_P1_BOTH_ZERO"}}if(this._p0zero&&this._p4==0){throw"FORMAT_VDATA_FORMULA_EXPONENTIAL_P0_P4_BOTH_ZERO"}}name(){return this._name}apply(val){if(this._p3zero){let result=Math.exp(((val-this._p6)*this._p5-this._p2)/this._p0)/this._p1;return Number.isFinite(result)?result:NaN}if(this._p0zero){let denom=val-this._p6;let result=this._p2/denom;if(!Number.isFinite(result)){return NaN}result=Math.exp((result-this._p5)/this._p3)/this._p4;return Number.isFinite(result)?result:NaN}return NaN}}class VDataFormulaRational{constructor(name,p0,p1,p2,p3,p4,p5){this._name=name;this._p0=p0;this._p1=p1;this._p2=p2;this._p3=p3;this._p4=p4;this._p5=p5}name(){return this._name}apply(val){let numer=val*val*this._p0+val*this._p1+this._p2;let denom=val*val*this._p3+val*this._p4+this._p5;let result=numer/denom;return Number.isFinite(result)?result:NaN}}class VDataFormulaDecode{constructor(name,_list){this._name=name;if(_list==null||Array.isArray(_list)==false||_list.length==0){throw"FORMAT_VDATA_FORMULA_DECODE_LIST_EMPTY"}if(_list.length%2!=0){throw"FORMAT_VDATA_FORMULA_DECODE_LIST_ODD_SIZE"}this._list=_list;this._lsize=Math.floor(this._list.length/2)}name(){return this._name}apply(val){let x=this._list[0];let y=this._list[1];let compare=x-val;if(compare>=0){return y}for(let i=0;i<this._lsize;i++){compare=this._list[2*i]-val;if(compare<0){x=this._list[2*i];y=this._list[2*i+1]}else if(compare==0){return this._list[2*i+1]}else{if(this._list[2*i]-val-(val-x)>=0){return y}else{return this._list[2*i+1]}}}return this._list[2*this._lsize-1]}}class VDataFormulaInterpolate{constructor(name,_list){this._name=name;if(_list==null||Array.isArray(_list)==false||_list.length==0){throw"FORMAT_VDATA_FORMULA_INTERPOLATE_LIST_EMPTY"}if(_list.length%2!=0){throw"FORMAT_VDATA_FORMULA_INTERPOLATE_LIST_ODD_SIZE"}this._list=_list;this._lsize=Math.floor(this._list.length/2)}name(){return this._name}apply(val){let x1=this._list[0];let y1=this._list[1];let x2=0;let y2=0;let a=0;let compare=x1-val;if(compare>0){x2=this._list[2];y2=this._list[3];a=(y2-y1)/(x2-x1);if(!Number.isFinite(a)){return NaN}return y1+a*(val-x1)}else if(compare==0){return y1}for(let i=0;i<this._lsize-1;i++){x1=this._list[2*i];y1=this._list[2*i+1];compare=x1-val;if(compare>0){x2=this._list[2*i+2];y2=this._list[2*i+3];a=(y2-y1)/(x2-x1);if(!Number.isFinite(a)){return NaN}return y1+a*(val-x1)}else if(compare==0){return y1}}x2=this._list[2*this._lsize-2];y2=this._list[2*this._lsize-1];compare=x2-val;if(compare==0){return y2}else{a=(y2-y1)/(x2-x1);if(!Number.isFinite(a)){return NaN}return y1+a*(val-x1)}}}class VDataFormulaArray{constructor(name,formulas){this._name=name;this._formulas=formulas}name(){return this._name}apply(val){let vals=[];if(!isNaN(val)){vals.push(val);return vals}for(let i=0,s=this._formulas.length;i<s;++i){vals.push(this._formulas[i].apply(val))}return vals}}class VDataFormulaNamedArray extends VDataFormulaArray{constructor(name,formulas){super(name,formulas)}}class VDataFormulaStruct{constructor(name,formulas){this._name=name;this._formulas=formulas}name(){return this._name}apply(val){let vals=new Map;for(let i=0,s=this._formulas.length;i<s;++i){vals.set(this._formulas[i]._name,this._formulas[i].apply(val))}return vals}}class VDataFormulaFactory{build(desc,insensitiveCase=false){if(desc.length==0){throw"FORMAT_VDATA_KEY_DESC_EMPTY"}let idx=desc.indexOf("|");if(idx==0){throw"FORMAT_VDATA_KEY_DESC_INVALID: "+desc}else if(idx<0){let name=insensitiveCase?desc.trim().toLowerCase():desc.trim();return new VDataFormulaNone(name)}let name=desc.substring(0,idx).trim();if(name.length==0){throw"FORMAT_VDATA_KEY_DESC_INVALID: "+desc}if(insensitiveCase){name=name.toLowerCase()}let formula=desc.substring(idx+1).trim();if(formula.length==0){return new VDataFormulaNone(name)}let code=formula;idx=formula.indexOf(":");if(idx==0){throw"FORMAT_VDATA_KEY_DESC_INVALID: "+desc}else if(idx>0){code=formula.substring(0,idx)}if("8"==code){if(idx<0){return this.buildArrayFormula(name,"",insensitiveCase)}else if(idx>0){formula=formula.substring(idx+1).trim();if(formula.length==0){return this.buildArrayFormula(name,"",insensitiveCase)}}if(formula[0]!="["||formula[formula.length-1]!="]"){throw"FORMAT_VDATA_KEY_DESC_INVALID_ARRAY: "+desc}formula=formula.substring(1,formula.length-1).trim();if(formula.length==0){throw"FORMAT_VDATA_KEY_DESC_INVALID_ARRAY: "+desc}return this.buildArrayFormula(name,formula,insensitiveCase)}if("9"==code){if(idx<0){throw"FORMAT_VDATA_KEY_DESC_INVALID_STRUCT: "+desc}else if(idx>0){formula=formula.substring(idx+1).trim();if(formula.length==0){throw"FORMAT_VDATA_KEY_DESC_INVALID_STRUCT: "+desc}}if(formula[0]!="{"||formula[formula.length-1]!="}"){throw"FORMAT_VDATA_KEY_DESC_INVALID_STRUCT: "+desc}formula=formula.substring(1,formula.length-1).trim();if(formula.length==0){throw"FORMAT_VDATA_KEY_DESC_INVALID_STRUCT: "+desc}return this.buildStructFormula(name,formula,insensitiveCase)}return this.buildSimpleFormula(name,formula)}buildArrayFormula(name,formula,insensitiveCase=false){let descs=formula.split(",");let formulas=[];let namedArray=false;let names=new Set;for(let i=0,s=descs.length;i<s;++i){let desc=descs[i].trim();if(desc.length==0){if(namedArray&&i!=0){throw"FORMAT_VDATA_KEY_DESC_ARRAY_MIXED_NAMES_NOT_ALLOWED: "+name}formulas.push(new VDataFormulaNone(name));continue}let idx=desc.indexOf("|");if(idx<0){if(desc.indexOf(":")<0&&"0"!=desc){if(!namedArray&&i!=0){throw"FORMAT_VDATA_KEY_DESC_ARRAY_MIXED_NAMES_NOT_ALLOWED: "+name}if(insensitiveCase){desc=desc.toLowerCase()}if(names.has(desc)){throw"FORMAT_VDATA_KEY_DESC_ARRAY_DUPLICATE_NAMES_NOT_ALLOWED: "+name+" - "+desc}formulas.push(new VDataFormulaNone(desc));names.add(desc);namedArray=true}else{if(namedArray&&i!=0){throw"FORMAT_VDATA_KEY_DESC_ARRAY_MIXED_NAMES_NOT_ALLOWED: "+name+" - "+desc}formulas.push(this.buildSimpleFormula(name,desc))}continue}if(idx==0){if(namedArray&&i!=0){throw"FORMAT_VDATA_KEY_DESC_ARRAY_MIXED_NAMES_NOT_ALLOWED: "+name}desc=desc.substring(1).trim();if(desc.length()==0){formulas.push(new VDataFormulaNone(name))}else{formulas.push(this.buildSimpleFormula(name,desc))}continue}let itemname=desc.substring(0,idx).trim();if(itemname.length==0){throw"FORMAT_VDATA_KEY_DESC_INVALID_ARRAY_ITEM: "+name+" - "+desc}if(insensitiveCase){itemname=itemname.toLowerCase()}let itemformula=desc.substring(idx+1).trim();if(names.has(itemname)){throw"FORMAT_VDATA_KEY_DESC_ARRAY_DUPLICATE_NAMES_NOT_ALLOWED: "+name+" - "+itemname}else{names.add(itemname);namedArray=true}if(itemformula.length==0){formulas.push(new VDataFormulaNone(itemname))}else{formulas.push(this.buildSimpleFormula(itemname,itemformula))}}if(namedArray){return new VDataFormulaNamedArray(name,formulas)}else{return new VDataFormulaArray(name,formulas)}}buildStructFormula(name,formula,insensitiveCase=false){let descs=formula.split(",");let formulas=[];for(let i=0,s=descs.length;i<s;++i){let desc=descs[i].trim();let idx=desc.indexOf("|");if(idx==0){throw"FORMAT_VDATA_KEY_DESC_INVALID_STRUCT_ITEM: "+name}else if(idx<0){let itemname=insensitiveCase?desc.trim().toLowerCase():desc.trim();formulas.push(new VDataFormulaNone(itemname));continue}let itemname=desc.substring(0,idx).trim();if(itemname.length==0){throw"FORMAT_VDATA_KEY_DESC_INVALID_STRUCT_ITEM: "+name}if(insensitiveCase){itemname=itemname.toLowerCase()}let itemformula=desc.substring(idx+1).trim();if(itemformula.length==0){formulas.push(new VDataFormulaNone(itemname))}else{formulas.push(this.buildSimpleFormula(itemname,itemformula))}}return new VDataFormulaStruct(name,formulas)}buildSimpleFormula(fname,formula){let fitems=formula.split(/[:]/);let formulaType=fitems[0].trim();let flen=fitems.length;if("0"==formulaType){if(flen==1){return new VDataFormulaNone(fname)}throw"FORMAT_VDATA_KEY_DESC_INVALID: "+fname+"|"+formula}if("1"==formulaType){if(flen==3){let factor=parseFloat(fitems[1].trim());let offset=parseFloat(fitems[2].trim());if(Number.isInteger(factor)&&Math.floor(factor)==1&&Number.isInteger(offset)&&Math.floor(offset)==0){return new VDataFormulaNone(fname)}else{return new VDataFormulaLinear(fname,factor,offset)}}throw"FORMAT_VDATA_KEY_DESC_INVALID: "+fname+"|"+formula}if("2"==formulaType){if(flen==7){let p0=parseFloat(fitems[1].trim());let p1=parseFloat(fitems[2].trim());let p2=parseFloat(fitems[3].trim());let p3=parseFloat(fitems[4].trim());let p4=parseFloat(fitems[5].trim());let p5=parseFloat(fitems[6].trim());return new VDataFormulaPolynomial(fname,p0,p1,p2,p3,p4,p5)}throw"FORMAT_VDATA_KEY_DESC_INVALID: "+fname+"|"+formula}if("3"==formulaType){if(flen==8){let p0=parseFloat(fitems[1].trim());let p1=parseFloat(fitems[2].trim());let p2=parseFloat(fitems[3].trim());let p3=parseFloat(fitems[4].trim());let p4=parseFloat(fitems[5].trim());let p5=parseFloat(fitems[6].trim());let p6=parseFloat(fitems[7].trim());return new VDataFormulaExponential(fname,p0,p1,p2,p3,p4,p5,p6)}throw"FORMAT_VDATA_KEY_DESC_INVALID: "+fname+"|"+formula}if("4"==formulaType){if(flen==8){let p0=parseFloat(fitems[1].trim());let p1=parseFloat(fitems[2].trim());let p2=parseFloat(fitems[3].trim());let p3=parseFloat(fitems[4].trim());let p4=parseFloat(fitems[5].trim());let p5=parseFloat(fitems[6].trim());let p6=parseFloat(fitems[7].trim());return new VDataFormulaLogarithmic(fname,p0,p1,p2,p3,p4,p5,p6)}throw"FORMAT_VDATA_KEY_DESC_INVALID: "+fname+"|"+formula}if("5"==formulaType){if(flen==7){let p0=parseFloat(fitems[1].trim());let p1=parseFloat(fitems[2].trim());let p2=parseFloat(fitems[3].trim());let p3=parseFloat(fitems[4].trim());let p4=parseFloat(fitems[5].trim());let p5=parseFloat(fitems[6].trim());return new VDataFormulaRational(fname,p0,p1,p2,p3,p4,p5)}throw"FORMAT_VDATA_KEY_DESC_INVALID: "+fname+"|"+formula}if("6"==formulaType){if(flen>=3){let plist=[];for(let i=1;i<flen;i++){plist.push(parseFloat(fitems[i].trim()))}return new VDataFormulaDecode(fname,plist)}throw"FORMAT_VDATA_KEY_DESC_INVALID: "+fname+"|"+formula}if("7"==formulaType){if(flen>=5){let plist=[];for(let i=1;i<flen;i++){plist.push(parseFloat(fitems[i].trim()))}return new VDataFormulaInterpolate(fname,plist)}throw"FORMAT_VDATA_KEY_DESC_INVALID: "+fname+"|"+formula}if("11"==formulaType){return new VDataFormulaBlob(fname)}throw"FORMAT_VDATA_KEY_DESC_INVALID: "+fname+"|"+formula}}class VDataSeriesMeta{constructor(formula,storageid_high,storageid_low,pageSize,storageIdLength){this._name=formula.name();this._formula=formula;const _high=storageid_high;const _low=storageid_low;if(pageSize!=32768){this._pageIndex=_high>>16;this._pageOffset=_high&65535;this._dataLength=(_low>>31&1)!=0?(_low>>16&32767)+32768:_low>>16&32767;this._itemCount=(_low>>15&1)!=0?(_low&32767)+32768:_low&32767}else if(storageIdLength==5){this._pageIndex=_high>>3&31;this._pageOffset=(_low>>20&4095)+((_high&7)<<12);this._dataLength=_low>>9&2047;this._itemCount=_low&511}else{this._pageIndex=_high>>8&255;this._pageOffset=(_low>>25&127)+((_high&255)<<7);this._dataLength=_low>>10&32767;this._itemCount=_low&1023}}get[Symbol.toStringTag](){return"{name:"+String(this._name)+", items:"+String(this._itemCount)+", length:"+String(this._dataLength)+"}"}name(){return this._name}formula(){return this._formula}pageIndex(){return this._pageIndex}pageOffset(){return this._pageOffset}dataLength(){return this._dataLength}itemCount(){return this._itemCount}setItemCount(cnt){this._itemCount=cnt}}class BitTracker{constructor(){this._numBits=0}getNumBits(){return this._numBits}setNumBits(bits){this._numBits=bits}getByteIndex(){return this._numBits>>3}getNumBytes(){return(this._numBits&7)!=0?(this._numBits>>3)+1:this._numBits>>3}incrementBit(){this._numBits++}incrementBits(bits){this._numBits=this._numBits+bits}}const VDataConstants={PAGE_LENGTH:65536,BIT_MASKS:[-128,64,32,16,8,4,2,1],FIRST_BYTE_BIT_MASKS:[255,127,63,31,15,7,3,1],BIT_POWER2:[1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912,1073741824,2147483648],BIGINT_POWER2:[1n,2n,4n,8n,16n,32n,64n,128n,256n],TIMESTAMP_INIT_DELTA:60,TIMESTAMP_VALUE_ENCODING:[7,9,12,32],TIMESTAMP_FIRST_VALUE_BITS:41,MICROSECOND_BITS:10,XOR_LEADING_ZERO_LENGTH_BITS:5,XOR_BLOCK_SIZE_LENGTH_BITS:6,XOR_BLOCK_SIZE_ADJUSTMENTS:1,ENCODE_LEADING_BITS:[0,8,12,16,18,20,22,24],POLL_QUEUE_MIN_SIZE:10};const DType={Float64:0,String:1,Boolean:2,Int8:3,UInt8:4,Int16:5,Int32:6,Int64:7,Array:8,Struct:9,Float32:10,Blob:11,Uint64:12};const DEncoder={NONE:0,XOR:1,GZIP:2,DELTA:3,CHIMP:4,ERASURE:5,PLAIN:6};const DExpand={NONE:0,FLAT:1,FULL:2};class VDataUtils{static getColumnExpandMode(mode){if(mode!=null){let m=mode;if(typeof m=="string"){m=m.toLowerCase().trim();if(m=="none"){return DExpand.NONE}else if(m=="flat"){return DExpand.FLAT}else if(m=="full"){return DExpand.FULL}}m=parseInt(mode);if(Number.isInteger(m)){if(m==DExpand.NONE){return DExpand.NONE}else if(m==DExpand.FULL){return DExpand.FULL}}}return DExpand.FLAT}static getSignalQueueMode(mode){if(mode!=null){let m=String(mode).trim().toLowerCase();if(m=="first"){return"first"}if(m=="all"){return"all"}}return"last"}static isQualifiedExpandName(mode){return VDataUtils.getColumnExpandMode(mode)==DExpand.FULL}static isAllSignalQueueMode(mode){return"all"==VDataUtils.getSignalQueueMode(mode)}static insertion_order_set_list(names){if(names==null||names.length==0){return[]}let st=new Set(names);let ns=[];for(let nm of names){if(st.has(nm)){ns.push(nm);st.delete(nm)}}return ns}}class VDataDecodeUtils{static sortAddDecoder(decoders,decoder){let size=decoders.length;if(size==0){console.log("Add decoder "+String(decoder));decoders.push(decoder);return}let decoderStartTime=decoder._meta.storageStartTime();for(let i=size-1;i>=0;--i){let dc=decoders[i];let st=dc._meta.storageStartTime();if(st<=decoderStartTime){console.log("Add decoder "+String(decoder));decoders.splice(i+1,0,decoder);return}}console.log("Add decoder "+String(decoder));decoders.splice(0,0,decoder)}static readValueFromBitOne(page,bitpos){return(page[bitpos>>3]&VDataConstants.BIT_MASKS[bitpos&7])==0?0:1}static readValueFromBitString(page,bitsToRead,bitpos){let bitsEnd=bitpos+bitsToRead-1;let bitMaskFirstByte=bitpos&7;let bitsLastByte=(bitsEnd&7)+1;let byteFirst=bitpos>>3;let byteLast=bitsEnd>>3;let value=page[byteFirst]&255&VDataConstants.FIRST_BYTE_BIT_MASKS[bitMaskFirstByte];if(byteFirst==byteLast){value=value>>8-bitsLastByte}else{let bytepos=byteFirst+1;while(bytepos<byteLast){value=value*256+(page[bytepos++]&255)}value=value*VDataConstants.BIT_POWER2[bitsLastByte]+((page[byteLast]&255)>>8-bitsLastByte)}return value}static readBigIntFromBitString(page,bitsToRead,bitpos){if(bitsToRead<=32){return BigInt(this.readValueFromBitString(page,bitsToRead,bitpos))}let bitsEnd=bitpos+bitsToRead-1;let bitMaskFirstByte=bitpos&7;let bitsLastByte=(bitsEnd&7)+1;let byteFirst=bitpos>>3;let byteLast=bitsEnd>>3;let fbyte=page[byteFirst]&255&VDataConstants.FIRST_BYTE_BIT_MASKS[bitMaskFirstByte];let value;if(byteFirst==byteLast){value=BigInt(fbyte>>8-bitsLastByte)}else{value=BigInt(fbyte);let bytepos=byteFirst+1;while(bytepos<byteLast){value=value*256n+BigInt(page[bytepos++]&255)}value=value*VDataConstants.BIGINT_POWER2[bitsLastByte]+BigInt((page[byteLast]&255)>>8-bitsLastByte)}return value}static intBitsToFloat(bits){let sign=bits>>>31==0?1:-1;let e=bits>>>23&255;let m=e==0?(bits&8388607)<<1:bits&8388607|8388608;let f=sign*m*Math.pow(2,e-150);return f}static longBitsToDouble(bits){let _buf=new ArrayBuffer(8);let _view=new DataView(_buf);_view.setBigInt64(0,bits,false);return new DataView(_buf).getFloat64(0)}static longBitsToUint64(bits){let _buf=new ArrayBuffer(8);let _view=new DataView(_buf);_view.setBigUint64(0,bits,false);return new DataView(_buf).getBigInt64(0)}}class VDataFloat32NoneDecode{constructor(_page,_formula,_bitTracker){this.page=_page;this.bitTracker=_bitTracker;this.formula=_formula;this.hasFormula=_formula!=null&&!(_formula instanceof VDataFormulaNone);this.bitValue=0}first(){this.next()}next(){let bitpos=this.bitTracker.getNumBits();this.bitValue=VDataDecodeUtils.readValueFromBitString(this.page,32,bitpos);this.bitTracker.setNumBits(bitpos+32)}get(){return this.hasFormula?this.formula.apply(VDataDecodeUtils.intBitsToFloat(this.bitValue)):VDataDecodeUtils.intBitsToFloat(this.bitValue)}raw(){return VDataDecodeUtils.intBitsToFloat(this.bitValue)}bits(){return this.bitValue}}class VDataFloat64NoneDecode{constructor(_page,_formula,_bitTracker){this.page=_page;this.bitTracker=_bitTracker;this.formula=_formula;this.hasFormula=_formula!=null&&!(_formula instanceof VDataFormulaNone);this.bitValue=0n}first(){this.next()}next(){let bitpos=this.bitTracker.getNumBits();this.bitValue=VDataDecodeUtils.readBigIntFromBitString(this.page,64,bitpos);this.bitTracker.setNumBits(bitpos+64)}get(){return this.hasFormula?this.formula.apply(VDataDecodeUtils.longBitsToDouble(this.bitValue)):VDataDecodeUtils.longBitsToDouble(this.bitValue)}raw(){return VDataDecodeUtils.longBitsToDouble(this.bitValue)}bits(){return this.bitValue}}class VDataFloat64ChimpDecode{constructor(_page,_formula,_bitTracker){this.page=_page;this.bitTracker=_bitTracker;this.formula=_formula;this.hasFormula=_formula!=null&&!(_formula instanceof VDataFormulaNone);this.bitValue=0n;this.leadingZeros=0;this.trailingZeros=0;this.signalValue=0;this.updatedBits=false}first(){this.next()}next(){let bitpos=this.bitTracker.getNumBits();let xorValue=0n;if(VDataDecodeUtils.readValueFromBitOne(this.page,bitpos++)==0){if(VDataDecodeUtils.readValueFromBitOne(this.page,bitpos++)==0){this.bitTracker.setNumBits(bitpos);return}this.leadingZeros=VDataConstants.ENCODE_LEADING_BITS[VDataDecodeUtils.readValueFromBitString(this.page,3,bitpos)];bitpos=bitpos+3;let significantBits=VDataDecodeUtils.readValueFromBitString(this.page,6,bitpos);bitpos=bitpos+6;if(significantBits==0){significantBits=64}this.trailingZeros=64-significantBits-this.leadingZeros;xorValue=VDataDecodeUtils.readBigIntFromBitString(this.page,significantBits,bitpos);xorValue=xorValue*BigInt(Math.pow(2,this.trailingZeros));bitpos+=significantBits}else{if(VDataDecodeUtils.readValueFromBitOne(this.page,bitpos++)==0){let bits=64-this.leadingZeros;xorValue=VDataDecodeUtils.readBigIntFromBitString(this.page,bits,bitpos);bitpos=bitpos+bits}else{this.leadingZeros=VDataConstants.ENCODE_LEADING_BITS[VDataDecodeUtils.readValueFromBitString(this.page,3,bitpos)];bitpos=bitpos+3;let bits=64-this.leadingZeros;xorValue=VDataDecodeUtils.readBigIntFromBitString(this.page,bits,bitpos);bitpos=bitpos+bits}}this.bitValue=xorValue^this.bitValue;this.updatedBits=true;this.bitTracker.setNumBits(bitpos)}get(){return this.hasFormula?this.formula.apply(this.raw()):this.raw()}raw(){if(this.updatedBits){this.signalValue=VDataDecodeUtils.longBitsToDouble(this.bitValue);this.updatedBits=false}return this.signalValue}bits(){return this.bitValue}}class VDataFloat64ErasureDecode{static POWER_P10=Object.freeze([1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10]);static POWER_N10=Object.freeze([1,.1,.01,.001,1e-4,1e-5,1e-6,1e-7,1e-8,1e-9,1e-10]);static POWER_P20=Object.freeze([1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13,1e14,1e15,1e16,1e17,1e18,1e19,1e20]);static POWER_N20=Object.freeze([1,.1,.01,.001,1e-4,1e-5,1e-6,1e-7,1e-8,1e-9,1e-10,1e-11,1e-12,1e-13,1e-14,1e-15,1e-16,1e-17,1e-18,1e-19,1e-20]);constructor(_page,_formula,_bitTracker){this.page=_page;this.bitTracker=_bitTracker;this.formula=_formula;this.hasFormula=_formula!=null&&!(_formula instanceof VDataFormulaNone);this.bitValue=0n;this.signalValue=0;this.leadingZeros=0;this.trailingZeros=0;this.beta=Number.MAX_VALUE}first(){let bitpos=this.bitTracker.getNumBits()+2;this.trailingZeros=VDataDecodeUtils.readValueFromBitString(this.page,7,bitpos);bitpos=bitpos+7;if(this.trailingZeros<64){let bits=63-this.trailingZeros;let value=VDataDecodeUtils.readBigIntFromBitString(this.page,bits,bitpos);value=value*2n+1n;this.bitValue=value*BigInt(Math.pow(2,this.trailingZeros));bitpos=bitpos+bits}this.bitTracker.setNumBits(bitpos)}next(){let bitpos=this.bitTracker.getNumBits();if(VDataDecodeUtils.readValueFromBitOne(this.page,bitpos++)==0){this.bitTracker.setNumBits(bitpos);this.decodeToPower()}else if(VDataDecodeUtils.readValueFromBitOne(this.page,bitpos++)==0){this.bitTracker.setNumBits(bitpos);this.decodeBase()}else{this.beta=VDataDecodeUtils.readValueFromBitString(this.page,4,bitpos);this.bitTracker.setNumBits(bitpos+4);this.decodeToPower()}}decodeBase(){let bitpos=this.bitTracker.getNumBits();let bits=VDataDecodeUtils.readValueFromBitString(this.page,2,bitpos);bitpos=bitpos+2;if(bits!=1){let xorValue=0n;if(bits==0){let centerBits=64-this.leadingZeros-this.trailingZeros;xorValue=VDataDecodeUtils.readBigIntFromBitString(this.page,centerBits,bitpos);xorValue=xorValue*BigInt(Math.pow(2,this.trailingZeros));bitpos=bitpos+centerBits}else if(bits==2){let leadCenter=VDataDecodeUtils.readValueFromBitString(this.page,7,bitpos);bitpos=bitpos+7;this.leadingZeros=VDataConstants.ENCODE_LEADING_BITS[leadCenter>>>4];let centerBits=15&leadCenter;if(centerBits==0){centerBits=16}this.trailingZeros=64-this.leadingZeros-centerBits;xorValue=VDataDecodeUtils.readBigIntFromBitString(this.page,centerBits-1,bitpos);xorValue=xorValue*2n+1n;xorValue=xorValue*BigInt(Math.pow(2,this.trailingZeros));bitpos=bitpos+centerBits-1}else if(bits==3){let leadCenter=VDataDecodeUtils.readValueFromBitString(this.page,9,bitpos);bitpos=bitpos+9;this.leadingZeros=VDataConstants.ENCODE_LEADING_BITS[leadCenter>>>6];let centerBits=63&leadCenter;if(centerBits==0){centerBits=64}this.trailingZeros=64-this.leadingZeros-centerBits;xorValue=VDataDecodeUtils.readBigIntFromBitString(this.page,centerBits-1,bitpos);xorValue=xorValue*2n+1n;xorValue=xorValue*BigInt(Math.pow(2,this.trailingZeros));bitpos=bitpos+centerBits-1}this.bitValue=xorValue^this.bitValue}this.bitTracker.setNumBits(bitpos)}decodeToPower(){this.decodeBase();let base=VDataDecodeUtils.longBitsToDouble(this.bitValue);let power=this.getTensPower(Math.abs(base));let value=0;if(this.beta==0){value=this.toTenthPower(-power-1);if(base<0){value=-value}}else{let scale=this.beta-power-1;value=this.roundToDigits(base,scale)}this.signalValue=value}roundToDigits(value,digits=0){const multiplier=Math.pow(10,digits);return Math.round(value*multiplier)/multiplier}getTensPower(v){if(v>=1){for(let i=1,s=VDataFloat64ErasureDecode.POWER_P10.length;i<s;++i){if(v<VDataFloat64ErasureDecode.POWER_P10[i]){return i-1}}}else{for(let i=1,s=VDataFloat64ErasureDecode.POWER_N10.length;i<s;++i){if(v>=VDataFloat64ErasureDecode.POWER_N10[i]){return-i}}}return Math.floor(Math.log10(v))}toTenthPower(i){if(i>=VDataFloat64ErasureDecode.POWER_N20.length){return Math.pow(10,i)}else{return VDataFloat64ErasureDecode.POWER_N20[i]}}toTenPower(i){if(i>=VDataFloat64ErasureDecode.POWER_P20.length){return Math.round(Math.pow(10,i))}else{return VDataFloat64ErasureDecode.POWER_P20[i]}}get(){return this.hasFormula?this.formula.apply(this.signalValue):this.signalValue}raw(){return this.signalValue}bits(){return this.bitValue}}class VDataFloat64XorDecode{constructor(_page,_formula,_bitTracker){this.page=_page;this.bitTracker=_bitTracker;this.formula=_formula;this.hasFormula=_formula!=null&&!(_formula instanceof VDataFormulaNone);this.bitValue=0n;this.leadingZeros=0;this.trailingZeros=0;this.signalValue=0;this.updatedBits=false}first(){this.next()}next(){let bitpos=this.bitTracker.getNumBits();if((this.page[bitpos>>3]&VDataConstants.BIT_MASKS[bitpos++&7])!=0){let xorValue;if((this.page[bitpos>>3]&VDataConstants.BIT_MASKS[bitpos++&7])!=0){let bits=64-this.leadingZeros-this.trailingZeros;xorValue=VDataDecodeUtils.readBigIntFromBitString(this.page,bits,bitpos);xorValue=xorValue*BigInt(Math.pow(2,this.trailingZeros));bitpos=bitpos+bits}else{this.leadingZeros=VDataDecodeUtils.readValueFromBitString(this.page,VDataConstants.XOR_LEADING_ZERO_LENGTH_BITS,bitpos);bitpos=bitpos+VDataConstants.XOR_LEADING_ZERO_LENGTH_BITS;let blockSize=VDataDecodeUtils.readValueFromBitString(this.page,VDataConstants.XOR_BLOCK_SIZE_LENGTH_BITS,bitpos)+VDataConstants.XOR_BLOCK_SIZE_ADJUSTMENTS;bitpos=bitpos+VDataConstants.XOR_BLOCK_SIZE_LENGTH_BITS;this.trailingZeros=64-blockSize-this.leadingZeros;xorValue=VDataDecodeUtils.readBigIntFromBitString(this.page,blockSize,bitpos);xorValue=xorValue*BigInt(Math.pow(2,this.trailingZeros));bitpos=bitpos+blockSize}this.bitValue=xorValue^this.bitValue;this.updatedBits=true}this.bitTracker.setNumBits(bitpos)}get(){return this.hasFormula?this.formula.apply(this.raw()):this.raw()}raw(){if(this.updatedBits){this.signalValue=VDataDecodeUtils.longBitsToDouble(this.bitValue);this.updatedBits=false}return this.signalValue}bits(){return this.bitValue}}class VDataUint64XorDecode{constructor(_page,_formula,_bitTracker){this.page=_page;this.bitTracker=_bitTracker;this.formula=_formula;this.hasFormula=_formula!=null&&!(_formula instanceof VDataFormulaNone);this.bitValue=0n;this.leadingZeros=0;this.trailingZeros=0;this.updatedBits=false}first(){this.next()}next(){let bitpos=this.bitTracker.getNumBits();if(VDataDecodeUtils.readValueFromBitOne(this.page,bitpos++)!=0){let xorValue;if(VDataDecodeUtils.readValueFromBitOne(this.page,bitpos++)!=0){let bits=64-this.leadingZeros-this.trailingZeros;xorValue=VDataDecodeUtils.readBigIntFromBitString(this.page,bits,bitpos);xorValue=xorValue*BigInt(Math.pow(2,this.trailingZeros));bitpos=bitpos+bits}else{this.leadingZeros=VDataDecodeUtils.readValueFromBitString(this.page,VDataConstants.XOR_LEADING_ZERO_LENGTH_BITS,bitpos);bitpos=bitpos+VDataConstants.XOR_LEADING_ZERO_LENGTH_BITS;let blockSize=VDataDecodeUtils.readValueFromBitString(this.page,VDataConstants.XOR_BLOCK_SIZE_LENGTH_BITS,bitpos)+VDataConstants.XOR_BLOCK_SIZE_ADJUSTMENTS;bitpos=bitpos+VDataConstants.XOR_BLOCK_SIZE_LENGTH_BITS;this.trailingZeros=64-blockSize-this.leadingZeros;xorValue=VDataDecodeUtils.readBigIntFromBitString(this.page,blockSize,bitpos);bitpos=bitpos+blockSize;xorValue=xorValue*BigInt(Math.pow(2,this.trailingZeros))}this.bitValue=xorValue^this.bitValue;this.updatedBits=true}this.bitTracker.setNumBits(bitpos)}get(){return this.hasFormula?this.formula.apply(this.raw()):this.raw()}raw(){if(this.updatedBits){this.updatedBits=false}return this.bitValue}bits(){return this.bitValue}}class VDataInt64XorDecode extends VDataUint64XorDecode{constructor(_page,_formula,_bitTracker){super(_page,_formula,_bitTracker);this.signalValue=0n}raw(){if(this.updatedBits){this.signalValue=VDataDecodeUtils.longBitsToUint64(this.bitValue);this.updatedBits=false}return this.signalValue}}class VDataUInt8NoneDecode{constructor(_page,_formula,_bitTracker){this.page=_page;this.bitTracker=_bitTracker;this.formula=_formula;this.hasFormula=_formula!=null&&!(_formula instanceof VDataFormulaNone);this.bitValue=0}first(){this.next()}next(){let bitpos=this.bitTracker.getNumBits();if((this.page[bitpos>>3]&VDataConstants.BIT_MASKS[bitpos++&7])!=0){this.bitValue=VDataDecodeUtils.readValueFromBitString(this.page,8,bitpos);bitpos=bitpos+8}this.bitTracker.setNumBits(bitpos)}get(){return this.hasFormula?this.formula.apply(this.bitValue):this.bitValue}raw(){return this.bitValue}bits(){return this.bitValue}}class VDataUInt8PlainDecode{constructor(_page,_formula,_bitTracker){this.page=_page;this.bitTracker=_bitTracker;this.formula=_formula;this.hasFormula=_formula!=null&&!(_formula instanceof VDataFormulaNone);this.bitValue=0}first(){this.next()}next(){let bitpos=this.bitTracker.getNumBits();this.bitValue=VDataDecodeUtils.readValueFromBitString(this.page,8,bitpos);this.bitTracker.setNumBits(bitpos+8)}get(){return this.hasFormula?this.formula.apply(this.bitValue):this.bitValue}raw(){return this.bitValue}bits(){return this.bitValue}}class VDataUInt8XorDecode{constructor(_page,_formula,_bitTracker){this.page=_page;this.bitTracker=_bitTracker;this.formula=_formula;this.hasFormula=_formula!=null&&!(_formula instanceof VDataFormulaNone);this.bitValue=0}first(){this.next()}next(){let bitpos=this.bitTracker.getNumBits();if(VDataDecodeUtils.readValueFromBitOne(this.page,bitpos++)!=0){let diff=0;if(VDataDecodeUtils.readValueFromBitOne(this.page,bitpos++)==0){diff=VDataDecodeUtils.readValueFromBitString(this.page,3,bitpos)+1;bitpos=bitpos+3}else{diff=VDataDecodeUtils.readValueFromBitString(this.page,8,bitpos);bitpos=bitpos+8}this.bitValue=diff^this.bitValue}this.bitTracker.setNumBits(bitpos)}get(){return this.hasFormula?this.formula.apply(this.bitValue):this.bitValue}raw(){return this.bitValue}bits(){return this.bitValue}}class VDataInt8NoneDecode{constructor(_page,_formula,_bitTracker){this.page=_page;this.bitTracker=_bitTracker;this.formula=_formula;this.hasFormula=_formula!=null&&!(_formula instanceof VDataFormulaNone);this.bitValue=0}first(){this.next()}next(){let bitpos=this.bitTracker.getNumBits();if(VDataDecodeUtils.readValueFromBitOne(this.page,bitpos++)!=0){let value=VDataDecodeUtils.readValueFromBitString(this.page,8,bitpos);if(value>127){value=value-256}this.bitValue=value;bitpos=bitpos+8}this.bitTracker.setNumBits(bitpos)}get(){return this.hasFormula?this.formula.apply(this.bitValue):this.bitValue}raw(){return this.bitValue}bits(){return this.bitValue}}class VDataInt32DeltaDecode{constructor(_page,_formula,_bitTracker){this.page=_page;this.bitTracker=_bitTracker;this.formula=_formula;this.hasFormula=_formula!=null&&!(_formula instanceof VDataFormulaNone);this.bitValue=0;this.deltaSigBits=0}first(){this.next()}next(){let bitpos=this.bitTracker.getNumBits();if(VDataDecodeUtils.readValueFromBitOne(this.page,bitpos++)!=0){if(VDataDecodeUtils.readValueFromBitOne(this.page,bitpos++)==0){this.deltaSigBits=VDataDecodeUtils.readValueFromBitString(this.page,VDataConstants.XOR_LEADING_ZERO_LENGTH_BITS,bitpos);bitpos=bitpos+VDataConstants.XOR_LEADING_ZERO_LENGTH_BITS}let neg=VDataDecodeUtils.readValueFromBitOne(this.page,bitpos++)!=0;let deltaValue=VDataDecodeUtils.readValueFromBitString(this.page,this.deltaSigBits,bitpos);bitpos=bitpos+this.deltaSigBits;let value=0;if(neg){value=this.bitValue-deltaValue;if(-value>2147483648){value=value+4294967296}}else{value=this.bitValue+deltaValue;if(value>2147483647){value=value-4294967296}}this.bitValue=value}this.bitTracker.setNumBits(bitpos)}get(){return this.hasFormula?this.formula.apply(this.bitValue):this.bitValue}raw(){return this.bitValue}bits(){return this.bitValue}}class VDataBlobDecode{constructor(_page,_formula,_bitTracker,_blobBuffer){this.blobBuffer=_blobBuffer;this.blobView=new DataView(new Uint8Array(_blobBuffer).buffer);this.formula=_formula;this.hasFormula=_formula!=null&&!(_formula instanceof VDataFormulaNone);this.offsetDecode=new VDataInt32DeltaDecode(_page,new VDataFormulaNone(_formula.name()+"_offset"),_bitTracker)}first(){this.next()}next(){this.offsetDecode.next()}get(){let offset=this.offsetDecode.get();let data=this.getBlobData(offset);return this.hasFormula?this.formula.apply(data):data}raw(){let offset=this.offsetDecode.get();let data=this.getBlobData(offset);return data}bits(){return this.raw()}getBlobData(offset){let header_length=this.blobView.getUint16(offset,true);let data_length=this.blobView.getInt32(offset+4,true);return this.blobBuffer.slice(offset+header_length,offset+header_length+data_length)}}class VDataBooleanNoneDecode{constructor(_page,_formula,_bitTracker){this.page=_page;this.bitTracker=_bitTracker;this.formula=_formula;this.hasFormula=_formula!=null&&!(_formula instanceof VDataFormulaNone);this.bitValue=0}first(){this.next()}next(){let bitpos=this.bitTracker.getNumBits();this.bitValue=VDataDecodeUtils.readValueFromBitOne(this.page,bitpos);this.bitTracker.setNumBits(bitpos+1)}get(){return this.hasFormula?this.formula.apply(this.bitValue):this.bitValue}raw(){return this.bitValue}bits(){return this.bitValue}}class VDataStringNoneDecode{constructor(_page,_formula,_bitTracker){this.page=_page;this.bitTracker=_bitTracker;this.formula=_formula;this.hasFormula=_formula!=null&&!(_formula instanceof VDataFormulaNone);this.bitValue=[]}first(){this.next()}next(){let bitpos=this.bitTracker.getNumBits();let bb=[];let b;do{b=VDataDecodeUtils.readValueFromBitString(this.page,8,bitpos);bitpos=bitpos+8;if(b==0){break}bb.push(b)}while(true);this.bitValue=bb;this.bitTracker.setNumBits(bitpos)}get(){return this.hasFormula?this.formula.apply(this.raw()):this.raw()}raw(){return this.bitValue.length==0?"":(new TextDecoder).decode(new Uint8Array(this.bitValue))}bits(){return this.bitValue}}class VDataNumberArrayDecode{constructor(_page,_dtype,_encoder,_length,_matchLength,_formula,_bitTracker){this.page=_page;this.decoders=[];this.bitTracker=_bitTracker;if(_formula instanceof VDataFormulaArray){let formulas=_formula._formulas;let flen=formulas.length;if(flen==0){let fn=new VDataFormulaNone(_formula._name);for(let i=0;i<_length;++i){this.decoders.push(this.buildDecoder(_page,_dtype,_encoder,fn,_bitTracker))}}else{if(_length!=flen&&_matchLength){throw"FORMAT_VDATA_ARRAY_LENGTH_MISMATCH: length="+String(_length)+", formula is "+_formula.name()}let s=_length<flen?_length:flen;for(let i=0;i<s;++i){this.decoders.push(this.buildDecoder(_page,_dtype,_encoder,formulas[i],_bitTracker))}for(let i=flen;i<_length;++i){this.decoders.push(this.buildDecoder(_page,_dtype,_encoder,formulas[flen-1],_bitTracker))}}}else{for(let i=0;i<_length;++i){this.decoders.push(this.buildDecoder(_page,_dtype,_encoder,_formula,_bitTracker))}}}buildDecoder(_page,_dtype,_encoder,_formula,_bitTracker){if(_dtype==DType.UInt8){if(_encoder==DEncoder.XOR){return new VDataUInt8XorDecode(_page,_formula,_bitTracker)}else if(_encoder==DEncoder.PLAIN){return new VDataUInt8PlainDecode(_page,_formula,_bitTracker)}else{return new VDataUInt8NoneDecode(_page,_formula,_bitTracker)}}if(_dtype==DType.Float64){if(_encoder==DEncoder.CHIMP){return new VDataFloat64ChimpDecode(_page,_formula,_bitTracker)}else if(_encoder==DEncoder.ERASURE){return new VDataFloat64ErasureDecode(_page,_formula,_bitTracker)}else if(_encoder==DEncoder.NONE){return new VDataFloat64NoneDecode(_page,_formula,_bitTracker)}else{return new VDataFloat64XorDecode(_page,_formula,_bitTracker)}}if(_dtype==DType.Int8){return new VDataInt8NoneDecode(_page,_formula,_bitTracker)}if(_dtype==DType.Int16||_dtype==DType.Int32){return new VDataInt32DeltaDecode(_page,_formula,_bitTracker)}if(_dtype==DType.Boolean){return new VDataBooleanNoneDecode(_page,_formula,_bitTracker)}if(_dtype==DType.Float32){return new VDataFloat32NoneDecode(_page,_formula,_bitTracker)}if(_dtype==DType.Uint64){return new VDataUint64XorDecode(_page,_formula,_bitTracker)}if(_dtype==DType.Int64){return new VDataInt64XorDecode(_page,_formula,_bitTracker)}throw"FORMAT_VDATA_DATA_TYPE_NOT_SUPPORTED: "+String(_dtype)}first(){this.next()}next(){for(let i=0,s=this.decoders.length;i<s;++i){this.decoders[i].next()}}get(){let vals=[];for(let i=0,s=this.decoders.length;i<s;++i){vals.push(this.decoders[i].get())}return vals}raw(){let vals=[];for(let i=0,s=this.decoders.length;i<s;++i){vals.push(this.decoders[i].raw())}return vals}bits(){let vals=[];for(let i=0,s=this.decoders.length;i<s;++i){vals.push(this.decoders[i].bits())}return vals}}class VDataStringArrayDecode{constructor(_page,_dtype,_encoder,_length,_matchLength,_formula,_bitTracker){this.page=_page;this.decoders=[];this.bitTracker=_bitTracker;if(_formula instanceof VDataFormulaArray){let formulas=_formula._formulas;let flen=formulas.length;if(flen==0){let fn=new VDataFormulaNone(_formula._name);for(let i=0;i<_length;++i){this.decoders.push(this.buildDecoder(_page,_dtype,_encoder,fn,_bitTracker))}}else{if(_length!=flen&&_matchLength){throw"FORMAT_VDATA_ARRAY_LENGTH_MISMATCH: length="+String(_length)+", formula is "+_formula.name()}let s=_length<flen?_length:flen;for(let i=0;i<s;++i){this.decoders.push(this.buildDecoder(_page,_dtype,_encoder,formulas[i],_bitTracker))}for(let i=flen;i<_length;++i){this.decoders.push(this.buildDecoder(_page,_dtype,_encoder,formulas[flen-1],_bitTracker))}}}else{for(let i=0;i<_length;++i){this.decoders.push(this.buildDecoder(_page,_dtype,_encoder,_formula,_bitTracker))}}}buildDecoder(_page,_dtype,_encoder,_formula,_bitTracker){return new VDataStringNoneDecode(_page,_formula,_bitTracker)}first(){this.next()}next(){for(let i=0,s=this.decoders.length;i<s;++i){this.decoders[i].next()}}get(){let vals=[];for(let i=0,s=this.decoders.length;i<s;++i){vals.push(this.decoders[i].get())}return vals}raw(){let vals=[];for(let i=0,s=this.decoders.length;i<s;++i){vals.push(this.decoders[i].raw())}return vals}bits(){let vals=[];for(let i=0,s=this.decoders.length;i<s;++i){vals.push(this.decoders[i].bits())}return vals}}class VDataNullDecode{constructor(_page,_bitTracker){this.page=_page;this.bitTracker=_bitTracker}isNull(){const bitpos=this.bitTracker.getNumBits();let check=VDataDecodeUtils.readValueFromBitOne(this.page,bitpos)==1;this.bitTracker.setNumBits(bitpos+1);return check}isNotNull(){const bitpos=this.bitTracker.getNumBits();let check=VDataDecodeUtils.readValueFromBitOne(this.page,bitpos)==0;this.bitTracker.setNumBits(bitpos+1);return check}}class VDataStructDecode{constructor(_page,_dtypes,_encoders,_length,_formula,_bitTracker){this.page=_page;this.decoders=[];this.notnulls=[];this.bitTracker=_bitTracker;this.nullDecoder=new VDataNullDecode(_page,_bitTracker);if(!(_formula instanceof VDataFormulaStruct)){throw"FORMAT_VDATA_STRUCT_FORMULA_MISMATCH: "+_formula._name}let formulas=_formula._formulas;let flen=formulas.length;if(_length!=flen){throw"FORMAT_VDATA_STRUCT_LENGTH_MISMATCH: "+_formula._name}this.subLength=flen;for(let i=0;i<flen;++i){this.decoders.push(this.buildDecoder(_page,_dtypes[i],_encoders[i],formulas[i],_bitTracker));this.notnulls.push(true)}}buildDecoder(_page,_dtype,_encoder,_formula,_bitTracker){if(_dtype==DType.UInt8){if(_encoder==DEncoder.XOR){return new VDataUInt8XorDecode(_page,_formula,_bitTracker)}else{return new VDataUInt8NoneDecode(_page,_formula,_bitTracker)}}if(_dtype==DType.Float64){if(_encoder==DEncoder.CHIMP){return new VDataFloat64ChimpDecode(_page,_formula,_bitTracker)}else if(_encoder==DEncoder.ERASURE){return new VDataFloat64ErasureDecode(_page,_formula,_bitTracker)}else if(_encoder==DEncoder.NONE){return new VDataFloat64NoneDecode(_page,_formula,_bitTracker)}else{return new VDataFloat64XorDecode(_page,_formula,_bitTracker)}}if(_dtype==DType.Int8){return new VDataInt8NoneDecode(_page,_formula,_bitTracker)}if(_dtype==DType.Int16||_dtype==DType.Int32){return new VDataInt32DeltaDecode(_page,_formula,_bitTracker)}if(_dtype==DType.Boolean){return new VDataBooleanNoneDecode(_page,_formula,_bitTracker)}if(_dtype==DType.String){return new VDataStringNoneDecode(_page,_formula,_bitTracker)}if(_dtype==DType.Float32){return new VDataFloat32NoneDecode(_page,_formula,_bitTracker)}if(_dtype==DType.Uint64){return new VDataUint64XorDecode(_page,_formula,_bitTracker)}if(_dtype==DType.Int64){return new VDataInt64XorDecode(_page,_formula,_bitTracker)}throw"FORMAT_VDATA_DATA_TYPE_NOT_SUPPORTED: "+String(_dtype)}first(){this.next()}next(){for(let i=0,s=this.decoders.length;i<s;++i){this.notnulls[i]=this.nullDecoder.isNotNull();if(this.notnulls[i]){this.decoders[i].next()}}}get(){let vals=[];for(let i=0,s=this.decoders.length;i<s;++i){vals.push(this.notnulls[i]?this.decoders[i].get():null)}return vals}raw(){let vals=[];for(let i=0,s=this.decoders.length;i<s;++i){vals.push(this.notnulls[i]?this.decoders[i].raw():null)}return vals}bits(){let vals=[];for(let i=0,s=this.decoders.length;i<s;++i){vals.push(this.notnulls[i]?this.decoders[i].bits():null)}return vals}}class VDataTimeDeltaDecode{constructor(_page,_bitTracker,_timestampLength){this.page=_page;this.bitTracker=_bitTracker;this.timestampLength=_timestampLength;this.millis=0;this.millisDelta=0}first(){let bitpos=this.bitTracker.getNumBits();this.millis=VDataDecodeUtils.readValueFromBitString(this.page,this.timestampLength,bitpos);this.millisDelta=VDataConstants.TIMESTAMP_INIT_DELTA;this.bitTracker.setNumBits(bitpos+this.timestampLength)}next(){let bitpos=this.bitTracker.getNumBits();if((this.page[bitpos>>3]&VDataConstants.BIT_MASKS[bitpos++&7])!=0){let ttype;if((this.page[bitpos>>3]&VDataConstants.BIT_MASKS[bitpos++&7])==0){ttype=1}else if((this.page[bitpos>>3]&VDataConstants.BIT_MASKS[bitpos++&7])==0){ttype=2}else if((this.page[bitpos>>3]&VDataConstants.BIT_MASKS[bitpos++&7])==0){ttype=3}else{ttype=4}let bitsForValue=VDataConstants.TIMESTAMP_VALUE_ENCODING[ttype-1];let decodedValue=VDataDecodeUtils.readValueFromBitString(this.page,bitsForValue,bitpos)-VDataConstants.BIT_POWER2[bitsForValue-1];this.millisDelta=this.millisDelta+(decodedValue>=0?decodedValue+1:decodedValue);bitpos=bitpos+bitsForValue}this.millis=this.millis+this.millisDelta;this.bitTracker.setNumBits(bitpos)}get(){return this.millis}raw(){return this.millis}timestamp(){return this.millis}}class VDataTimeMicrosDecode{constructor(_page,_bitTracker,_timestampLength){this.page=_page;this.bitTracker=_bitTracker;this.timestampLength=_timestampLength;this.millis=0;this.millisDelta=0;this.micros=0}first(){let bitpos=this.bitTracker.getNumBits();this.millis=VDataDecodeUtils.readValueFromBitString(this.page,this.timestampLength,bitpos);this.millisDelta=VDataConstants.TIMESTAMP_INIT_DELTA;bitpos=bitpos+this.timestampLength;if(VDataDecodeUtils.readValueFromBitOne(this.page,bitpos++)!=0){this.micros=VDataDecodeUtils.readValueFromBitString(this.page,VDataConstants.MICROSECOND_BITS,bitpos);bitpos=bitpos+VDataConstants.MICROSECOND_BITS}else{this.micros=0}this.bitTracker.setNumBits(bitpos)}next(){let bitpos=this.bitTracker.getNumBits();if((this.page[bitpos>>3]&VDataConstants.BIT_MASKS[bitpos++&7])!=0){let ttype;if((this.page[bitpos>>3]&VDataConstants.BIT_MASKS[bitpos++&7])==0){ttype=1}else if((this.page[bitpos>>3]&VDataConstants.BIT_MASKS[bitpos++&7])==0){ttype=2}else if((this.page[bitpos>>3]&VDataConstants.BIT_MASKS[bitpos++&7])==0){ttype=3}else{ttype=4}let bitsForValue=VDataConstants.TIMESTAMP_VALUE_ENCODING[ttype-1];let decodedValue=VDataDecodeUtils.readValueFromBitString(this.page,bitsForValue,bitpos)-VDataConstants.BIT_POWER2[bitsForValue-1];this.millisDelta=this.millisDelta+(decodedValue>=0?decodedValue+1:decodedValue);bitpos=bitpos+bitsForValue}this.millis=this.millis+this.millisDelta;if((this.page[bitpos>>3]&VDataConstants.BIT_MASKS[bitpos++&7])!=0){this.micros=VDataDecodeUtils.readValueFromBitString(this.page,VDataConstants.MICROSECOND_BITS,bitpos);bitpos=bitpos+VDataConstants.MICROSECOND_BITS}else{this.micros=0}this.bitTracker.setNumBits(bitpos)}get(){if(this.micros==0){return this.millis}return this.millis+this.micros/1e3}raw(){if(this.micros==0){return this.millis}return this.millis+this.micros/1e3}timestamp(){return this.millis}}class VDataObjectValueArray{constructor(time,colsize){this._time=time;this._colsize=colsize}getTime(){return this._time}}class VDataDenseArray extends VDataObjectValueArray{constructor(time,colsize){super(time,colsize);this._values=new Array(colsize);this._values[0]=this._time}isEmptyAt(position){return this._values[position]==null}add(position,value){this._values[position]=value}toObjects(){return this._values}}class VDataDenseArrayFirstMode extends VDataDenseArray{constructor(time,colsize){super(time,colsize)}add(position,value){if(this._values[position]==null){this._values[position]=value}}}class VDataSparseArray extends VDataObjectValueArray{constructor(time,colsize){super(time,colsize);this._posits=new Array;this._values=new Array;this._posits.push(0);this._values.push(time)}isEmptyAt(position){for(let i=1,s=this._posits.length;i<s;++i){if(this._posits[i]==position){return this._values[i]==null}}return true}add(position,value){this._posits.push(position);this._values.push(value)}toObjects(){let vals=new Array(this._colsize);for(let i=0,s=this._posits.length;i<s;++i){vals[this._posits[i]]=this._values[i]}return vals}}class VDataSparseArrayFirstMode extends VDataSparseArray{constructor(time,colsize){super(time,colsize)}toObjects(){let vals=new Array(this._colsize);for(let i=0,s=this._posits.length;i<s;++i){let pos=this._posits[i];if(vals[pos]==null){vals[pos]=this._values[i]}}return vals}}class VDataSparseArrayAllMode extends VDataSparseArray{constructor(time,colsize){super(time,colsize)}isEmptyAt(position){let low=1;let high=this._posits.length-1;let mid=Math.floor((low+high)/2);let pos=0;while(low<high){pos=this._posits[mid];if(position==pos){return false}else if(position<pos){high=mid-1}else{low=mid+1}mid=Math.floor((low+high)/2)}if(high==low&&position==this._posits[low]){return false}return true}add(position,value){if(position==0){return}let low=1;let high=this._posits.length-1;let mid=Math.floor((low+high)/2);let pos=0;while(low<high){pos=this._posits[mid];if(position==pos){this._values[mid]=value;return}else if(position<pos){high=mid-1}else{low=mid+1}mid=Math.floor((low+high)/2)}if(low==high){pos=this._posits[low];if(position==pos){this._values[low]=value}else if(position<pos){this._posits.splice(low,0,position);this._values.splice(low,0,value)}else{this._posits.splice(low+1,0,position);this._values.splice(low+1,0,value)}}else{this._posits.splice(low,0,position);this._values.splice(low,0,value)}}}class VDataSeriesDecodeBuilder{static build(_data){let _version=_data.getFormatVersion();if(_version<26){return new VDataSeriesDecodeNumber(_data,0,DType.Float64,DEncoder.XOR)}let _bt=_data.getPage();let btreader=new VDataByteReader(_bt);let firstbyte=btreader.read(1)[0];let _type=firstbyte>>4&15;let _offset=8;if(_type==DType.Array){let high_len=btreader.read(1)[0];let low_len=btreader.read(1)[0];let _length=(high_len&255)<<8|low_len&255;let sub=btreader.read(1)[0];let _subtype=sub>>4&15;let _encoder=sub&15;_offset=32;let element_exist_array=new Array(_length);if(_version>27){for(var i=0;i<_length;i++){element_exist_array[i]=true;var byte_index=i/8;var bit_index=7-i%8;element_exist_array[i]=(_data[4+byte_index]>>bit_index&1)==1;_offset=32+(_length<=16?2:Math.ceil(_length/8))*8}}else{for(var i=0;i<_length;i++){element_exist_array[i]=true}_offset=32}if(_data.getFormula()instanceof VDataFormulaNamedArray){return new VDataSeriesDecodeNamedArray(_data,_offset,_subtype,_encoder,_length)}else if(_subtype==DType.String){return new VDataSeriesDecodeStringArray(_data,_offset,_subtype,_encoder,_length)}else{return new VDataSeriesDecodeNumberArray(_data,_offset,_subtype,_encoder,_length,false)}}if(_type==DType.Struct){let high_len=btreader.read(1)[0];let low_len=btreader.read(1)[0];let _length=(high_len&255)<<8|low_len&255;let _subtypes=[];let _encoders=[];_offset=8+16+8*_length;for(let i=0;i<_length;++i){let sub=btreader.read(1)[0];_subtypes.push(sub>>4&15);_encoders.push(sub&15)}return new VDataSeriesDecodeStruct(_data,_offset,_subtypes,_encoders,_length)}let _encoder=firstbyte&15;if(_type==DType.String){return new VDataSeriesDecodeString(_data,_offset,_type,_encoder)}if(_type==DType.Blob){return new VDataSeriesDecodeBlob(_data,_offset,_type,_encoder)}return new VDataSeriesDecodeNumber(_data,_offset,_type,_encoder)}static builds(_datas){let decoders=[];for(const _data of _datas){decoders.push(VDataSeriesDecodeBuilder.build(_data))}return decoders}}class VDataSeriesBucket{constructor(){this.name=null;this.formatVersion=0;this.bucketCycle=0;this.sstime=0;this.setime=0;this.qstime=0;this.qetime=0;this.page=null;this.formula=null;this.itemCount=0;this.firstTime=null}getFormatVersion(){return this.formatVersion}setFormatVersion(version){this.formatVersion=version}getName(){return this.name}getFormula(){return this.formula}getItemCount(){return this.itemCount}setMeta(meta){this.name=meta.name();this.formula=meta.formula();this.itemCount=meta.itemCount()}getPage(){return this.page}setPage(page){this.page=page}getFirstTime(){return this.firstTime}setFirstTime(time){this.firstTime=time}getBucketCycle(){return this.bucketCycle}setBucketCycle(cycle){this.bucketCycle=cycle}getBucketStartTime(){return this.sstime}setBucketStartTime(time){this.sstime=time}getBucketEndTime(){return this.setime}setBucketEndTime(time){this.setime=time}getQueryStartTime(){return this.qstime}setQueryStartTime(qstime){this.qstime=qstime}getQueryEndTime(){return this.qetime}setQueryEndTime(qetime){this.qetime=qetime}setBlobData(data){this.blobData=data}getBlobData(){return this.blobData}setSeriesTimestampLength(length){this.timestampLenth=length}getSeriesTimestampLength(){return this.timestampLenth}}class VDataSeriesDecode{constructor(data,offset){this.name=data.getName();this.formula=data.getFormula();this.itemCount=data.getItemCount();this.page=data.getPage();this.bucketCycle=data.getBucketCycle();this.qstime=data.getQueryStartTime();this.qetime=data.getQueryEndTime();this.bitTracker=new BitTracker;this.bitTracker.setNumBits(offset);this.timeDecode=new VDataTimeDeltaDecode(this.page,this.bitTracker,data.getSeriesTimestampLength());this.readCount=0;this.emptied=true}getName(){return this.name}getFormula(){return this.formula}getItemCount(){return this.itemCount}getQueryStartTime(){return this.qstime}getQueryEndTime(){return this.qetime}time(){return this.timeDecode.get()}timestamp(){return this.timeDecode.timestamp()}isEmpty(){return this.emptied}getSubNames(){return null}}class VDataSeriesDecodeNumber extends VDataSeriesDecode{constructor(data,offset,dtype,encoder){super(data,offset);if(dtype==DType.UInt8){if(encoder==DEncoder.XOR){this.valueDecode=new VDataUInt8XorDecode(this.page,this.formula,this.bitTracker)}else{this.valueDecode=new VDataUInt8NoneDecode(this.page,this.formula,this.bitTracker)}}else if(dtype==DType.Float64){if(encoder==DEncoder.CHIMP){this.valueDecode=new VDataFloat64ChimpDecode(this.page,this.formula,this.bitTracker)}else if(encoder==DEncoder.ERASURE){this.valueDecode=new VDataFloat64ErasureDecode(this.page,this.formula,this.bitTracker)}else if(encoder==DEncoder.NONE){this.valueDecode=new VDataFloat64NoneDecode(this.page,this.formula,this.bitTracker)}else{this.valueDecode=new VDataFloat64XorDecode(this.page,this.formula,this.bitTracker)}}else if(dtype==DType.Int8){this.valueDecode=new VDataInt8NoneDecode(this.page,this.formula,this.bitTracker)}else if(dtype==DType.Int16||dtype==DType.Int32){this.valueDecode=new VDataInt32DeltaDecode(this.page,this.formula,this.bitTracker)}else if(dtype==DType.Boolean){this.valueDecode=new VDataBooleanNoneDecode(this.page,this.formula,this.bitTracker)}else if(dtype==DType.Float32){this.valueDecode=new VDataFloat32NoneDecode(this.page,this.formula,this.bitTracker)}else if(dtype==DType.Uint64){this.valueDecode=new VDataUint64XorDecode(this.page,this.formula,this.bitTracker)}else if(dtype==DType.Int64){this.valueDecode=new VDataInt64XorDecode(this.page,this.formula,this.bitTracker)}else{throw"FORMAT_VDATA_DATA_TYPE_NOT_SUPPORTED: "+String(dtype)}if(this.readCount<this.itemCount){this.timeDecode.first();this.valueDecode.first();this.emptied=false;this.readCount++}}value(){return this.valueDecode.get()}rawBits(){return this.valueDecode.bits()}pair(){return new VDataSeriesPair(this.time(),this.value())}pollAndAdd(){if(this.readCount<this.itemCount){this.timeDecode.next();this.valueDecode.next();this.readCount++}else{this.emptied=true}}}class VDataSeriesDecodeBlob extends VDataSeriesDecode{constructor(data,offset,dtype,encoder){super(data,offset);this.valueDecode=new VDataBlobDecode(this.page,this.formula,this.bitTracker,data.getBlobData());if(this.readCount<this.itemCount){this.timeDecode.first();this.valueDecode.first();this.emptied=false;this.readCount++}}value(){return this.valueDecode.get()}rawBits(){return this.valueDecode.bits()}pair(){return new VDataSeriesPair(this.time(),this.value())}pollAndAdd(){if(this.readCount<this.itemCount){this.timeDecode.next();this.valueDecode.next();this.readCount++}else{this.emptied=true}}}class VDataSeriesDecodeString extends VDataSeriesDecode{constructor(data,offset,dtype,encoder){super(data,offset);this.valueDecode=new VDataStringNoneDecode(this.page,this.formula,this.bitTracker);if(this.readCount<this.itemCount){this.timeDecode.first();this.valueDecode.first();this.emptied=false;this.readCount++}}value(){return this.valueDecode.get()}rawBits(){return this.valueDecode.bits()}pair(){return new VDataSeriesPair(this.time(),this.value())}pollAndAdd(){if(this.readCount<this.itemCount){this.timeDecode.next();this.valueDecode.next();this.readCount++}else{this.emptied=true}}}class VDataSeriesDecodeNumberArray extends VDataSeriesDecode{constructor(data,offset,dtype,encoder,length,matchLength){super(data,offset);if(encoder==DEncoder.PLAIN){this.timeDecode=new VDataTimeDeltaDecode(this.page,this.bitTracker,data.getSeriesTimestampLength());this.isPlain=true}else{this.timeDecode=new VDataTimeMicrosDecode(this.page,this.bitTracker,data.getSeriesTimestampLength());this.isPlain=false}this.valueDecode=new VDataNumberArrayDecode(this.page,dtype,encoder,length,matchLength,this.formula,this.bitTracker);if(this.readCount<this.itemCount){this.timeDecode.first();if(this.isPlain){if(this.bitTracker.getNumBits()%8!=0){var pos=Math.ceil(this.bitTracker.getNumBits()/8)*8;this.bitTracker.setNumBits(pos)}}this.valueDecode.first();this.emptied=false;this.readCount++}}value(){return this.valueDecode.get()}rawBits(){return this.valueDecode.bits()}pair(){return new VDataSeriesPair(this.time(),this.value())}pollAndAdd(){if(this.readCount<this.itemCount){this.timeDecode.next();if(this.isPlain){if(this.bitTracker.getNumBits()%8!=0){var pos=Math.ceil(this.bitTracker.getNumBits()/8)*8;this.bitTracker.setNumBits(pos)}}this.valueDecode.next();this.readCount++}else{this.emptied=true}}}class VDataSeriesDecodeStringArray extends VDataSeriesDecode{constructor(data,offset,dtype,encoder,length,matchLength){super(data,offset);this.timeDecode=new VDataTimeMicrosDecode(this.page,this.bitTracker,data.getSeriesTimestampLength());this.valueDecode=new VDataStringArrayDecode(this.page,dtype,encoder,length,matchLength,this.formula,this.bitTracker);if(this.readCount<this.itemCount){this.timeDecode.first();this.valueDecode.first();this.emptied=false;this.readCount++}}value(){return this.valueDecode.get()}rawBits(){return this.valueDecode.bits()}pair(){return new VDataSeriesPair(this.time(),this.value())}pollAndAdd(){if(this.readCount<this.itemCount){this.timeDecode.next();this.valueDecode.next();this.readCount++}else{this.emptied=true}}}class VDataSeriesDecodeNamedArray extends VDataSeriesDecode{constructor(data,offset,dtype,encoder,length){super(data,offset);this.timeDecode=new VDataTimeMicrosDecode(this.page,this.bitTracker,data.getSeriesTimestampLength());if(dtype!=DType.String){this.valueDecode=new VDataNumberArrayDecode(this.page,dtype,encoder,length,true,this.formula,this.bitTracker)}else{this.valueDecode=new VDataStringArrayDecode(this.page,dtype,encoder,length,true,this.formula,this.bitTracker)}let formulas=this.formula._formulas;this.subNames=[];for(let i=0,s=formulas.length;i<s;++i){this.subNames.push(formulas[i].name())}if(this.readCount<this.itemCount){this.timeDecode.first();this.valueDecode.first();this.emptied=false;this.readCount++}}value(){return this.valueDecode.get()}rawBits(){return this.valueDecode.bits()}pair(){return new VDataSeriesPair(this.time(),this.value())}pollAndAdd(){if(this.readCount<this.itemCount){this.timeDecode.next();this.valueDecode.next();this.readCount++}else{this.emptied=true}}getSubNames(){return this.subNames}}class VDataSeriesDecodeStruct extends VDataSeriesDecode{constructor(data,offset,dtypes,encoders,length){super(data,offset);this.timeDecode=new VDataTimeMicrosDecode(this.page,this.bitTracker,data.getSeriesTimestampLength());this.valueDecode=new VDataStructDecode(this.page,dtypes,encoders,length,this.formula,this.bitTracker);let formulas=this.formula._formulas;this.subNames=[];for(let i=0,s=formulas.length;i<s;++i){this.subNames.push(formulas[i].name())}if(this.readCount<this.itemCount){this.timeDecode.first();this.valueDecode.first();this.emptied=false;this.readCount++}}value(){return this.valueDecode.get()}rawBits(){return this.valueDecode.bits()}pair(){return new VDataSeriesPair(this.time(),this.value())}pollAndAdd(){if(this.readCount<this.itemCount){this.timeDecode.next();this.valueDecode.next();this.readCount++}else{this.emptied=true}}getSubNames(){return this.subNames}}class VDataSeries{constructor(name,buckets=null,itemCounts=null){this._name=name;this._buckets=buckets==null?[]:buckets;this._itemCounts=itemCounts==null?new Map:itemCounts}get[Symbol.toStringTag](){return"{name="+String(this._name)+", buckets="+String(this._buckets.length)+"}"}name(){return this._name}buckets(){return this._buckets}itemCounts(){return this._itemCounts}numBuckets(){return this._buckets.length}getMaxBucketItemCount(){let maxcnt=0;for(let[_,cnt]of this._itemCounts){if(cnt>maxcnt){maxcnt=cnt}}return maxcnt}updateBucketItemCounts(bucketNum,itemCount){let cnt=this._itemCounts.get(bucketNum);if(cnt==null){this._itemCounts.set(bucketNum,itemCount)}else{this._itemCounts.set(bucketNum,cnt+itemCount)}}addBucket(bucket){if(this._buckets.length==0){this._buckets.push(bucket);return}let bucketStartTime=bucket.getQueryStartTime()>bucket.getBucketStartTime()?bucket.getQueryStartTime():bucket.getBucketStartTime();if(bucketStartTime<=0){this._buckets.push(bucket);return}for(let i=this._buckets.length-1;i>=0;--i){let b=this._buckets[i];let s=b.getQueryStartTime()>b.getBucketStartTime()?b.getQueryStartTime():b.getBucketStartTime();if(s<=0){continue}if(bucketStartTime>s){this._buckets.splice(i+1,0,bucket);return}if(bucketStartTime==s){if(bucket.getBucketCycle()<b.getBucketCycle()){let index=i;while(index-1>=0){let probe=this._buckets[index-1];if(probe.getBucketStartTime()==s&&probe.getBucketCycle()>=b.getBucketCycle()){index=index-1}else{break}}let begin=i;while(begin>index){this._buckets.splice(begin,1);begin=begin-1}this._buckets[index]=b}else if(bucket.getBucketCycle()==b.getBucketCycle()){let index=i;while(index>=0){let probe=this._buckets[index];if(probe.getBucketStartTime()==s&&VDataSeriesUtils.getFirstDataTime(probe)>VDataSeriesUtils.getFirstDataTime(bucket)){index=index-1}else{break}}this._buckets.splice(index+1,0,bucket)}return}}this._buckets.splice(0,0,bucket)}formula(){return this._buckets[0].formula}}class VDataSeriesPoll{constructor(series,qsize=0,qmode=null){this._name=series.name();this._decoders=VDataSeriesDecodeBuilder.builds(series.buckets());this._qsize=qsize>0?qsize:VDataConstants.POLL_QUEUE_MIN_SIZE;this._qstime=0;this._qetime=0;let maxItemCount=series.getMaxBucketItemCount();if(this._qsize<maxItemCount+VDataConstants.POLL_QUEUE_MIN_SIZE){this._qsize=maxItemCount+VDataConstants.POLL_QUEUE_MIN_SIZE}this._decoder=null;this._decoderIndex=0;this._pair=null;this._queue=null;if(this._decoders.length>0){this._queue=this.buildQueue(qmode);this._decoder=this._decoders[0];this._qstime=this.getQueryStartTime(this._decoder);this._qetime=this.getQueryEndTime(this._decoder);let pair=this._decoder.pair();let _time=pair.time();let rcount=0;if(_time>this._qstime&&_time<this._qetime){this._queue.put(pair);rcount++}while(rcount<this._qsize){pair=this.poll();if(pair==null){break}_time=pair.time();if(_time>this._qstime&&_time<this._qetime&&this._queue.put(pair)){rcount++}}if(this._queue.empty()){this._queue=null}else{this._pair=this._queue.poll()}}}get[Symbol.toStringTag](){return"{name="+String(this._name)+", buckets="+String(this._decoders.length)+"}"}buildQueue(qmode){if(qmode==null){return new VDataPairQueueLastIn}switch(String(qmode).toLowerCase().trim()){case"all":return new VDataPairQueueAllIn;case"first":return new VDataPairQueueFirstIn;default:return new VDataPairQueueLastIn}}name(){return this._name}time(){return this._pair.time()}value(){return this._pair.value()}pair(){return this._pair}isEmpty(){return this._queue==null}poll(){if(this._decoder!=null){this._decoder.pollAndAdd();if(this._decoder.isEmpty()){this._decoderIndex+=1;if(this._decoders.length>this._decoderIndex){this._decoder=this._decoders[this._decoderIndex];this._qstime=this.getQueryStartTime(this._decoder);this._qetime=this.getQueryEndTime(this._decoder);return this._decoder.pair()}else{this._decoder=null;return null}}else{return this._decoder.pair()}}return null}pollAndAdd(){while(this._decoder!=null){this._decoder.pollAndAdd();if(this._decoder.isEmpty()){this._decoderIndex+=1;if(this._decoders.length>this._decoderIndex){this._decoder=this._decoders[this._decoderIndex];this._qstime=this.getQueryStartTime(this._decoder);this._qetime=this.getQueryEndTime(this._decoder);let pair=this._decoder.pair();let _time=pair.time();if(_time>this._qstime&&_time<this._qetime&&this._queue.put(pair)){break}}else{this._decoder=null}}else{let pair=this._decoder.pair();let _time=pair.time();if(_time>this._qstime&&_time<this._qetime&&this._queue.put(pair)){break}}}if(this._queue.empty()){this._queue=null}else{this._pair=this._queue.poll()}}getQueryStartTime(_decoder){return _decoder.getQueryStartTime()>0?_decoder.getQueryStartTime()-1:0}getQueryEndTime(_decoder){return _decoder.getQueryEndTime()>0?_decoder.getQueryEndTime()+1:Number.MAX_VALUE}formula(){return this._decoders[0].formula}getSubNames(){return this._decoders[0].getSubNames()}}class VDataPairQueue{constructor(){this.data=[]}empty(){return this.data.length==0}put(item){return false}poll(){if(this.data.length===0){return null}return this.data.shift()}peek(){return this.data[0]}}class VDataPairQueueAllIn extends VDataPairQueue{put(item){let low=0,high=this.data.length;if(high==0){this.data.push(item);return true}let current=this.data[high-1];let l=current.time(),t=item.time();if(t>=l){this.data.push(item);return true}while(low<high){let mid=low+high>>>1;if(this.data[mid].time()<t){low=mid+1}else{high=mid}}if(this.data[low].time()==t){while(this.data[low+1].time()==t){low=low+1}}this.data.splice(low,0,item);return true}}class VDataPairQueueFirstIn extends VDataPairQueue{put(item){let low=0,high=this.data.length;if(high==0){this.data.push(item);return true}let current=this.data[high-1];let l=current.time(),t=item.time();if(t>l){this.data.push(item);return true}else if(t==l){return false}while(low<high){let mid=low+high>>>1;if(this.data[mid].time()<t){low=mid+1}else{high=mid}}if(this.data[low].time()==t){return false}this.data.splice(low,0,item);return true}}class VDataPairQueueLastIn extends VDataPairQueue{put(item){let low=0,high=this.data.length;if(high==0){this.data.push(item);return true}let current=this.data[high-1];let l=current.time(),t=item.time();if(t>l){this.data.push(item);return true}else if(t==l){this.data[high-1]=item;return false}while(low<high){let mid=low+high>>>1;if(this.data[mid].time()<t){low=mid+1}else{high=mid}}if(this.data[low].time()==t){this.data[low]=item;return false}this.data.splice(low,0,item);return true}}class VDataPollQueue{constructor(){this.data=[];this.length=0}empty(){return this.length==0}put(item){this.data.push(item);this._up(this.length++)}poll(){if(this.length===0){return null}const top=this.data[0];const bottom=this.data.pop();if(--this.length>0){this.data[0]=bottom;this._down(0)}return top}peek(){return this.data[0]}pop(){if(this.length===0){return[]}const t=this.peek().time();const grouped=[];while(!this.empty()&&this.peek().time()==t){grouped.push(this.poll())}return grouped}_up(pos){const item=this.data[pos];while(pos>0){const parent=pos-1>>1;const current=this.data[parent];if(item.time()>=current.time()){break}this.data[pos]=current;pos=parent}this.data[pos]=item}_down(pos){const halfLength=this.length>>1;const item=this.data[pos];while(pos<halfLength){let bestChild=(pos<<1)+1;const right=bestChild+1;if(right<this.length&&this.data[right].time()<this.data[bestChild].time()){bestChild=right}if(this.data[bestChild].time()>=item.time()){break}this.data[pos]=this.data[bestChild];pos=bestChild}this.data[pos]=item}}class VDataSignalFilter{constructor(){this._signals=new Set;this._prefixes=new Set;this._signal_names=[]}getSignals(){return this._signals}setSignals(signals){if(signals!=null){this._signal_names=VDataUtils.insertion_order_set_list(signals);this._signals=new Set(this._signal_names)}else{this._signals.clear()}}getPrefixes(){return this._prefixes}setPrefixes(prefixes){if(prefixes!=null){this._prefixes=new Set(prefixes)}else{this._prefixes.clear()}}getSignalNames(){return this._signal_names}isEmpty(){return this._signals.size==0&&this._prefixes.size==0}hasNameFilterOnly(){return this._signals.size>0&&this._prefixes.size==0}}class VDataFrame{constructor(buckets,series,signalFilter=null,columnExpandMode=null,signalQueueMode=null){this._signalFilter=signalFilter!=null?signalFilter:new VDataSignalFilter;this._columnExpandMode=VDataUtils.getColumnExpandMode(columnExpandMode);this._qualifiedExpandName=VDataUtils.isQualifiedExpandName(columnExpandMode);this._signalQueueMode=VDataUtils.getSignalQueueMode(signalQueueMode);this._startTime=0;this._endTime=0;this._buckets=buckets;this._series={};for(const k in series){if(series[k].numBuckets()>0){this._series[series[k].name()]=series[k]}}}get[Symbol.toStringTag](){return Object.keys(this._series)}getSignalFilter(){return this._signalFilter}setSignalFilter(signalFilter){if(signalFilter!=null){this._signalFilter=signalFilter}}getColumnExpandMode(){return this._columnExpandMode}setColumnExpandMode(mode){this._columnExpandMode=VDataUtils.getColumnExpandMode(mode);this._qualifiedExpandName=VDataUtils.isQualifiedExpandName(mode)}getSignalQueueMode(){return this._signalQueueMode}setSignalQueueMode(mode){this._signalQueueMode=VDataUtils.getSignalQueueMode(mode)}getStartTime(){return this._startTime}setStartTime(time){this._startTime=time}getEndTime(){return this._endTime}setEndTime(time){this._endTime=time}cols(includeTime=false){let columns=VDataSeriesUtils.seriesToColumns(this._series,this._signalFilter,this._columnExpandMode,this._qualifiedExpandName);if(includeTime){columns.splice(0,0,"time")}return columns}series(){return this._series}values(densifyRowsAhead=0,densifyOutputItv=0,signalQueueRows=0){let queue=new VDataPollQueue;let templateable=new Map;let data=[];let interval=densifyOutputItv>0?densifyOutputItv:0;let denseitv=interval!=0;let nextTime=0;let columns=VDataSeriesUtils.seriesToColumns(this._series,this._signalFilter,this._columnExpandMode,this._qualifiedExpandName);for(const column of columns){templateable.set(column,null)}let selectall=this._signalFilter.isEmpty();for(const column in this._series){if(selectall||VDataSeriesUtils.serieContainsSignal(templateable,this._series[column].formula(),this._columnExpandMode,this._qualifiedExpandName)){let poll=new VDataSeriesPoll(this._series[column],signalQueueRows,this._signalQueueMode);if(!poll.isEmpty()){queue.put(poll)}}}if(densifyRowsAhead<=0){while(!queue.empty()){let polls=queue.pop();let _time=polls[0].time();let values=new Map(templateable);for(let i=0;i<polls.length;++i){let poll=polls[i];this.put(values,poll);poll.pollAndAdd();if(!poll.isEmpty()){queue.put(poll)}}let row=[_time];row.push.apply(row,[...values.values()]);data.push(row)}}else{let records=[];let cnt=0;while(cnt++<=densifyRowsAhead){if(queue.empty()){break}let values=new Map;let polls=queue.pop();let _time=polls[0].time();for(let i=0;i<polls.length;++i){let poll=polls[i];this.tut(templateable,values,poll);poll.pollAndAdd();if(!poll.isEmpty()){queue.put(poll)}}records.push(new VDataRecord(_time,values))}nextTime=denseitv?this.cutoffInterval(records[0].time(),interval):0;for(const record of records){if(denseitv){let millis=this.cutoffInterval(record.time(),interval);if(millis!=nextTime){let row=[nextTime];row.push.apply(row,[...templateable.values()]);data.push(row);nextTime=nextTime+interval}}let _values=record.values();for(let[_k,_v]of _values){templateable.set(_k,_v)}if(!denseitv){let row=[record.time()];row.push.apply(row,[...templateable.values()]);data.push(row)}}while(!queue.empty()){let polls=queue.pop();let _time=polls[0].time();if(denseitv){let millis=this.cutoffInterval(_time,interval);if(millis!=nextTime){let row=[nextTime];row.push.apply(row,[...templateable.values()]);data.push(row);nextTime=nextTime+interval}}for(let i=0;i<polls.length;++i){let poll=polls[i];this.put(templateable,poll);poll.pollAndAdd();if(!poll.isEmpty()){queue.put(poll)}}if(!denseitv){let row=[_time];row.push.apply(row,[...templateable.values()]);data.push(row)}}}if(denseitv&&nextTime!=0){let row=[nextTime];row.push.apply(row,[...templateable.values()]);data.push(row)}console.log("Data rows: "+String(data.length));return data}put(values,poll){let pname=poll.name();let pval=poll.value();let subNames=poll.getSubNames();if(subNames==null||subNames.length==0){values.set(pname,pval)}else if(this._columnExpandMode==DExpand.NONE){let subValues=pval;let pmap={};for(let i=0,s=subNames.length;i<s;++i){pmap[subNames[i]]=subValues[i]}values.set(pname,pmap)}else{let subValues=pval;for(let i=0,s=subNames.length;i<s;++i){let subName=this._qualifiedExpandName?pname+"."+subNames[i]:subNames[i];if(values.has(subName)){values.set(subName,subValues[i])}}}}tut(templateable,values,poll){let pname=poll.name();let pval=poll.value();let subNames=poll.getSubNames();if(subNames==null||subNames.length==0){if(templateable.get(pname)==null){templateable.set(pname,pval)}values.set(pname,pval)}else if(this._columnExpandMode==DExpand.NONE){let subValues=pval;let pmap={};for(let i=0,s=subNames.length;i<s;++i){pmap[subNames[i]]=subValues[i]}if(templateable.get(pname)==null){templateable.set(pname,pmap)}values.set(pname,pmap)}else{let subValues=pval;for(let i=0,s=subNames.length;i<s;++i){let subName=this._qualifiedExpandName?pname+"."+subNames[i]:subNames[i];if(templateable.has(subName)){if(templateable.get(subName)==null){templateable.set(subName,subValues[i])}values.set(subName,subValues[i])}}}}objects(densifyRowsAhead=0,densifyOutputItv=0){if(this._endTime-this._startTime>36e5){return this.values(densifyRowsAhead,densifyOutputItv)}let oread=null;switch(this._signalQueueMode){case"all":oread=new VDataObjectsSeriesAllMode(this._series,this._signalFilter,this._columnExpandMode,this._qualifiedExpandName,this._startTime,this._endTime);break;case"first":oread=new VDataObjectsSeriesFirstMode(this._series,this._signalFilter,this._columnExpandMode,this._qualifiedExpandName,this._startTime,this._endTime);break;default:oread=new VDataObjectsSeriesReader(this._series,this._signalFilter,this._columnExpandMode,this._qualifiedExpandName,this._startTime,this._endTime)}let objects=oread.read();if(densifyRowsAhead<=0||objects.length<=1){return objects}for(let col=1,cols=objects[0].length;col<cols;++col){if(objects[0][col]==null){for(let row=1;row<densifyRowsAhead;++row){if(objects[row][col]!=null){objects[0][col]=objects[row][col];break}}}}for(let row=1,rows=objects.length;row<rows;++row){for(let col=1,cols=objects[row].length;col<cols;++col){if(objects[row][col]==null){objects[row][col]=objects[row-1][col]}}}if(densifyOutputItv<=0){return objects}let itv=new Array;let nextTime=this.cutoffInterval(objects[0][0],densifyOutputItv);let millis=nextTime;let row=0;let rows=objects.length;let lastpos=-1;let pos=0;do{while(millis==nextTime){if(++row>=rows){break}millis=this.cutoffInterval(objects[row][0],densifyOutputItv)}pos=row-1;if(lastpos!=pos){objects[pos][0]=nextTime;itv.push(objects[pos]);lastpos=pos}else{let objcopy=[...objects[pos]];objcopy[0]=nextTime;itv.push(objcopy)}nextTime=nextTime+densifyOutputItv}while(row<rows);return itv}object1s(){return this.sampling(1e3)}sampling(frequency){if(frequency<=1){throw"Sampling frequency must be greater than 1"}let oread=null;switch(this._signalQueueMode){case"first":oread=new VDataObjectsSeriesFirstMode(this._series,this._signalFilter,this._columnExpandMode,this._qualifiedExpandName,this._startTime,this._endTime);break;default:oread=new VDataObjectsSeriesReader(this._series,this._signalFilter,this._columnExpandMode,this._qualifiedExpandName,this._startTime,this._endTime)}return oread.sampling(frequency)}cutoffInterval(time,interval){let millis=Math.floor(time);let cutoff=Math.floor(millis/interval)*interval;return millis>cutoff?cutoff+interval:cutoff}}class VDataDecoder{static get pako(){return require("pako")}static get fzstd(){return require("fzstd")}constructor(reader,meta){this._reader=reader;this._meta=meta;this._signals=new Set;this._prefixes=new Set;this._insensitiveCase=false;this._readLivingData=true;this._queryFilter=true;this._queryStartTime=0;this._queryEndTime=0;this._columnExpandMode=null;this._qualifiedExpandName=false;this._signalQueueMode=null;this._buckets=null;this._keys=null}get[Symbol.toStringTag](){if(this._meta==null){return"{}"}return"{start="+(this._meta.queryStartTime()>0?String(this._meta.queryStartTime()):String(this._meta.storageStartTime()))+", end="+(this._meta.queryEndTime()>0?String(this._meta.queryEndTime()):String(this._meta.storageEndTime()))+", buckets="+String(this._buckets.length)+", keys="+String(Object.keys(this._keys).length)+"}"}setSignalFilter(signalFilter){if(signalFilter!=null){this._signals=signalFilter.getSignals();this._prefixes=signalFilter.getPrefixes()}else{this._signals.clear();this._prefixes.clear()}}setInsensitiveCase(insensitiveCase){this._insensitiveCase=insensitiveCase}setReadLivingData(readLivingData){this._readLivingData=readLivingData}setQueryFilter(queryFilter){this._queryFilter=queryFilter}setQueryRange(qstime,qetime){this._queryStartTime=qstime;this._queryEndTime=qetime}setColumnExpandMode(columnExpandMode){this._columnExpandMode=columnExpandMode}setSignalQueueMode(signalQueueMode){this._signalQueueMode=signalQueueMode}setSignalDeocders(signalDecoders){this._signalDecoders=signalDecoders}initialize(){const hasSignalFilter=this._signals.size>0||this._prefixes.size>0;let formulas={};this._keys={};this._columnExpandMode=VDataUtils.getColumnExpandMode(this._columnExpandMode);this._qualifiedExpandName=VDataUtils.isQualifiedExpandName(this._columnExpandMode);const formatVersion=this._meta.formatVersion();const compressMethod=this._meta.compressMethod();const encryptMethod=this._meta.encryptMethod();const blocksCount=this._meta.blocksCount();if(this._queryStartTime==0&&this._meta.queryStartTime()==0){this._queryStartTime=this._meta.storageStartTime()}if(this._queryEndTime==0&&this._meta.queryEndTime()==0){this._queryEndTime=this._meta.storageEndTime()}console.log("file format verion: "+formatVersion);console.log("file bucket count: "+blocksCount);if(formatVersion>=26){console.log("file query start time: "+this._meta.queryStartTime());console.log("file query end time: "+this._meta.queryEndTime())}if(this._meta.pageSize()!=32768){this.readKeys()}else{this.readStfKeys()}for(let[_,key]of Object.entries(this._keys)){formulas[key._seriesid]=key._formula;if(this._signalDecoders!=undefined&&this._signalDecoders[key._name]!=undefined){if(key._formula instanceof VDataFormulaBlob){let de=this._signalDecoders[key._name];key._formula.setSignalDeocder(de)}else{key._formula=new VDataFormulaBlob(key._name);key._formula.setSignalDeocder(this._signalDecoders[key._name]);formulas[key._seriesid]=key._formula}}}this._buckets=[];for(let b=0;b<blocksCount;++b){let crc=0;let length=0;let bucketCycle=0;let bucketStartTime=0;let bucketEndTime=0;let living=0;let blobCompressType=0;let position=0;let dataStartTime=0;let dataEndTime=0;let blobCount=0;let blobDataLength=0;let blobCrc=0;if(formatVersion<24){crc=this.readLong(this._reader.read(8));living=this._reader.read(1)&1;this._reader.read(7);length=this.readInt(this._reader.read(4))-24;this._reader.read(4)}else if(formatVersion<27){crc=this.readLong(this._reader.read(8));living=this._reader.read(1)&1;this._reader.read(3);bucketCycle=this.readInt(this._reader.read(4));bucketStartTime=this.readLong(this._reader.read(8));bucketEndTime=this.readLong(this._reader.read(8));length=this.readInt(this._reader.read(4))-40;this._reader.read(4)}else{if(this._meta.pageSize()!=32768){crc=this.readLong(this._reader.read(8));living=this._reader.read(1)&1;this._reader.read(3);bucketCycle=this.readInt(this._reader.read(4));bucketStartTime=this.readLong(this._reader.read(8));bucketEndTime=this.readLong(this._reader.read(8));length=this.readInt(this._reader.read(4))-72;position=this.readInt(this._reader.read(4));dataStartTime=this.readLong(this._reader.read(8));dataEndTime=this.readLong(this._reader.read(8));blobCrc=this.readLong(this._reader.read(8));blobCount=this.readInt(this._reader.read(4));blobDataLength=this.readInt(this._reader.read(4))}else{crc=this.readLong(this._reader.read(8));living=this._reader.read(1)&1;this._reader.read(3);bucketCycle=this.readInt(this._reader.read(4));bucketStartTime=this.readLong(this._reader.read(8));bucketEndTime=this.readLong(this._reader.read(8));length=this.readInt(this._reader.read(4))-48;position=this.readInt(this._reader.read(4));blobCount=this.readInt(this._reader.read(4));blobDataLength=this.readInt(this._reader.read(4))}}if(length<=0){throw"FORMAT_VDATA_BUCKET_LENGTH_INVALID"}let databytes=this.decompress(this._reader.read(length),compressMethod);let blobDatabytes=[];if(blobDataLength>0){blobDatabytes=this.decompress(this._reader.read(blobDataLength),compressMethod)}if(crc!=0){if(crc!=this.crc32(databytes)){throw"FORMAT_VDATA_CRC_MISMATCH"}}if(living!=0&&!this._readLivingData){continue}let seriesCount=0;let activePages=0;let seriesMetas=[];let storageIdHighs=[];let storageIdLows=[];let seriesIds=[];let storageIdLength=this._meta.storageIdLength();seriesCount=this.readInt(databytes.slice(0,4));activePages=this.readInt(databytes.slice(4,8));if(seriesCount<=0){throw"FORMAT_VDATA_SERIES_COUNT_ZERO"}if(activePages<=0){throw"FORMAT_VDATA_ACTIVE_PAGES_ZERO"}let index=8;if(this._meta.pageSize()!=32768){for(let i=0;i<seriesCount;++i,index+=4){seriesIds.push(this.readInt(databytes.slice(index,index+4)))}for(let i=0;i<seriesCount;++i,index+=8){let storageidbt=databytes.slice(index,index+8);storageIdHighs.push(this.readUInt(storageidbt,4));storageIdLows.push(this.readUInt(storageidbt,0))}}else{for(let i=0;i<this._keyIds.length;++i){if((databytes[index+(i>>3)]>>(i&7)&1)==1){seriesIds.push(this._keyIds[i])}}index+=Math.floor((this._keyIds.length+7)/8);for(let i=0;i<seriesCount;++i,index+=storageIdLength){let storageidbt=databytes.slice(index,index+storageIdLength);if(storageIdLength==5){storageIdHighs.push(storageidbt[4]&255)}else{storageIdHighs.push((storageidbt[4]|storageidbt[5]<<8)&65535)}storageIdLows.push(this.readUInt(storageidbt,0))}}let blobSeriesIds=[];let blobOffsetVec=[];let blobLengthVec=[];let sid_to_blob_idx={};for(let i=0;i<blobCount;++i,index+=4){blobSeriesIds.push(this.readInt(databytes.slice(index,index+4)));sid_to_blob_idx[blobSeriesIds[i]]=i}for(let i=0;i<blobCount;++i,index+=4){blobOffsetVec.push(this.readInt(databytes.slice(index,index+4)))}for(let i=0;i<blobCount;++i,index+=4){blobLengthVec.push(this.readInt(databytes.slice(index,index+4)))}for(let i=0;i<seriesCount;++i){if(seriesIds[i]in formulas==false){throw"FORMAT_VDATA_SERIES_NOT_FOUND: "+String(seriesIds[i])}if(hasSignalFilter&&!VDataSeriesUtils.serieMatchSignalFilter(this._signals,this._prefixes,formulas[seriesIds[i]],this._columnExpandMode,this._qualifiedExpandName)){continue}const mt=new VDataSeriesMeta(formulas[seriesIds[i]],storageIdHighs[i],storageIdLows[i],this._meta.pageSize(),storageIdLength);if(mt.dataLength()==0||mt.itemCount()==0){throw"FORMAT_VDATA_SERIES_DATA_EMPTY: "+mt.name()}seriesMetas.push(mt)}let bucket=new VDataBucket;bucket.setStartTime(bucketStartTime);bucket.setEndTime(bucketEndTime);bucket.setCycle(bucketCycle);bucket.setLiving(living);bucket.setCrc(crc);for(let i=0,s=seriesMetas.length;i<s;++i){const mt=seriesMetas[i];let bstart=index+mt.pageIndex()*this._meta.pageSize()+mt.pageOffset();let bend=bstart+mt.dataLength();let bt=databytes.slice(bstart,bend);let seriesBucket=new VDataSeriesBucket;seriesBucket.setFormatVersion(formatVersion);seriesBucket.setMeta(mt);seriesBucket.setPage(bt);seriesBucket.setBucketCycle(bucketCycle);seriesBucket.setBucketStartTime(bucketStartTime);seriesBucket.setBucketEndTime(bucketEndTime);seriesBucket.setSeriesTimestampLength(this._meta.seriesTimestampLength());if(sid_to_blob_idx[i]!=undefined){let idx=sid_to_blob_idx[i];let seriesBlobData=blobDatabytes.slice(blobOffsetVec[idx],blobOffsetVec[idx]+blobLengthVec[idx]);seriesBucket.setBlobData(seriesBlobData)}if(seriesBucket.getItemCount()>0){bucket.addSeriesBucket(seriesBucket)}}if(bucket.getSeriesBuckets().length>0){if(bucket.getStartTime()==0){let serieDecoders=VDataSeriesDecodeBuilder.builds(bucket.getSeriesBuckets());let minSeriesStartTime=serieDecoders[0].time();for(let i=1;i<serieDecoders.length;++i){let tm=serieDecoders[i].time();if(tm<minSeriesStartTime){minSeriesStartTime=tm}}bucket.setStartTime(minSeriesStartTime);bucket.setNotime(1)}VDataBucketUtils.sortAddBucket(this._buckets,bucket,false,this._signalQueueMode)}}VDataBucketUtils.updateBucketQueryRange(this._buckets,this._meta,this._signalQueueMode,this._queryFilter,this._queryStartTime,this._queryEndTime)}readKeys(){const compressMethod=this._meta.compressMethod();const keysCount=this.readInt(this._reader.read(4));let length=this.readInt(this._reader.read(4));if(keysCount<=0){throw"FORMAT_VDATA_KEYS_COUNT_INVALID"}if(length<=0){throw"FORMAT_VDATA_KEYS_LENGTH_INVALID"}let databytes=this.decompress(this._reader.read(length),compressMethod);let fmbulider=new VDataFormulaFactory;let datareader=new VDataByteReader(databytes);for(let i=0;i<keysCount;++i){const keyid=this.readInt(datareader.read(4));let keyname=[];let b=datareader.read(1);while(b[0]!=0){keyname.push(b[0]);b=datareader.read(1)}if(keyname.length==0){throw"FORMAT_VDATA_KEY_NAME_EMPTY"}let desc=(new TextDecoder).decode(new Uint8Array(keyname));let formula=fmbulider.build(desc,this._insensitiveCase);let sname=this.getUniqueName(this._keys,formula._name);if(sname!=formula._name){console.log("Replace series "+String(keyid)+" duplicate name {"+formula._name+"} with name {"+sname+"}");formula._name=sname}this._keys[sname]=new VDataSeriesSpec(sname,keyid,formula,desc)}}readStfKeys(){const keysCount=this.readInt(this._reader.read(4));let length=this.readInt(this._reader.read(4));if(keysCount<=0){throw"FORMAT_VDATA_KEYS_COUNT_INVALID"}if(length<=0){throw"FORMAT_VDATA_KEYS_LENGTH_INVALID"}let formulaNone=new VDataFormulaNone("keys");let databytes=this._reader.read(length);let decode=new VDataInt32DeltaDecode(databytes,formulaNone,new BitTracker);this._keyIds=[];for(var i=0;i<keysCount;i++){decode.next();let keyid=decode.get();let sname="0x"+keyid.toString(16).padStart(8,"0").toUpperCase();this._keyIds.push(keyid);this._keys[sname]=new VDataSeriesSpec(sname,keyid,new VDataFormulaNone(sname),sname)}}readInt(_bytes){return new DataView(new Uint8Array(_bytes).buffer).getInt32(0,true)}readUInt(_bytes,offset){return new DataView(new Uint8Array(_bytes).buffer).getUint32(offset,true)}readLong(_bytes){return Number(new DataView(new Uint8Array(_bytes).buffer).getBigInt64(0,true))}crc32(_bytes){const a_table="00000000 77073096 EE0E612C 990951BA 076DC419 706AF48F E963A535 9E6495A3 0EDB8832 79DCB8A4 E0D5E91E 97D2D988 09B64C2B 7EB17CBD E7B82D07 90BF1D91 1DB71064 6AB020F2 F3B97148 84BE41DE 1ADAD47D 6DDDE4EB F4D4B551 83D385C7 136C9856 646BA8C0 FD62F97A 8A65C9EC 14015C4F 63066CD9 FA0F3D63 8D080DF5 3B6E20C8 4C69105E D56041E4 A2677172 3C03E4D1 4B04D447 D20D85FD A50AB56B 35B5A8FA 42B2986C DBBBC9D6 ACBCF940 32D86CE3 45DF5C75 DCD60DCF ABD13D59 26D930AC 51DE003A C8D75180 BFD06116 21B4F4B5 56B3C423 CFBA9599 B8BDA50F 2802B89E 5F058808 C60CD9B2 B10BE924 2F6F7C87 58684C11 C1611DAB B6662D3D 76DC4190 01DB7106 98D220BC EFD5102A 71B18589 06B6B51F 9FBFE4A5 E8B8D433 7807C9A2 0F00F934 9609A88E E10E9818 7F6A0DBB 086D3D2D 91646C97 E6635C01 6B6B51F4 1C6C6162 856530D8 F262004E 6C0695ED 1B01A57B 8208F4C1 F50FC457 65B0D9C6 12B7E950 8BBEB8EA FCB9887C 62DD1DDF 15DA2D49 8CD37CF3 FBD44C65 4DB26158 3AB551CE A3BC0074 D4BB30E2 4ADFA541 3DD895D7 A4D1C46D D3D6F4FB 4369E96A 346ED9FC AD678846 DA60B8D0 44042D73 33031DE5 AA0A4C5F DD0D7CC9 5005713C 270241AA BE0B1010 C90C2086 5768B525 206F85B3 B966D409 CE61E49F 5EDEF90E 29D9C998 B0D09822 C7D7A8B4 59B33D17 2EB40D81 B7BD5C3B C0BA6CAD EDB88320 9ABFB3B6 03B6E20C 74B1D29A EAD54739 9DD277AF 04DB2615 73DC1683 E3630B12 94643B84 0D6D6A3E 7A6A5AA8 E40ECF0B 9309FF9D 0A00AE27 7D079EB1 F00F9344 8708A3D2 1E01F268 6906C2FE F762575D 806567CB 196C3671 6E6B06E7 FED41B76 89D32BE0 10DA7A5A 67DD4ACC F9B9DF6F 8EBEEFF9 17B7BE43 60B08ED5 D6D6A3E8 A1D1937E 38D8C2C4 4FDFF252 D1BB67F1 A6BC5767 3FB506DD 48B2364B D80D2BDA AF0A1B4C 36034AF6 41047A60 DF60EFC3 A867DF55 316E8EEF 4669BE79 CB61B38C BC66831A 256FD2A0 5268E236 CC0C7795 BB0B4703 220216B9 5505262F C5BA3BBE B2BD0B28 2BB45A92 5CB36A04 C2D7FFA7 B5D0CF31 2CD99E8B 5BDEAE1D 9B64C2B0 EC63F226 756AA39C 026D930A 9C0906A9 EB0E363F 72076785 05005713 95BF4A82 E2B87A14 7BB12BAE 0CB61B38 92D28E9B E5D5BE0D 7CDCEFB7 0BDBDF21 86D3D2D4 F1D4E242 68DDB3F8 1FDA836E 81BE16CD F6B9265B 6FB077E1 18B74777 88085AE6 FF0F6A70 66063BCA 11010B5C 8F659EFF F862AE69 616BFFD3 166CCF45 A00AE278 D70DD2EE 4E048354 3903B3C2 A7672661 D06016F7 4969474D 3E6E77DB AED16A4A D9D65ADC 40DF0B66 37D83BF0 A9BCAE53 DEBB9EC5 47B2CF7F 30B5FFE9 BDBDF21C CABAC28A 53B39330 24B4A3A6 BAD03605 CDD70693 54DE5729 23D967BF B3667A2E C4614AB8 5D681B02 2A6F2B94 B40BBE37 C30C8EA1 5A05DF1B 2D02EF8D";const b_table=a_table.split(" ").map((function(s){return parseInt(s,16)}));let crc=-1;for(let i=0,s=_bytes.length;i<s;++i){crc=crc>>>8^b_table[(crc^_bytes[i])&255]}return(crc^-1)>>>0}getUniqueName(keys,key){if(key in keys==false){return key}let counter=2;let backup=key+"_duplicate_"+String(counter).padStart(5,"0");while(backup in keys&&counter<1e5){counter=counter+1;backup=key+"_duplicate_"+String(counter).padStart(5,"0")}if(counter==1e5){throw"FORMAT_VDATA_KEY_NAME_BACKUP_EXHAUSTED: "+key}return backup}decompress(_bytes,_compressMethod){if(_compressMethod==1){return pako.inflate(_bytes)}if(_compressMethod==3){return fzstd.decompress(_bytes)}return _bytes}buckets(){return this._buckets}keys(){return this._keys}meta(){return this._meta}}class VDataBucketUtils{static sortAddBucket(buckets,bucket,dropMultiFileIntersects,signalQueueMode){if(VDataUtils.isAllSignalQueueMode(signalQueueMode)){VDataBucketUtils.sortAllBucketForAllQueueMode(buckets,bucket,dropMultiFileIntersects)}else{VDataBucketUtils.sortAllBucketForSingleQueueMode(buckets,bucket)}}static _getSeriesNameSet(bucket){let names=new Set;if(bucket==null||bucket.seriesBuckets==null){return names}for(let i=0;i<bucket.seriesBuckets.length;++i){names.add(bucket.seriesBuckets[i].name)}return names}static isStrictlyIdenticalBucket(left,right){if(left==null||right==null){return false}if(left.getCrc()==0||right.getCrc()==0||left.getCrc()!=right.getCrc()){return false}if(left.getStartTime()!=right.getStartTime()||left.getEndTime()!=right.getEndTime()||left.getCycle()!=right.getCycle()||left.isLiving()!=right.isLiving()){return false}if(left.seriesBuckets.length!=right.seriesBuckets.length){return false}let leftSeriesNames=VDataBucketUtils._getSeriesNameSet(left);let rightSeriesNames=VDataBucketUtils._getSeriesNameSet(right);if(leftSeriesNames.size!=rightSeriesNames.size){return false}for(let name of leftSeriesNames){if(!rightSeriesNames.has(name)){return false}}return true}static sortAllBucketForSingleQueueMode(buckets,bucket){let size=buckets.length;if(size==0){console.log("Add bucket "+String(bucket));buckets.push(bucket);return}let bucketStartTime=bucket.getStartTime();for(let i=size-1;i>=0;--i){let bk=buckets[i];let st=bk.getStartTime();if(st==bucketStartTime){if(bucket.getCrc()!=0){for(let j=i;j>=0;--j){let stbk=buckets[j];if(stbk.getStartTime()!=st){break}if(bucket.getCrc()==stbk.getCrc()){let reason="identical";console.warn("Keep "+reason+" bucket "+String(stbk)+" discard bucket "+String(bucket));return}}}console.log("Add bucket "+String(bucket));buckets.splice(i+1,0,bucket);return}else if(st<bucketStartTime){console.log("Add bucket "+String(bucket));buckets.splice(i+1,0,bucket);return}}console.log("Add bucket "+String(bucket));buckets.splice(0,0,bucket)}static sortAllBucketForAllQueueMode(buckets,bucket,dropMultiFileIntersects){let size=buckets.length;if(size==0){console.log("Add bucket "+String(bucket));buckets.push(bucket);return}let bucketStartTime=bucket.getStartTime();for(let i=size-1;i>=0;--i){let bk=buckets[i];let st=bk.getStartTime();if(VDataBucketUtils.isStrictlyIdenticalBucket(bk,bucket)){console.warn("Keep strict-identical bucket "+String(bk)+" discard bucket "+String(bucket));return}if(st<bucketStartTime){console.log("Add bucket "+String(bucket));buckets.splice(i+1,0,bucket);return}}console.log("Add bucket "+String(bucket));buckets.splice(0,0,bucket)}static updateBucketQueryRange(buckets,meta,signalQueueMode,queryFilter,queryStartTime,queryEndTime){let _qstime=queryFilter?queryStartTime>0?queryStartTime:meta.queryStartTime():0;if(VDataUtils.isAllSignalQueueMode(signalQueueMode)){let _qetime=queryFilter?queryEndTime>0?queryEndTime:meta.queryEndTime():0;for(let b=0;b<buckets.length;++b){let bucket=buckets[b];let cetime=bucket.isLiving()?Number.MAX_VALUE-1:bucket.getEndTime();let qstime=Math.max(_qstime,bucket.getStartTime());let qetime=_qetime>0?Math.min(_qetime,cetime):cetime;for(let j=0;j<bucket.seriesBuckets.length;++j){let seriesBucket=bucket.seriesBuckets[j];seriesBucket.setQueryStartTime(qstime);seriesBucket.setQueryEndTime(qetime)}}}else{let _qetime=queryFilter?queryEndTime>0?queryEndTime:meta.queryEndTime():Number.MAX_VALUE-1;for(let b=0;b<buckets.length;++b){let bucket=buckets[b];for(let j=0;j<bucket.seriesBuckets.length;++j){let seriesBucket=bucket.seriesBuckets[j];seriesBucket.setQueryStartTime(_qstime);seriesBucket.setQueryEndTime(_qetime)}}}}}class VDataSeriesSpec{constructor(name,seriesid,formula,desc){this._name=name;this._seriesid=seriesid;this._formula=formula;this._desc=desc}}class VDataSeriesUtils{static seriesToColumns(series,signalFilter,columnExpandMode,qualifiedExpandName){if(signalFilter.hasNameFilterOnly()){return Array.from(signalFilter.getSignalNames())}let allcols=[];if(columnExpandMode==DExpand.NONE){allcols=Object.keys(series)}else{for(const k in series){let ss=series[k];if(ss.numBuckets()==0){continue}let formula=ss.formula();if(formula instanceof VDataFormulaStruct||formula instanceof VDataFormulaNamedArray){for(const i in formula._formulas){let f=formula._formulas[i];if(qualifiedExpandName){allcols.push(k+"."+f._name)}else{allcols.push(f._name)}}continue}allcols.push(formula._name)}}if(signalFilter.isEmpty()){return VDataUtils.insertion_order_set_list(allcols)}let selected=[];let smap=signalFilter.getSignals();let spfx=signalFilter.getPrefixes();for(let col of allcols){if(VDataSeriesUtils.containsSignal(smap,spfx,col)){selected.push(col)}}return VDataUtils.insertion_order_set_list(selected)}static serieContainsSignal(signals,formula,columnExpandMode,qualifiedExpandName){if(columnExpandMode==DExpand.NONE){return true}if(formula instanceof VDataFormulaStruct||formula instanceof VDataFormulaNamedArray){let serieName=formula.name();for(const i in formula._formulas){let f=formula._formulas[i];let name=qualifiedExpandName?serieName+"."+f._name:f._name;if(signals.has(name)){return true}}}else{return signals.has(formula.name())}return false}static serieMatchSignalFilter(signals,prefixes,formula,columnExpandMode,qualifiedExpandName){if(columnExpandMode==DExpand.NONE){return VDataSeriesUtils.containsSignal(signals,prefixes,formula.name())}if(formula instanceof VDataFormulaStruct||formula instanceof VDataFormulaNamedArray){let serieName=formula.name();for(const i in formula._formulas){let f=formula._formulas[i];let name=qualifiedExpandName?serieName+"."+f._name:f._name;if(VDataSeriesUtils.containsSignal(signals,prefixes,name)){return true}}}else{return VDataSeriesUtils.containsSignal(signals,prefixes,formula.name())}return false}static containsSignal(signals,prefixes,name){if(signals.has(name)){return true}for(const prefix of prefixes){if(name.startsWith(prefix)){return true}}return false}static getFirstDataTime(bt){let time=bt.getFirstTime();if(time!=null){return time}let decoder=VDataSeriesDecodeBuilder.build(bt);time=decoder.time();bt.setFirstTime(time);return time}}class VDataObjectsSeriesReader{constructor(series,signalFilter,columnExpandMode,qualifiedExpandName,startTime,endTime){this._series=series;this._signalFilter=signalFilter;this._columnExpandMode=columnExpandMode;this._qualifiedExpandName=qualifiedExpandName;this._startTime=startTime;this._endTime=endTime;let timediff=this._endTime-this._startTime+1;if(timediff<=0){throw"invalid negative time range"}if(timediff>Number.MAX_VALUE){throw"time range is too big to use objects() method"}this._columns=VDataSeriesUtils.seriesToColumns(series,signalFilter,columnExpandMode,qualifiedExpandName);this._indices=new Map;for(let i=0,c=this._columns.length;i<c;++i){this._indices.set(this._columns[i],i+1)}this._colsize=this._columns.length+1}read(){if(this._series==null||this._series.length==0){return[]}let hasComplexType=false;if(this._columnExpandMode!=DExpand.NONE){for(let column in this._series){let serie=this._series[column];let fm=serie.buckets()[0].getFormula();if(fm instanceof VDataFormulaArray||fm instanceof VDataFormulaStruct){hasComplexType=true;break}}}let rawobjs=hasComplexType?this.__readComplexRawObjects():this.__readSimpleRawObjects();let objs=[];for(let rowobj of rawobjs){if(rowobj!=null){for(let row of rowobj){objs.push(row.toObjects())}}}return objs}__readComplexRawObjects(){let rows=this._endTime-this._startTime+1;let rawobjs=new Array(rows);let list=null;let vals=null;let decoders;let serie;let pval;let pname;let time;let colidx,rowidx;let millis;let subNames;let subIndices;let comps=new Array(2);let noSubNames;for(pname in this._series){serie=this._series[pname];colidx=this._indices.get(pname);decoders=VDataSeriesDecodeBuilder.builds(serie.buckets());subNames=decoders[0].getSubNames();noSubNames=subNames==null||subNames.length==0;subIndices=null;if(!noSubNames&&this._columnExpandMode!=DExpand.NONE){subIndices=new Array(subNames.length);for(let i=0,s=subNames.length;i<s;++i){let subName=this._qualifiedExpandName?pname+"."+subNames[i]:subNames[i];subIndices[i]=this._indices.get(subName)}}for(let decoder of decoders){let qstime=decoder.getQueryStartTime();let qetime=decoder.getQueryEndTime();let qenzero=qetime!=0;do{millis=decoder.timestamp();if(millis<qstime||qenzero&&millis>qetime){decoder.pollAndAdd();continue}time=decoder.time();rowidx=millis-this._startTime;if(rawobjs[rowidx]==null){list=new Array;vals=this.createValueArray(time);list.push(vals);rawobjs[rowidx]=list}else{list=rawobjs[rowidx];this.comp(list,time,colidx,subNames,subIndices,comps);if(comps[1]==1){vals=list[comps[0]]}else{vals=this.createValueArray(time);list.splice(comps[0],0,vals)}}pval=decoder.value();if(noSubNames){vals.add(colidx,pval)}else{let subValues=pval;for(let i=0,s=subNames.length;i<s;++i){if(subIndices[i]!=null){vals.add(subIndices[i],subValues[i])}}}decoder.pollAndAdd()}while(!decoder.isEmpty())}}return rawobjs}__readSimpleRawObjects(){let rows=this._endTime-this._startTime+1;let rawobjs=new Array(rows);let list=null;let vals=null;let decoders;let serie;let pname;let time;let colidx,rowidx;let millis;let comps=new Array(2);for(pname in this._series){serie=this._series[pname];colidx=this._indices.get(pname);decoders=VDataSeriesDecodeBuilder.builds(serie.buckets());for(let decoder of decoders){let qstime=decoder.getQueryStartTime();let qetime=decoder.getQueryEndTime();let qenzero=qetime!=0;do{millis=decoder.timestamp();if(millis<qstime||qenzero&&millis>qetime){decoder.pollAndAdd();continue}time=decoder.time();rowidx=millis-this._startTime;if(rawobjs[rowidx]==null){list=new Array;vals=this.createValueArray(time);list.push(vals);rawobjs[rowidx]=list}else{list=rawobjs[rowidx];this.comp(list,time,colidx,null,null,comps);if(comps[1]==1){vals=list[comps[0]]}else{vals=this.createValueArray(time);list.splice(comps[0],0,vals)}}vals.add(colidx,decoder.value());decoder.pollAndAdd()}while(!decoder.isEmpty())}}return rawobjs}sampling(frequency){if(this._series==null||this._series.length==0){return new Array}let hasComplexType=false;if(this._columnExpandMode!=DExpand.NONE){for(let column in this._series){let serie=this._series[column];let fm=serie.buckets()[0].getFormula();if(fm instanceof VDataFormulaArray||fm instanceof VDataFormulaStruct){hasComplexType=true;break}}}let objs=hasComplexType?this.__samplingComplex(frequency):this.__samplingSimple(frequency);let nonEmptyIndex=objs.length-1;w:while(nonEmptyIndex>=0){let row=objs[nonEmptyIndex];for(let i=1,s=row.length;i<s;++i){if(row[i]!=null){break w}}nonEmptyIndex--}if(nonEmptyIndex==objs.length-1){return objs}else if(nonEmptyIndex<0){return new Array}else{return objs.slice(0,nonEmptyIndex+1)}}__samplingComplex(frequency){let startFreqBase=Math.floor(this._startTime/frequency);let rows=Math.floor(this._endTime/frequency)-startFreqBase+1;let rawobjs=new Array(rows);for(let i=0;i<rows;++i){rawobjs[i]=new Array(this._colsize);rawobjs[i][0]=(startFreqBase+i)*frequency}let serie;let decoders;let colidx;let rowidx=0;let lastrowidx=-1;let pname;let subNames;let subIndices;let noSubNames;for(pname in this._series){lastrowidx=-1;serie=this._series[pname];colidx=this._indices.get(serie.name());decoders=VDataSeriesDecodeBuilder.builds(serie.buckets());subNames=decoders[0].getSubNames();noSubNames=subNames==null||subNames.length==0;subIndices=null;if(!noSubNames&&this._columnExpandMode!=DExpand.NONE){subIndices=new Array(subNames.length);for(let i=0,s=subNames.length;i<s;++i){let subName=this._qualifiedExpandName?pname+"."+subNames[i]:subNames[i];subIndices[i]=this._indices.get(subName)}}for(let decoder of decoders){do{rowidx=Math.floor(decoder.timestamp()/frequency)-startFreqBase;if(rowidx!=lastrowidx&&rowidx>=0&&rowidx<rows){lastrowidx=rowidx;if(noSubNames){if(rawobjs[rowidx][colidx]==null){rawobjs[rowidx][colidx]=decoder.value()}}else{let subValues=decoder.value();for(let i=0,s=subNames.length;i<s;++i){if(subIndices[i]!=null&&rawobjs[rowidx][subIndices[i]]==null){rawobjs[rowidx][subIndices[i]]=subValues[i]}}}}decoder.pollAndAdd()}while(!decoder.isEmpty())}}return rawobjs}__samplingSimple(frequency){let startFreqBase=Math.floor(this._startTime/frequency);let rows=Math.floor(this._endTime/frequency)-startFreqBase+1;let rawobjs=new Array(rows);for(let i=0;i<rows;++i){rawobjs[i]=new Array(this._colsize);rawobjs[i][0]=(startFreqBase+i)*frequency}let pname;let serie;let decoders;let colidx;let rowidx=0;let lastrowidx=-1;for(pname in this._series){lastrowidx=-1;serie=this._series[pname];colidx=this._indices.get(serie.name());decoders=VDataSeriesDecodeBuilder.builds(serie.buckets());for(let decoder of decoders){do{rowidx=Math.floor(decoder.timestamp()/frequency)-startFreqBase;if(rowidx!=lastrowidx&&rowidx>=0&&rowidx<rows){lastrowidx=rowidx;if(rawobjs[rowidx][colidx]==null){rawobjs[rowidx][colidx]=decoder.value()}}decoder.pollAndAdd()}while(!decoder.isEmpty())}}return rawobjs}createValueArray(time){return new VDataDenseArray(time,this._colsize)}comp(arrs,time,colidx,subNames,subIndices,result){VDataObjectsUtils.compareUniqueMode(arrs,time,result)}}class VDataObjectsSeriesFirstMode extends VDataObjectsSeriesReader{constructor(series,signalFilter,columnExpandMode,qualifiedExpandName,startTime,endTime){super(series,signalFilter,columnExpandMode,qualifiedExpandName,startTime,endTime)}createValueArray(time){return new VDataDenseArrayFirstMode(time,this._colsize)}}class VDataObjectsSeriesAllMode extends VDataObjectsSeriesReader{constructor(series,signalFilter,columnExpandMode,qualifiedExpandName,startTime,endTime){super(series,signalFilter,columnExpandMode,qualifiedExpandName,startTime,endTime)}createValueArray(time){return new VDataDenseArray(time,this._colsize)}comp(arrs,time,colidx,subNames,subIndices,result){VDataObjectsUtils.compareAllMode(arrs,time,this._columnExpandMode,colidx,subNames,subIndices,result)}}class VDataObjectsUtils{static compareUniqueMode(arrs,time,result){let size=arrs.length;let subtime=0;let comp=0;result[0]=result[1]=0;let low=0;let high=size-1;let mid=0;do{mid=Math.floor((low+high)/2);subtime=arrs[mid].getTime();comp=time-subtime;if(comp==0){result[0]=mid;result[1]=1;return}else if(comp<0){high=mid-1}else{low=mid+1}}while(high>low);if(high==low){subtime=arrs[low].getTime();comp=time-subtime;if(comp==0){result[0]=low;result[1]=1}else if(comp<0){result[0]=low}else{result[0]=low+1}}else if(comp<0){result[0]=mid}else{result[0]=mid+1}}static compareAllMode(arrs,time,expand,colidx,subNames,subIndices,result){let size=arrs.length;let subtime=0;let comp=0;result[0]=result[1]=0;let low=0;let high=size-1;let mid=0;do{mid=Math.floor((low+high)/2);subtime=arrs[mid].getTime();comp=time-subtime;if(comp==0){let vals=arrs[mid];if(VDataObjectsUtils.isEmptyAt(vals,expand,colidx,subNames,subIndices)){while(mid-1>=0){vals=arrs[mid-1];if(time!=vals.getTime()){break}if(!VDataObjectsUtils.isEmptyAt(vals,expand,colidx,subNames,subIndices)){break}mid--}result[0]=mid;result[1]=1;return}else{while(mid+1<size){vals=arrs[mid+1];if(time!=vals.getTime()){result[0]=mid+1;return}if(VDataObjectsUtils.isEmptyAt(vals,expand,colidx,subNames,subIndices)){result[0]=mid+1;result[1]=1;return}mid++}result[0]=mid+1;return}}else if(comp<0){high=mid-1}else{low=mid+1}}while(high>low);if(high==low){subtime=arrs[low].getTime();comp=time-subtime;if(comp==0){let vals=arrs[low];if(VDataObjectsUtils.isEmptyAt(vals,expand,colidx,subNames,subIndices)){while(low-1>=0&&time==arrs[low-1].getTime()){low--}result[0]=low;result[1]=1;return}else{while(low+1<size){if(time!=arrs[low+1].getTime()){result[0]=low+1;return}if(VDataObjectsUtils.isEmptyAt(arrs[low+1],expand,colidx,subNames,subIndices)){result[0]=low+1;result[1]=1;return}low++}result[0]=low+1}}else if(comp<0){result[0]=low}else{result[0]=low+1}}else if(comp<0){result[0]=mid}else{result[0]=mid+1}}static isEmptyAt(vals,expand,colidx,subNames,subIndices){if(subNames==null||expand==DExpand.NONE){return vals.isEmptyAt(colidx)}else{for(let i=0,s=subNames.length;i<s;++i){if(subIndices[i]!=null){if(!vals.isEmptyAt(subIndices[i])){return false}}}}return true}}class VDataReaderFactory{constructor(){this._readers=null;this._signals=null;this._insensitiveCase=false;this._readLivingData=true;this._queryFilter=true;this._queryStartTime=0;this._queryEndTime=0;this._columnExpandMode=null;this._signalQueueMode=null;this._signalDecoders=null}setDataReaders(readers){this._readers=readers}setSignals(signals){this._signals=signals}setInsensitiveCase(insensitiveCase){this._insensitiveCase=insensitiveCase}setReadLivingData(readLiving){this._readLivingData=readLiving}setQueryFilter(filter){this._queryFilter=filter}setQueryStartTime(time){this._queryStartTime=time}setQueryEndTime(time){this._queryEndTime=time}setColumnExpandMode(mode){this._columnExpandMode=mode}setSignalQueueMode(mode){this._signalQueueMode=mode}setSignalDeocders(signalDecoders){this._signalDecoders=signalDecoders}open(){return new VDataReader(this._readers,this._signals,this._insensitiveCase,this._queryFilter,this._queryStartTime,this._queryEndTime,this._readLivingData,this._columnExpandMode,this._signalQueueMode,this._signalDecoders)}}class VDataReader{constructor(readers,signals=null,insensitiveCase=false,queryFilter=true,queryStartTime=0,queryEndTime=0,readLivingData=true,columnExpandMode=null,signalQueueMode=null,signalDecoders=null){const signalFilter=this.filterSignals(signals);const ndecoders=Array.isArray(readers)?readers.length:1;this._readers=Array.isArray(readers)?readers:[readers];this._columnExpandMode=VDataUtils.getColumnExpandMode(columnExpandMode);this._signalQueueMode=VDataUtils.getSignalQueueMode(signalQueueMode);this._frame=null;this._decoders=[];this._livingDataBuffer=1e3;let buckets=[];this._signalDecoders=signalDecoders;let livingData=readLivingData;if(readLivingData){if(ndecoders>1&&VDataUtils.isAllSignalQueueMode(this._signalQueueMode)){livingData=false}}for(let i=0;i<ndecoders;++i){let reader=this._readers[i];let meta=VDataReader.getMeta(reader);let decoder=new VDataDecoder(reader,meta);decoder.setSignalFilter(signalFilter);decoder.setInsensitiveCase(insensitiveCase);decoder.setReadLivingData(livingData);decoder.setQueryFilter(queryFilter);decoder.setQueryRange(queryStartTime,queryEndTime);decoder.setColumnExpandMode(this._columnExpandMode);decoder.setSignalQueueMode(this._signalQueueMode);decoder.setSignalDeocders(this._signalDecoders);decoder.initialize();VDataDecodeUtils.sortAddDecoder(this._decoders,decoder)}let series={};if(ndecoders>1){console.log("Sort and Add buckets for "+String(ndecoders)+" files")}for(let i=0;i<ndecoders;++i){let decoder=this._decoders[i];for(const bucket of decoder.buckets()){VDataBucketUtils.sortAddBucket(buckets,bucket,true,this._signalQueueMode)}for(const[name,_]of Object.entries(decoder.keys())){if(name in series==false){series[name]=new VDataSeries(name)}}}for(let b=0;b<buckets.length;++b){let bucket=buckets[b];for(let j=0;j<bucket.seriesBuckets.length;++j){let seriesBucket=bucket.seriesBuckets[j];let serie=series[seriesBucket.name];serie.addBucket(seriesBucket);serie.updateBucketItemCounts(b,seriesBucket.getItemCount())}}this._frame=new VDataFrame(buckets,series,signalFilter,this._columnExpandMode,this._signalQueueMode);let objectStartTime=queryFilter?queryStartTime:0;let objectEndTime=0;for(let decoder of this._decoders){if(queryStartTime==0){let meta=decoder.meta();let st=Number(meta.queryStartTime()==0?meta.storageStartTime():meta.queryStartTime());if(decoder.buckets().length>0){let bucketst=Number(decoder.buckets()[0].getStartTime());if(bucketst>0&&bucketst>st){st=bucketst}}objectStartTime=objectStartTime==0?st:st<objectStartTime?st:objectStartTime}let meta=decoder.meta();let et;if(!queryFilter){et=Number(meta.storageEndTime())}else{et=Number(meta.queryEndTime()==0?meta.storageEndTime():meta.queryEndTime())}if(et==0){let dbuckets=decoder.buckets();for(let i=0;i<dbuckets.length;++i){let bet=Number(dbuckets[i].getEndTime());if(bet>et){et=bet}}}objectEndTime=objectEndTime==0?et:et>objectEndTime?et:objectEndTime;if(meta.queryEndTime()==0){let dbuckets=decoder.buckets();if(dbuckets.length>0&&dbuckets[dbuckets.length-1].isLiving()){objectEndTime=objectEndTime+this._livingDataBuffer}}}objectStartTime=Number(objectStartTime);objectEndTime=Number(objectEndTime);if(queryFilter){if(queryStartTime>objectStartTime){objectStartTime=Number(queryStartTime)}if(queryEndTime!=0&&queryEndTime<objectEndTime){objectEndTime=Number(queryEndTime)}if(objectStartTime>objectEndTime){objectEndTime=objectStartTime}}this._frame.setStartTime(objectStartTime);this._frame.setEndTime(objectEndTime)}filterSignals(signals){let signalFilter=new VDataSignalFilter;if(signals==null||signals.length==0){return signalFilter}if(typeof signals==="string"){signals=signals.split(",")}let fsignals=[];let fprefixes=[];for(const s of signals){if(s==null){continue}let name=s.trim();if(name.length==0){continue}if(name[name.length-1]=="*"){do{name=name.substring(0,name.length-1)}while(name.length>0&&name[name.length-1]=="*");if(name.length==0){return signalFilter}fprefixes.push(name)}else{fsignals.push(name)}}signalFilter.setSignals(fsignals);signalFilter.setPrefixes(fprefixes);return signalFilter}static readInt8(_bytes){return new DataView(new Uint8Array(_bytes).buffer).getUint8(0)}static readUint16(_bytes){return new DataView(new Uint8Array(_bytes).buffer).getUint16(0,true)}static readInt32(_bytes){return new DataView(new Uint8Array(_bytes).buffer).getInt32(0,true)}static readUInt32(_bytes){return new DataView(new Uint8Array(_bytes).buffer).getUint32(0,true)}static readLong(_bytes){return Number(new DataView(new Uint8Array(_bytes).buffer).getBigInt64(0,true))}static readInt64(_bytes){return new DataView(new Uint8Array(_bytes).buffer).getBigInt64(0,true)}df(){return this._frame}static getMeta(_reader){if((new TextDecoder).decode(_reader.read(2))!="SD"){throw"FORMAT_VDATA_MAGIC_NUMBER_INVALID"}const formatFlags=VDataReader.readInt8(_reader.read(1));const compressMethod=formatFlags&15;const encryptMethod=formatFlags>>4&15;const formatVersion=VDataReader.readInt8(_reader.read(1));const blocksCount=VDataReader.readInt32(_reader.read(4));if(blocksCount<=0){throw"FORMAT_VDATA_BLOCKS_COUNT_INVALID"}let sstime=0;let setime=0;let qstime=0;let qetime=0;let extlength=0;let pageSizeCode=0;let keyTypeCode=0;let flag=0;if(formatVersion>0){if(formatVersion<26){sstime=VDataReader.readLong(_reader.read(8));setime=VDataReader.readLong(_reader.read(8))}else{sstime=VDataReader.readLong(_reader.read(8));setime=VDataReader.readLong(_reader.read(8));qstime=VDataReader.readLong(_reader.read(8));qetime=VDataReader.readLong(_reader.read(8))}extlength=VDataReader.readUint16(_reader.read(2));if(formatVersion>26){pageSizeCode=_reader.read(1)[0]&255;keyTypeCode=_reader.read(1)[0]&255;flag=VDataReader.readUInt32(_reader.read(4))}else{_reader.read(6)}}const extbytes=extlength>0?_reader.read(extlength):new Uint8Array(0);return new VDataMeta(formatVersion,compressMethod,encryptMethod,blocksCount,sstime,setime,qstime,qetime,extbytes,pageSizeCode,keyTypeCode,flag)}}module.exports={VDataByteReader:VDataByteReader,VDataReader:VDataReader,VDataReaderFactory:VDataReaderFactory,VDataFrame:VDataFrame,VDataMeta:VDataMeta,DExpand:DExpand,VDataSignalDecoder:VDataSignalDecoder};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "exceeddata-sdk-vdata",
|
|
3
|
-
"version": "2.10.
|
|
3
|
+
"version": "2.10.8",
|
|
4
4
|
"description": "This repository contains vsw decode libary for EXD vData SDK for Javascript package (exceeddata-sdk-vdata). vData is an edge database running on vehicles' domain controllers. It stores signal data in a high-compression file format with the extension of .vsw. EXD vData SDK offers vsw decoding capabilities in standard programming languages such as C++, Java, Python, Javascript, and etc. ",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|