UNPKG

gnablib

Version:

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

2 lines 1.1 kB
/*! 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 InsertColDef{constructor(e,t,n){this.name=e,this.type=t,null!=n&&(this.default=n)}toBin(){const e=this.name.toBin(),t=this.type.toBin(),n=this.type.unknownBin(this.default),s=new Uint8Array(e.length+t.length+n.length);s.set(e);let i=e.length;return s.set(t,i),i+=t.length,s.set(n,i),s}toJSON(){const e={};return e[this.name.name]=this.type.cudType+(this.type.nullable?"?":""),null!=this.default&&(e.default=this.default),e}static fromBin(s,i=0){let o=i;const r=e.fromBin(s,i);if(!r.success)return new t(0,void 0,"InsertColDef.fromBin missing name: "+r.reason);o+=r.byteLen;const l=n(s,o);if(!l.success)return new t(0,void 0,"InsertColDef.fromBin missing type: "+l.reason);o+=l.byteLen;const u=l.value.binUnknown(s,o);return u.success?(o+=u.byteLen,new t(o-i,new InsertColDef(r.value,l.value,u.value))):new t(0,void 0,"InsertColDef.fromBin missing default: "+u.reason)}}