UNPKG

gnablib

Version:

A lean, zero dependency library to provide a useful base for your project.

2 lines 823 B
/*! Copyright 2023 the gnablib contributors MPL-1.1 */ import{ColName as e}from"./ColName.js";import{FromBinResult as t}from"../primitive/FromBinResult.js";import{cudColTypeFromBin as n}from"./types/cudColTypeFromBin.js";export class CreateColDef{constructor(e,t){this.name=e,this.type=t}toBin(){const e=this.name.toBin(),t=this.type.toBin(),n=new Uint8Array(e.length+t.length);n.set(e);const s=e.length;return n.set(t,s),n}toJSON(){const e={};return e[this.name.name]=this.type.cudType+(this.type.nullable?"?":""),e}static fromBin(s,o=0){let r=o;const i=e.fromBin(s,r);if(!i.success)return new t(0,void 0,"CreateColDef.fromBin missing name: "+i.reason);r+=i.byteLen;const m=n(s,r);return m.success?(r+=m.byteLen,new t(r-o,new CreateColDef(i.value,m.value))):new t(0,void 0,"CreateColDef.fromBin missing type: "+m.reason)}}