CborMapDecodedStream

import { CborMapDecodedStream } from "jsr:@ende/cbor";

class

class CborMapDecodedStream extends ReadableStream<CborMapStreamOutput>

A ReadableStream that wraps the decoded CBOR "Map". RFC 8949 - Concise Binary Object Representation (CBOR)

Instances of this class is created from CborSequenceDecoderStream. This class is not designed for you to create instances of it yourself. It is merely a way for you to validate the type being returned.

Example: Usage

import { assert, assertEquals } from "@ende/assert";
import {
  CborMapDecodedStream,
  CborMapEncoderStream,
  CborSequenceDecoderStream,
} from "@ende/cbor";

const rawMessage: Record<string, number> = {
  a: 0,
  b: 1,
  c: 2,
  d: 3,
};

for await (
  const value of ReadableStream.from(Object.entries(rawMessage))
    .pipeThrough(new CborMapEncoderStream)
    .pipeThrough(new CborSequenceDecoderStream())
) {
  assert(value instanceof CborMapDecodedStream);
  for await (const [k, v] of value) {
    assertEquals(rawMessage[k], v);
  }
}

Constructors

constructor

new CborMapDecodedStream(gen: AsyncGenerator<CborMapStreamOutput>, releaseLock: ReleaseLock)

Constructs a new instance.

gen: AsyncGenerator<CborMapStreamOutput>

A AsyncGenerator.

releaseLock: ReleaseLock

A Function that's called when the stream is finished.

Source