UNPKG

cbor2

Version:

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

2 lines (1 loc) 932 B
class i{static#e=new Map;tag;contents;constructor(e,t=void 0){this.tag=e,this.contents=t}get noChildren(){return!!i.#e.get(this.tag)?.noChildren}static registerDecoder(e,t,n){const o=this.#e.get(e);return this.#e.set(e,t),o&&("comment"in t||(t.comment=o.comment),"noChildren"in t||(t.noChildren=o.noChildren)),n&&!t.comment&&(t.comment=()=>`(${n})`),o}static clearDecoder(e){const t=this.#e.get(e);return this.#e.delete(e),t}static getDecoder(e){return this.#e.get(e)}static getAllDecoders(){return new Map(this.#e)}*[Symbol.iterator](){yield this.contents}push(e){return this.contents=e,1}decode(e){const t=e?.tags?.get(this.tag)??i.#e.get(this.tag);return t?t(this,e):this}comment(e,t){const n=e?.tags?.get(this.tag)??i.#e.get(this.tag);if(n?.comment)return n.comment(this,e,t)}toCBOR(){return[this.tag,this.contents]}[Symbol.for("nodejs.util.inspect.custom")](e,t,n){return`${this.tag}(${n(this.contents,t)})`}}export{i as Tag};