import*as t from"./lib.js";import*as e from"./fields.js";export default function n(n,r){var i=r||e.multi(n),s=32*i.length+1,a=e.bytesPer(i),o=new ArrayBuffer(s+32+a*n.length+1),f=new Date,l=new DataView(o);l.setUint8(0,3),l.setUint8(1,f.getFullYear()-1900),l.setUint8(2,f.getMonth()+1),l.setUint8(3,f.getDate()),l.setUint32(4,n.length,!0);var c=s+32;l.setUint16(8,c,!0),l.setUint16(10,a,!0),l.setInt8(32+s-1,13),i.forEach((function(e,n){var r=32+32*n;t.toBuffer(e.name).slice(0,11).forEach((function(t,e){l.setInt8(r+e,t)})),l.setInt8(r+11,e.type.charCodeAt(0)),l.setInt8(r+16,e.size),"N"==e.type&&l.setInt8(r+17,3)}));var u=s+32;return n.forEach((function(e,n){l.setUint8(u,32),u++,i.forEach((function(n){var r=e[n.name];switch(null==r&&(r=""),n.type){case"L":l.setUint8(u,r?84:70),u++;break;case"D":u=t.writeField(l,8,t.writeDate(r),u);break;case"N":u=t.writeField(l,n.size,t.lpad(r.toString(),n.size," ").substr(0,18),u);break;case"C":u=t.writeField(l,n.size,t.rpad(r.toString(),n.size," "),u);break;default:throw new Error("Unknown field type")}}))})),l.setUint8(u,26),l}