Class CborTag<T>
Type Parameters
- T extends CborType | CborStreamInput | CborStreamOutput
The type of the tag's content, which can be a CborType, CborStreamInput, or CborStreamOutput.
Index
Constructors
Properties
Constructors
constructor
- new
Cbor <T>(tagNumber, tagContent): CborTag<T>Tag Constructs a new instance.
Type Parameters
- T extends
| undefined
| null
| string
| number
| bigint
| boolean
| Date
| Uint8Array
| CborArrayEncoderStream
| CborTag<CborStreamInput>
| CborStreamInput[]
| {
[k: string]: CborStreamInput;
}
| CborByteEncoderStream
| CborTextEncoderStream
| CborMapEncoderStream
| CborTag<CborType>
| Map<CborType, CborType>
| CborType[]
| {
[k: string]: CborType;
}
| CborArrayDecodedStream
| CborTag<CborStreamOutput>
| CborByteDecodedStream
| CborTextDecodedStream
| CborMapDecodedStream
Parameters
Returns CborTag<T>
- T extends
Properties
tagContent
Example: Usage
import { assert, assertEquals } from "@std/assert";
import { CborTag, decodeCbor, encodeCbor } from "@std/cbor";
import { decodeBase64Url, encodeBase64Url } from "@std/encoding";
const rawMessage = new TextEncoder().encode("Hello World");
const encodedMessage = encodeCbor(
new CborTag(
33, // TagNumber 33 specifies the tagContent must be a valid "base64url" "string".
encodeBase64Url(rawMessage),
),
);
const decodedMessage = decodeCbor(encodedMessage);
assert(decodedMessage instanceof CborTag);
assert(typeof decodedMessage.tagContent === "string");
assertEquals(decodeBase64Url(decodedMessage.tagContent), rawMessage);
tagNumber
tagNumber : number | bigint
A number or bigint representing the CBOR tag number, used to identify the type of the tagged content. CBOR Tags.
Example: Usage
import { assert, assertEquals } from "@std/assert";
import { CborTag, decodeCbor, encodeCbor } from "@std/cbor";
import { decodeBase64Url, encodeBase64Url } from "@std/encoding";
const rawMessage = new TextEncoder().encode("Hello World");
const encodedMessage = encodeCbor(
new CborTag(
33, // TagNumber 33 specifies the tagContent must be a valid "base64url" "string".
encodeBase64Url(rawMessage),
),
);
const decodedMessage = decodeCbor(encodedMessage);
assert(decodedMessage instanceof CborTag);
assert(typeof decodedMessage.tagContent === "string");
assertEquals(decodeBase64Url(decodedMessage.tagContent), rawMessage);
Represents a CBOR tag, which pairs a tag number with content, used to convey additional semantic information in CBOR-encoded data. CBOR Tags.
Example: Usage