MCPcopy Create free account
hub / github.com/denoland/std / #encode

Method #encode

cbor/sequence_encoder_stream.ts:118–146  ·  view source on GitHub ↗
(
    x: CborStreamInput,
  )

Source from the content-addressed store, hash-verified

116 }
117
118 async *#encode(
119 x: CborStreamInput,
120 ): AsyncGenerator<Uint8Array> {
121 if (
122 x instanceof CborByteEncoderStream ||
123 x instanceof CborTextEncoderStream ||
124 x instanceof CborArrayEncoderStream ||
125 x instanceof CborMapEncoderStream
126 ) {
127 for await (const y of x.readable) {
128 yield y;
129 }
130 } else if (x instanceof Array) {
131 for await (const y of this.#encodeArray(x)) {
132 yield y;
133 }
134 } else if (x instanceof CborTag) {
135 for await (const y of this.#encodeTag(x)) {
136 yield y;
137 }
138 } else if (typeof x === "object" && x !== null) {
139 if (x instanceof Date || x instanceof Uint8Array) yield encodeCbor(x);
140 else {
141 for await (const y of this.#encodeObject(x)) {
142 yield y;
143 }
144 }
145 } else yield encodeCbor(x);
146 }
147
148 async *#encodeArray(x: CborStreamInput[]): AsyncGenerator<Uint8Array> {
149 if (x.length < 24) yield new Uint8Array([0b100_00000 + x.length]);

Callers 4

#encodeFromReadableMethod · 0.95
#encodeArrayMethod · 0.95
#encodeObjectMethod · 0.95
#encodeTagMethod · 0.95

Calls 4

#encodeArrayMethod · 0.95
#encodeTagMethod · 0.95
#encodeObjectMethod · 0.95
encodeCborFunction · 0.90

Tested by

no test coverage detected