Class CborReader

A class for reading CBOR (Concise Binary Object Representation) data.

The CborReader class provides methods for decoding and extracting various data types from a CBOR-encoded binary stream. It supports handling integers, strings, arrays, maps, and other CBOR data structures.

Properties

ptr: number

Methods

  • Retrieves the total number of unread bytes remaining in the CBOR reader's buffer.

    Returns number

    The number of unread bytes remaining in the buffer.

    If the native function call fails.

  • 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.

    Returns 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.

    Returns number

    The current reference count of the CBOR writer in the WASM context.

  • Retrieves the remaining bytes from the CBOR reader.

    Returns Uint8Array

    A Uint8Array containing the remaining bytes.

    If the native function call fails.

  • Retrieves the current state of the CBOR reader without consuming any data.

    This method allows you to inspect the next data item's type or structure in the CBOR stream without advancing the reader's position. It is useful for determining the type of the next value to decide how to process it.

    Returns CborReaderState

    The current state of the reader, represented as a CborReaderState enum value.

    If the state could not be retrieved. The error includes details of the failure.

  • Peeks the next CBOR tag (major type 6) without advancing the reader's position.

    This method examines the next CBOR-encoded tag (semantic tag) in the stream without consuming it. CBOR tags provide semantic context to the data that follows, such as indicating a timestamp or a URI. Use this method to inspect the next tag before deciding how to process it.

    Returns CborTag

    The CBOR tag at the current position, as an enum value.

    If the value at the current position is not a valid CBOR tag or if any decoding error occurs.

  • Reads a big integer (BigInt) from the CBOR stream.

    This method decodes and retrieves the next CBOR data item as a big integer. CBOR bignums are used to represent integers too large to fit into standard 64-bit representations.

    Returns BigInt

    The decoded big integer from the CBOR stream.

    If the big integer could not be read. The error includes details of the failure.

  • Reads a CBOR boolean value (true or false).

    This method decodes and reads a CBOR-encoded boolean value (major type 7, simple values 20 and 21) from the current position in the reader. It supports CBOR representations for true and false.

    Returns boolean

    The decoded boolean value (true or false).

    If the boolean value could not be read due to an invalid state or parsing error.

  • Reads a CBOR byte string.

    This method decodes a CBOR-encoded byte string (major type 2) from the current position in the reader and returns it as a Uint8Array.

    Returns Uint8Array

    A Uint8Array containing the decoded byte string.

    If the value at the current position is not a valid CBOR byte string, or if any decoding error occurs.

  • Reads a double-precision floating-point number from the CBOR stream.

    This method decodes and retrieves the next CBOR data item as a double-precision floating-point number (IEEE 754 format). It is suitable for processing CBOR items encoded as floating-point numbers.

    Returns number

    The decoded double-precision floating-point number.

    If the double could not be read. The error includes details of the failure.

  • Reads and returns the next CBOR data item in its encoded byte form.

    This method retrieves the raw encoded bytes of the next CBOR data item, preserving its exact representation in the stream. This is useful for scenarios where the encoded value needs to be stored, inspected, or reprocessed.

    Returns Uint8Array

    A Uint8Array containing the encoded bytes of the next CBOR data item.

    If the encoded value could not be read. The error includes details of the failure.

  • Reads the end of a CBOR array (major type 4).

    This method is used to signify the completion of reading a CBOR array. It validates the presence of the end marker for both definite-length and indefinite-length arrays.

    Returns void

    If the end of the array could not be read. The error message includes details about the failure reason.

  • Reads the end of a CBOR map (major type 5).

    This method ensures that the CBOR reader is positioned at the end of a map and validates that all key-value pairs have been properly read.

    Returns void

    If the end of the map could not be read. The error includes details of the failure.

  • Reads a CBOR null value.

    This method decodes and validates a CBOR-encoded null value (major type 7, simple value 22) from the current position in the reader. It ensures the value represents null and moves the reader to the next data item in the CBOR stream.

    Returns void

    If the value at the current position is not a valid CBOR null, or if any parsing error occurs.

  • Reads a signed integer from the CBOR stream.

    This method decodes and retrieves the next CBOR data item as a signed 64-bit integer. It ensures that the integer is correctly interpreted based on its signed representation.

    Returns BigInt

    The signed integer read from the CBOR stream as a BigInt.

    If the signed integer could not be read. The error includes details of the failure.

  • Reads a CBOR simple value (major type 7) from the CBOR stream.

    CBOR simple values include false, true, null, undefined, and other custom simple values represented as major type 7.

    Returns CborSimpleValue

    The decoded simple value as a CborSimpleValue enum.

    If the simple value could not be read. The error includes details of the failure.

  • Reads the start of a CBOR array (major type 4).

    This method reads the initial marker of a CBOR array and returns its length. For definite-length arrays, the length represents the number of items in the array. For indefinite-length arrays, the length will return -1, and the array will end with a special "break" marker.

    Returns number

    The number of items in the array for definite-length arrays, or -1 for indefinite-length arrays.

    If the start of the array could not be read. The error includes details of the failure.

  • Reads the beginning of a CBOR map (major type 5).

    This method reads the CBOR stream and retrieves the number of key-value pairs in the map. If the map has an indefinite length, the returned size will be -1. After calling this method, the CBOR reader state transitions to process the key-value pairs within the map.

    Returns number

    The number of key-value pairs in the map or -1 for indefinite-length maps.

    If the start of the map could not be read. The error includes details of the failure.

  • Reads a CBOR tag (major type 6).

    This method decodes a CBOR-encoded tag (semantic tag) from the current position in the reader and returns it as a CborTag value. CBOR tags provide semantic context to the data that follows them, such as indicating a timestamp or a URI.

    Returns CborTag

    The decoded CBOR tag as an enum value.

    If the value at the current position is not a valid CBOR tag or if any decoding error occurs.

  • Reads a CBOR text string.

    This method decodes a CBOR-encoded text string (major type 3) from the current position in the reader and returns it as a JavaScript string.

    Returns string

    A JavaScript string containing the decoded CBOR text string.

    If the value at the current position is not a valid CBOR text string, or if any decoding error occurs.

  • Reads an unsigned integer from the CBOR stream.

    This method decodes and retrieves the next CBOR data item as an unsigned 64-bit integer. It ensures that the integer is correctly interpreted based on its unsigned representation.

    Returns BigInt

    The unsigned integer read from the CBOR stream as a BigInt.

    If the unsigned integer could not be read. The error includes details of the failure.

  • Skips the current CBOR value in the stream.

    This function moves the reader past the current CBOR data item without decoding it. It is particularly useful when you want to ignore a value in the CBOR stream, for example, when the value is not relevant to your application logic.

    Returns void

    If the skip operation fails. The error will include the reason for failure, as reported by the underlying CBOR reader.

  • Creates a new CborReader from a binary CBOR-encoded data.

    Parameters

    • data: Uint8Array

      The CBOR-encoded binary data to be read.

    Returns CborReader

    A new instance of the CborReader class.

    If the native CborReader could not be created.

  • Creates a new CborReader from a CBOR-encoded hexadecimal string.

    Parameters

    • hexString: string

      The CBOR-encoded data in hexadecimal string format.

    Returns CborReader

    A new instance of the CborReader class.

    If the native CborReader could not be created.