/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{bytesToUTF8 as e}from"./byteStreamUtils.js";function t(e){const t=e.fields,r=e.records,n=t.some(e=>"oid"===e.name.toLowerCase())?"OBJECTID":"OID",i=[{name:n,type:"esriFieldTypeOID",alias:"OID"}].concat(t.map(e=>({name:e.name,type:"esriFieldType"+e.typeName,alias:e.name}))),a=i.map(e=>e.name),s=[];let o=0,l=0;return r.forEach(e=>{const t={};for(t[n]=o++,l=1;l<a.length;l++)t[a[l]]=e[l-1];s.push({attributes:t})}),{displayFieldName:"",fields:i,features:s}}class r{static get supportedVersions(){return[5]}static parse(r){const n=new DataView(r),i=3&n.getUint8(0);if(3!==i)return{header:{version:i},recordSet:null};const a=n.getUint32(4,!0),s=n.getUint16(8,!0),o=n.getUint16(10,!0),l={version:i,recordCount:a,headerByteCount:s,recordByteCount:o};let p=32;const d=[],g=[];let h;if(3===i){for(;13!==n.getUint8(p);)h=String.fromCharCode(n.getUint8(p+11)).trim(),d.push({name:e(new Uint8Array(r,p,11)),type:h,typeName:["String","Date","Double","Boolean","String","Integer"][["C","D","F","L","M","N"].indexOf(h)],length:n.getUint8(p+16)}),p+=32;if(p+=1,d.length>0)for(;g.length<a&&r.byteLength-p>o;){const t=[];32===n.getUint8(p)?(p+=1,d.forEach(n=>{if("C"===n.type)t.push(e(new Uint8Array(r,p,n.length)).trim());else if("N"===n.type)t.push(parseInt(String.fromCharCode.apply(null,new Uint8Array(r,p,n.length)).trim(),10));else if("F"===n.type)t.push(parseFloat(String.fromCharCode.apply(null,new Uint8Array(r,p,n.length)).trim()));else if("D"===n.type){const e=String.fromCharCode.apply(null,new Uint8Array(r,p,n.length)).trim();t.push(new Date(parseInt(e.slice(0,4),10),parseInt(e.slice(4,6),10)-1,parseInt(e.slice(6,8),10)))}p+=n.length}),g.push(t)):p+=o}}return{header:l,fields:d,records:g,recordSet:t({fields:d,records:g})}}}export{r as default};
