UNPKG

cbor2

Version:

Encode and parse data in the Concise Binary Object Representation (CBOR) data format (RFC8949).

2 lines (1 loc) 666 B
import{MT as u,SIMPLE as n}from"./constants.js";import{writeInt as o}from"./encoder.js";class t{static KnownSimple=new Map([[n.FALSE,!1],[n.TRUE,!0],[n.NULL,null],[n.UNDEFINED,void 0]]);value;constructor(e){this.value=e}static create(e){return t.KnownSimple.has(e)?t.KnownSimple.get(e):new t(e)}toCBOR(e,i){if(i.rejectCustomSimples)throw new Error(`Cannot encode non-standard Simple value: ${this.value}`);o(this.value,e,u.SIMPLE_FLOAT)}toString(){return`simple(${this.value})`}decode(){return t.KnownSimple.has(this.value)?t.KnownSimple.get(this.value):this}[Symbol.for("nodejs.util.inspect.custom")](e,i,r){return`simple(${r(this.value,i)})`}}export{t as Simple};