baseenc

package
v0.8.3 Latest Latest
Warning

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

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

README

baseenc

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

Package baseenc registers the base-N 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/baseenc"

It registers nine Formats, one per alphabet, all through one pipeline: a value is encoded as JSON and the JSON text as base-N, and decoding runs the two steps backwards — so every alphabet carries any Go value encoding/json can, and swapping one alphabet for another is a change of Format name. Every Format 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.24.*; match them with errs.HasCode, or the sentinels with errors.Is:

CodeMarshalFailed    0.3.24.1  the value has no JSON encoding
CodeUnmarshalFailed  0.3.24.2  the decoded text is not JSON the target can hold
CodeDecodeFailed     0.3.24.3  the input is not text of the Format's alphabet
CodeSizeExceeded     0.3.24.4  an input past its bound — 10 MiB, 4 KiB for base58 and base62

No error message quotes the input.

Index

Constants

const ASCII85 = "ascii85"

ASCII85 is Adobe's Ascii85, four bytes in five characters.

const Base16 = "base16"

Base16 is upper-case hexadecimal, RFC 4648 §8.

const Base32 = "base32"

Base32 is standard base32, RFC 4648 §6.

const Base45 = "base45"

Base45 is RFC 9285's alphabet, the one a QR code's alphanumeric mode holds.

const Base58 = "base58"

Base58 is Bitcoin's alphabet; its base conversion is quadratic, so its input is capped at 4 KiB.

const Base62 = "base62"

Base62 is the alphanumeric alphabet; capped at 4 KiB like Base58.

const Base64 = "base64"

Base64 is standard base64, RFC 4648 §4.

const Base64URL = "base64url"

Base64URL is the URL- and filename-safe base64 alphabet, RFC 4648 §5.

const CodeDecodeFailed errs.Code = 202755

CodeDecodeFailed is 0.3.24.3: the input is not text of the Format's alphabet.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/baseenc.CodeBaseEncDecodeFailed.

Code 0.3.24.3

const CodeMarshalFailed errs.Code = 202753

CodeMarshalFailed is 0.3.24.1: the value has no JSON encoding.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/baseenc.CodeBaseEncMarshalFailed.

Code 0.3.24.1

const CodeSizeExceeded errs.Code = 202756

CodeSizeExceeded is 0.3.24.4: an input past its bound — 10 MiB, 4 KiB for base58 and base62.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/baseenc.CodeBaseEncSizeExceeded.

Code 0.3.24.4

const CodeUnmarshalFailed errs.Code = 202754

CodeUnmarshalFailed is 0.3.24.2: the decoded text is not JSON the target can hold.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/baseenc.CodeBaseEncUnmarshalFailed.

Code 0.3.24.2

const Hex = "hex"

Hex is lower-case hexadecimal.

Variables

var DecodeFailed *errs.Error

DecodeFailed is the sentinel of CodeDecodeFailed.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/baseenc.BaseEncDecodeFailed.

Code 0.3.24.3 · reason BASE_ENC_DECODE_FAILED · public "base-N decoding failed"

var MarshalFailed *errs.Error

MarshalFailed is the sentinel of CodeMarshalFailed.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/baseenc.BaseEncMarshalFailed.

Code 0.3.24.1 · reason BASE_ENC_MARSHAL_FAILED · public "base-N encoding failed"

var SizeExceeded *errs.Error

SizeExceeded is the sentinel of CodeSizeExceeded.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/baseenc.BaseEncSizeExceeded.

Code 0.3.24.4 · reason BASE_ENC_SIZE_EXCEEDED · public "base-N input exceeds size limit"

var UnmarshalFailed *errs.Error

UnmarshalFailed is the sentinel of CodeUnmarshalFailed.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/baseenc.BaseEncUnmarshalFailed.

Code 0.3.24.2 · reason BASE_ENC_UNMARSHAL_FAILED · public "base-N decoding failed"

Generated from docs/api by tools/genindex.

Documentation

Overview

Package baseenc registers the base-N 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/baseenc"

It registers nine Formats, one per alphabet, all through one pipeline: a value is encoded as JSON and the JSON text as base-N, and decoding runs the two steps backwards — so every alphabet carries any Go value encoding/json can, and swapping one alphabet for another is a change of Format name. Every Format 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.24.*; match them with errs.HasCode, or the sentinels with errors.Is:

CodeMarshalFailed    0.3.24.1  the value has no JSON encoding
CodeUnmarshalFailed  0.3.24.2  the decoded text is not JSON the target can hold
CodeDecodeFailed     0.3.24.3  the input is not text of the Format's alphabet
CodeSizeExceeded     0.3.24.4  an input past its bound — 10 MiB, 4 KiB for base58 and base62

No error message quotes the input.

Index

Constants

View Source
const (
	// Base64 is standard base64, RFC 4648 §4.
	Base64 = "base64"
	// Base64URL is the URL- and filename-safe base64 alphabet, RFC 4648 §5.
	Base64URL = "base64url"
	// Base32 is standard base32, RFC 4648 §6.
	Base32 = "base32"
	// Base16 is upper-case hexadecimal, RFC 4648 §8.
	Base16 = "base16"
	// Hex is lower-case hexadecimal.
	Hex = "hex"
	// ASCII85 is Adobe's Ascii85, four bytes in five characters.
	ASCII85 = "ascii85"
	// Base45 is RFC 9285's alphabet, the one a QR code's alphanumeric mode holds.
	Base45 = "base45"
	// Base58 is Bitcoin's alphabet; its base conversion is quadratic, so its input is capped at 4 KiB.
	Base58 = "base58"
	// Base62 is the alphanumeric alphabet; capped at 4 KiB like Base58.
	Base62 = "base62"
)

The nine Formats this package registers. Each 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.

View Source
const (
	// CodeMarshalFailed is 0.3.24.1: the value has no JSON encoding.
	CodeMarshalFailed errs.Code = corebaseenc.CodeBaseEncMarshalFailed
	// CodeUnmarshalFailed is 0.3.24.2: the decoded text is not JSON the target
	// can hold.
	CodeUnmarshalFailed errs.Code = corebaseenc.CodeBaseEncUnmarshalFailed
	// CodeDecodeFailed is 0.3.24.3: the input is not text of the Format's
	// alphabet.
	CodeDecodeFailed errs.Code = corebaseenc.CodeBaseEncDecodeFailed
	// CodeSizeExceeded is 0.3.24.4: an input past its bound — 10 MiB, 4 KiB
	// for base58 and base62.
	CodeSizeExceeded errs.Code = corebaseenc.CodeBaseEncSizeExceeded
)

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

Variables

View Source
var (
	// MarshalFailed is the sentinel of [CodeMarshalFailed].
	MarshalFailed = corebaseenc.BaseEncMarshalFailed
	// UnmarshalFailed is the sentinel of [CodeUnmarshalFailed].
	UnmarshalFailed = corebaseenc.BaseEncUnmarshalFailed
	// DecodeFailed is the sentinel of [CodeDecodeFailed].
	DecodeFailed = corebaseenc.BaseEncDecodeFailed
	// SizeExceeded is the sentinel of [CodeSizeExceeded].
	SizeExceeded = corebaseenc.BaseEncSizeExceeded
)

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