UNPKG

gnablib

Version:

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

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