Skip to content

Cbor.encode

Encodes a value into CBOR (Concise Binary Object Representation) format.

Imports

Named
import { Cbor } from 'ox'

Examples

import { Cbor } from 'ox'
 
Cbor.encode([1, 2, 3])
'0x83010203'
Cbor.encode({ foo: 'bar', baz: [1, 2, 3] })
'0xa263666f6f636261726362617a83010203'
Cbor.encode('hello', { as: 'Bytes' })
Uint8Array(6) [ 101, 104, 101, 108, 108, 111 ]

Definition

function encode<as>(
  data: unknown,
  options?: encode.Options<as>,
): encode.ReturnType<as>

Source: src/core/Cbor.ts

Parameters

data

  • Type: unknown

The value to encode.

options

  • Type: encode.Options<as>
  • Optional

Encoding options.

options.as

  • Type: "Bytes" | "Hex" | as
  • Optional

The format to return the encoded value in.

Return Type

The CBOR-encoded value.

encode.ReturnType<as>