cbor

package
v0.8.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 3 Imported by: 0

README

cbor

import "github.com/kitsunium/sdk/pkg/v1/data/codec/cbor"

Package cbor registers the CBOR codec with the SDK's codec registry — and no other codec — when it is imported (ADR 0134):

import _ "github.com/kitsunium/sdk/pkg/v1/data/codec/cbor"

The codec is RFC 8949 written on the standard library: maps, arrays, the integers and floats, text and byte strings, tags 0 to 3 for times and big numbers, struct fields by their cbor tag or their json tag. Map pairs are written sorted by their encoded key, the deterministic encoding of RFC 8949 §4.2.1, so one value always encodes to the same bytes. Input is checked whole — well-formed, valid, within its bounds — before the target is written. It streams.

Everything that dispatches through the registry by format name then reads and writes it: the codec package's Marshal and Unmarshal, config.FSSource and i18n.LoadFS. Importing github.com/kitsunium/sdk/pkg/v1/data/codec instead registers every format the SDK ships; this package links this one codec, the core package declaring its codes and the standard library, and nothing else. Importing both is harmless: a format is registered by the package that implements it, which Go initialises once however many packages import it.

Errors

Failures carry the range 0.3.6.*; match them with errs.HasCode, or the sentinels with errors.Is:

CodeMarshalFailed    0.3.6.1  a value CBOR cannot carry, invalid UTF-8, nesting past the bound
CodeUnmarshalFailed  0.3.6.2  input that is not one well-formed item, or an item the target cannot hold

No error message quotes the input.

Index

Constants

const CodeMarshalFailed errs.Code = 198145

CodeMarshalFailed is 0.3.6.1: a value CBOR cannot carry, invalid UTF-8, nesting past the bound.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/cbor.CodeCBORMarshalFailed.

Code 0.3.6.1

const CodeUnmarshalFailed errs.Code = 198146

CodeUnmarshalFailed is 0.3.6.2: input that is not one well-formed item, or an item the target cannot hold.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/cbor.CodeCBORUnmarshalFailed.

Code 0.3.6.2

const Format = "cbor"

Format is the name CBOR is registered under. It is an untyped constant, so it goes wherever a format name is taken — the codec package's Marshal, config.FSSource's string, i18n.LoadFS's codec.Format — without a conversion.

Variables

var MarshalFailed *errs.Error

MarshalFailed is the sentinel of CodeMarshalFailed.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/cbor.MarshalFailed.

Code 0.3.6.1 · reason MARSHAL_FAILED · public "CBOR encoding failed"

var UnmarshalFailed *errs.Error

UnmarshalFailed is the sentinel of CodeUnmarshalFailed.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/cbor.UnmarshalFailed.

Code 0.3.6.2 · reason UNMARSHAL_FAILED · public "CBOR decoding failed"

Generated from docs/api by tools/genindex.

Documentation

Overview

Package cbor registers the CBOR codec with the SDK's codec registry — and no other codec — when it is imported (ADR 0134):

import _ "github.com/kitsunium/sdk/pkg/v1/data/codec/cbor"

The codec is RFC 8949 written on the standard library: maps, arrays, the integers and floats, text and byte strings, tags 0 to 3 for times and big numbers, struct fields by their cbor tag or their json tag. Map pairs are written sorted by their encoded key, the deterministic encoding of RFC 8949 §4.2.1, so one value always encodes to the same bytes. Input is checked whole — well-formed, valid, within its bounds — before the target is written. It streams.

Everything that dispatches through the registry by format name then reads and writes it: the codec package's Marshal and Unmarshal, config.FSSource and i18n.LoadFS. Importing github.com/kitsunium/sdk/pkg/v1/data/codec instead registers every format the SDK ships; this package links this one codec, the core package declaring its codes and the standard library, and nothing else. Importing both is harmless: a format is registered by the package that implements it, which Go initialises once however many packages import it.

Errors

Failures carry the range 0.3.6.*; match them with errs.HasCode, or the sentinels with errors.Is:

CodeMarshalFailed    0.3.6.1  a value CBOR cannot carry, invalid UTF-8, nesting past the bound
CodeUnmarshalFailed  0.3.6.2  input that is not one well-formed item, or an item the target cannot hold

No error message quotes the input.

Index

Constants

View Source
const (
	// CodeMarshalFailed is 0.3.6.1: a value CBOR cannot carry, invalid UTF-8,
	// nesting past the bound.
	CodeMarshalFailed errs.Code = corecbor.CodeCBORMarshalFailed
	// CodeUnmarshalFailed is 0.3.6.2: input that is not one well-formed item,
	// or an item the target cannot hold.
	CodeUnmarshalFailed errs.Code = corecbor.CodeCBORUnmarshalFailed
)

The error codes, range 0.3.6.*, declared in the core (ADR 0160).

View Source
const Format = "cbor"

Format is the name CBOR is registered under. It is an untyped constant, so it goes wherever a format name is taken — the codec package's Marshal, config.FSSource's string, i18n.LoadFS's codec.Format — without a conversion.

Variables

View Source
var (
	// MarshalFailed is the sentinel of [CodeMarshalFailed].
	MarshalFailed = corecbor.MarshalFailed
	// UnmarshalFailed is the sentinel of [CodeUnmarshalFailed].
	UnmarshalFailed = corecbor.UnmarshalFailed
)

The sentinels, for errors.Is: each carries the code of the same name.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL