UNPKG

@atcute/cbor

Version:

lightweight DASL dCBOR42 codec library for AT Protocol

26 lines 632 B
import { fromBase64, toBase64 } from '@atcute/multibase'; const BYTES_SYMBOL = Symbol.for('@atcute/bytes-wrapper'); export class BytesWrapper { buf; /** @internal */ [BYTES_SYMBOL] = true; constructor(buf) { this.buf = buf; } get $bytes() { return toBase64(this.buf); } toJSON() { return { $bytes: this.$bytes }; } } export const toBytes = (buf) => { return new BytesWrapper(buf); }; export const fromBytes = (bytes) => { if (bytes instanceof BytesWrapper) { return bytes.buf; } return fromBase64(bytes.$bytes); }; //# sourceMappingURL=bytes.js.map