/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../../../core/Error","../../../../../rest/query/operations/pbfFeatureServiceParser"],(function(e,t,s){"use strict";const r=268435455;let n=function(){function e(){this.fieldMap=new Map,this.fields=[],this.hasFeatures=!1,this.fieldCount=0,this.featureCount=0,this.objectIdFieldIndex=0,this.vertexCount=0,this.offsets={attributes:new Array,geometry:new Array},this.centroid=new Array}var t=e.prototype;return t.hasField=function(e){return this.fieldMap.has(e)},t.isDateField=function(e){var t;return null==(t=this.fieldMap.get(e))?void 0:t.isDate},t.getFieldIndex=function(e){var t;return null==(t=this.fieldMap.get(e))?void 0:t.index},e}();function a(e){const t=1,r=2,n=e.getLength(),a=e.pos()+n,i={name:"",isDate:!1};for(;e.pos()<a&&e.next();)switch(e.tag()){case t:i.name=e.getString();break;case r:"esriFieldTypeDate"===s.parseFieldType(e.getEnum())&&(i.isDate=!0);break;default:e.skip()}return i}function i(e){return e.toLowerCase().trim()}function o(e,o,f=!1){const d=1,c=3,u=9,l=12,g=13,p=15,h=e.pos(),b=new n;let m=0,w=0;const y=1,k=2,x=4,I=3;let F=null,L=null,S=null,v=!1;for(;e.next();)switch(e.tag()){case d:F=e.getString();break;case c:L=e.getString();break;case l:S=e.processMessage(s.parseTransform);break;case u:if(b.exceededTransferLimit=e.getBool(),b.exceededTransferLimit){b.offsets.geometry=f?new Float64Array(8e3):new Int32Array(8e3),b.centroid=f?new Float64Array(16e3):new Int32Array(16e3);for(let e=0;e<b.centroid.length;e++)b.centroid[e]=r}break;case g:{const t=a(e),s=t.name,r=i(t.name),n={fieldName:s,index:m++,isDate:t.isDate};b.fields.push(n),b.fieldMap.set(t.name,n),b.fieldMap.set(r,n);break}case p:{const t=e.getLength(),s=e.pos()+t;if(!b.exceededTransferLimit){const e=b.offsets.geometry,t=b.centroid;e.push(0),t.push(r),t.push(r)}!v&&b.exceededTransferLimit&&(v=!0,b.offsets.attributes=f?new Float64Array(8e3*m):new Uint32Array(8e3*m));let n=w*m;for(;e.pos()<s&&e.next();)switch(e.tag()){case y:{if(v)b.offsets.attributes[n++]=e.pos();else{b.offsets.attributes.push(e.pos())}const t=e.getLength();e.skipLen(t);break}case k:if(o){const t=e.getLength(),s=e.pos()+t;for(;e.pos()<s&&e.next();)switch(e.tag()){case I:{e.getUInt32();const t=e.getSInt64(),s=e.getSInt64();b.centroid[2*w]=t,b.centroid[2*w+1]=s;break}default:e.skip()}}else{b.offsets.geometry[w]=e.pos();const t=e.getLength();b.vertexCount+=t,e.skipLen(t)}break;case x:{const t=e.getLength(),s=e.pos()+t;for(;e.pos()<s&&e.next();)switch(e.tag()){case I:{e.getUInt32();const t=e.getSInt64(),s=e.getSInt64();b.centroid[2*w]=t,b.centroid[2*w+1]=s;break}default:e.skip()}break}default:e.skip()}w++,b.hasFeatures=!0;break}default:e.skip()}const A=F||L;if(!A)throw new t("FeatureSet has no objectId or globalId field name");return b.featureCount=w,b.fieldCount=m,b.objectIdFieldIndex=b.getFieldIndex(A),b.transform=S,b.displayIds=new Uint32Array(b.featureCount),b.groupIds=new Uint16Array(b.featureCount),e.move(h),b}e.FeatureSetHeader=n,e.parseHeader=o,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
