/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{estimateNumberArrayMemory as e}from"../../../../../core/memoryEstimations.js";import{getFeatureIdInfoFieldNames as t}from"../../../../../layers/graphics/data/FeatureIdInfo.js";import s from"../../../../../layers/support/FieldsIndex.js";import{parseField as r,parseTransform as o}from"../../../../../rest/query/operations/pbfFeatureServiceParser.js";const a=268435455;class n{constructor(){this.hasFeatures=!1,this.exceededTransferLimit=!1,this.hasZ=!1,this.hasM=!1,this.fieldCount=0,this.featureCount=0,this.idFieldIndices=[],this.transform=null,this.vertexCount=0,this.offsets={attributes:new Array,geometry:new Array},this.centroid=new Array,this.byReferenceVertexCounts=new Map}get usedMemory(){let t=0;return t+=e(this.idFieldIndices),t+=e(this.offsets.attributes),t+=e(this.offsets.geometry),t+=e(this.centroid),this.displayIds&&(t+=e(this.displayIds)),this.groupIds&&(t+=e(this.groupIds)),t}get stride(){return 2+Number(this.hasZ)+Number(this.hasM)}}function i(e,i,c){const d=9,f=10,u=11,h=12,p=13,g=15,l=e.asUnsafe(),m=l.pos(),k=new n;let b=0,y=0;const I=1,x=2,w=4,C=12,F=3;let L=null;const M=[];for(;l.next();)switch(l.tag()){case h:L=l.processMessage(o);break;case d:k.exceededTransferLimit=l.getBool();break;case f:k.hasZ=l.getBool();break;case u:k.hasM=l.getBool();break;case p:{const e=l.processMessage(r);e.index=b++,M.push(e);break}case g:{const e=l.getPackedEnd(),t=k.offsets.geometry,s=k.centroid;t.push(0);const{stride:r}=k;for(s.push(a),s.push(a);l.pos()<e&&l.next();)switch(l.tag()){case I:{k.offsets.attributes.push(l.pos());const e=l.getLength();l.skipLen(e);break}case x:if(i){const e=l.getPackedEnd();for(;l.pos()<e&&l.next();)switch(l.tag()){case F:{const e=l.getPackedEnd();let t=y*r;for(;l.pos()<e;)k.centroid[t++]=l.getSInt64();break}default:l.skip()}}else{k.offsets.geometry[y]=l.pos();const e=l.getLength();k.vertexCount+=e,l.skipLen(e)}break;case w:{const e=l.getLength(),t=l.pos()+e;for(;l.pos()<t&&l.next();)switch(l.tag()){case F:{const e=l.getPackedEnd();let t=y*r;for(;l.pos()<e;)k.centroid[t++]=l.getSInt64();break}default:l.skip()}break}case C:{const e=l.getUInt64();k.byReferenceVertexCounts.set(y,e);break}default:l.skip()}y++,k.hasFeatures=!0;break}default:l.skip()}k.fields=new s(M),k.featureCount=y,k.fieldCount=b;const A=t(c);return k.idFieldIndices=Array.from(A,e=>k.fields.get(e)?.index),k.transform=L,k.displayIds=new Uint32Array(k.featureCount),k.groupIds=new Uint16Array(k.featureCount),l.move(m),k}export{n as FeatureSetHeader,i as parseHeader};
