Creates a new instance of the CborWriter class.
This constructor initializes a new native CBOR writer instance and ensures it is ready for use. Throws an error if the writer instance cannot be created.
The internal pointer to the native CBOR writer instance. This pointer is managed internally and should not be modified directly.
Finalizes the CBOR encoding process and retrieves the encoded data.
This method computes the final CBOR representation of all the data items
written to the writer. It allocates and returns a Uint8Array containing
the serialized CBOR data.
A Uint8Array containing the CBOR-encoded data.
Finalizes the CBOR encoding process and retrieves the encoded data as a hexadecimal string.
This method computes the final CBOR representation of all the data items written to the writer and returns the serialized CBOR data as a hexadecimal string.
A string containing the CBOR-encoded data in hexadecimal format.
Ends the encoding of an indefinite-length CBOR array.
This method writes the stop code to indicate the end of an indefinite-length
CBOR array (major type 4). It must only be called after startArray has been
called with -1 as the size.
The current CborWriter instance.
Ends the encoding of an indefinite-length CBOR map.
This method writes the stop code to indicate the end of an indefinite-length
CBOR map (major type 5). It must only be called after startMap has been
called with -1 as the size.
The current CborWriter instance.
Retrieves the last error message recorded by the CBOR writer.
This method provides a human-readable description of the last error encountered during CBOR encoding operations. If no error has occurred, it returns an empty string.
A string describing the last error message, or empty if no message is available.
The reference count retrieved by this method reflects the number of references maintained internally by libcardano-c for this native instance of the CBOR writer object. This is unrelated to the reference counting mechanism in JavaScript, which is managed by the JavaScript engine's garbage collector.
This method is primarily intended for diagnostic purposes.
The current reference count of the CBOR writer in the WASM context.
Resets the CBOR writer, clearing all written data.
This method resets the internal state of the CBOR writer, effectively removing any data that has been written. It allows the writer to be reused for a new CBOR encoding session.
The current CborWriter instance.
Begins the encoding of a CBOR array.
This method writes the start of a CBOR array into the CBOR stream. CBOR arrays are
encoded as major type 4. The size parameter specifies the number of elements in
the array for definite-length arrays. For indefinite-length arrays, pass -1 as
the size.
Optionalsize: numberThe number of elements in the array. Use -1 for an indefinite-length array.
The current CborWriter instance.
Begins the encoding of a CBOR map.
This method writes the start of a CBOR map into the CBOR stream. CBOR maps are
encoded as major type 5. The size parameter specifies the number of key-value
pairs in the map for definite-length maps. For indefinite-length maps, pass -1
as the size.
Optionalsize: numberThe number of key-value pairs in the map. Use -1 for an indefinite-length map.
The current CborWriter instance.
Encodes and writes a BigInt value as a CBOR bignum.
This method writes a big integer value into the CBOR stream using the appropriate CBOR tag for bignum encoding. It supports both positive and negative bignums.
The BigInt value to encode and write.
The current CborWriter instance.
Encodes and writes a boolean value as a CBOR simple value.
This method writes a boolean value (true or false) into the CBOR stream.
CBOR encodes boolean values as simple values (major type 7).
The boolean value to encode and write.
The current CborWriter instance.
Encodes and writes a byte string as a CBOR data item.
This method writes a byte string (Uint8Array) into the CBOR stream. CBOR encodes
byte strings as major type 2.
The byte string to encode and write as a Uint8Array.
The current CborWriter instance.
Writes a pre-encoded CBOR data item into the CBOR stream.
This method directly writes a byte array containing a pre-encoded CBOR data item into the CBOR stream. This is useful for embedding CBOR data items that have already been encoded elsewhere.
The byte array containing the pre-encoded CBOR data item.
The current CborWriter instance.
Encodes and writes an integer as a CBOR data item.
This method writes a integer value into the CBOR stream. CBOR encodes integers as either major type 0 (positive integers) or major type 1 (negative integers).
The integer value to encode and write. This can be a number or bigint.
The current CborWriter instance.
Encodes and writes a null value as a CBOR data item.
This method writes a null value into the CBOR stream. CBOR encodes null values as
a simple value with major type 7 and additional information 22.
The current CborWriter instance.
Encodes and writes a signed integer as a CBOR data item.
This method writes a signed integer value into the CBOR stream. CBOR encodes signed integers as either major type 0 (for positive integers) or major type 1 (for negative integers).
The signed integer value to encode and write. This can be a number or bigint.
The current CborWriter instance.
Encodes and writes a CBOR semantic tag.
This method writes a semantic tag into the CBOR stream. CBOR tags are encoded as major type 6 and provide additional context or meaning for the data that follows. For example, a tag may indicate a date, a base64-encoded string, or another semantic type.
The semantic tag to encode and write, represented as a value of the CborTag enum or a number.
The current CborWriter instance.
Encodes and writes a UTF-8 encoded text string as a CBOR data item.
This method writes a text string into the CBOR stream. CBOR encodes text strings as major type 3.
The text string to encode and write.
The current CborWriter instance.
Encodes and writes an undefined value as a CBOR data item.
This method writes an undefined value into the CBOR stream. CBOR encodes undefined
values as a simple value with major type 7 and additional information 23.
The current CborWriter instance.
Encodes and writes an unsigned integer as a CBOR data item.
This method writes an unsigned integer value into the CBOR stream. CBOR encodes unsigned integers as major type 0.
The unsigned integer value to encode and write. This can be a number or bigint.
The current CborWriter instance.
A class for encoding data into the Concise Binary Object Representation (CBOR) format.
This class provides a high-level interface for constructing CBOR-encoded data items. It manages the underlying CBOR writer instance and ensures proper memory management.