Open Ottunger opened 1 year ago
We could solve our issue using genTypes
, specifically:
const EmbeddedCBORGenTypes = {
Uint8Array: (gen: Encoder, obj: Uint8Array) => {
if(!gen._pushTag(0b00011000)) {
return false;
}
return CBOR.Encoder._pushBuffer(gen, Buffer.from(obj))
}
};
It's not perfect but it does the job. Is it worth searching for an alternative?
You could wrap your Buffer in a Tag, like so:
const buf = cbor.encode(...)
const t = new cbor.Tagged(24, buf)
return cbor.encode(t)
When we know that resulting Buffer (or Uint8Array in case of cbor-web) is to be used as part of a larger CBOR payload, it should be encoded using tag 24.
Is there any way to pass to
encodeOne
an overwrite for the tag to apply on typed array, saybufferTagType
much like there already existsdateType
? This would be used on the top-levelencode
operation.