encoding

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package encoding provides low-level encoding utilities with no dependencies. This is the foundational package for ID encoding used throughout LCI.

Base-63 Alphabet: A-Z (0-25), a-z (26-51), 0-9 (52-61), _ (62) This provides ~6 character IDs for typical projects (vs ~16 for hex).

Index

Constants

View Source
const (
	Base63     = 63
	Alphabet63 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_"
)

Base-63 encoding constants

Variables

View Source
var (
	ErrEmptyString = errors.New("empty encoded string")
	ErrInvalidChar = errors.New("invalid character in encoded string")
	ErrOverflow    = errors.New("decoded value overflow")
)

Common errors for encoding operations

Functions

func Base63CharToValue

func Base63CharToValue(c rune) (uint64, error)

Base63CharToValue converts a character to its base-63 numeric value (0-62).

func Base63Decode

func Base63Decode(encoded string) (uint64, error)

Base63Decode decodes a base-63 string to a uint64 value. Returns error for empty strings or invalid characters.

func Base63Encode

func Base63Encode(value uint64) string

Base63Encode encodes a uint64 value to a base-63 string. Returns "A" for zero (minimum non-empty encoding).

func Base63EncodeNoZero

func Base63EncodeNoZero(value uint64) string

Base63EncodeNoZero encodes a uint64 value to a base-63 string. Returns empty string for zero value (used for composite IDs where 0 means "none").

func Base63IsValid

func Base63IsValid(encoded string) bool

Base63IsValid checks if a string is a valid base-63 encoded value.

func Base63ValueToChar

func Base63ValueToChar(val uint64) byte

Base63ValueToChar converts a base-63 numeric value (0-62) to its character. Panics if value > 62 (internal error, should never happen with valid input).

func PackUint32Pair

func PackUint32Pair(lower, upper uint32) uint64

PackUint32Pair packs two uint32 values into a single uint64. lower goes into lower 32 bits, upper goes into upper 32 bits.

func UnpackUint32Pair

func UnpackUint32Pair(packed uint64) (lower, upper uint32)

UnpackUint32Pair unpacks a uint64 into two uint32 values. Returns (lower 32 bits, upper 32 bits).

Types

This section is empty.

Jump to

Keyboard shortcuts

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