idcodec

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: 4 Imported by: 0

Documentation

Overview

Package idcodec provides consolidated ID encoding/decoding operations. This package delegates to internal/encoding for the core base-63 algorithm and provides type-safe wrappers for LCI-specific ID types.

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 (
	Base     = encoding.Base63
	Alphabet = encoding.Alphabet63
)

Re-export constants from encoding package for convenience

Variables

View Source
var (
	ErrEmptyString = encoding.ErrEmptyString
	ErrInvalidChar = encoding.ErrInvalidChar
	ErrOverflow    = encoding.ErrOverflow
)

Re-export errors from encoding package for use with errors.Is

View Source
var (
	ErrSymbolNotFound    = &LookupError{Reason: ReasonNotFound}
	ErrSymbolFileDeleted = &LookupError{Reason: ReasonDeletedFile}
	ErrSymbolInvalidID   = &LookupError{Reason: ReasonInvalidID}
)

Sentinel errors for use with errors.Is

Functions

func Decode

func Decode(encoded string) (uint64, error)

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

func DecodeComposite

func DecodeComposite(encoded string) (types.FileID, uint32, error)

DecodeComposite decodes a base-63 string to FileID and LocalSymbolID. Returns error for invalid input.

func DecodeFileID

func DecodeFileID(encoded string) (types.FileID, error)

DecodeFileID decodes a base-63 string to a FileID.

func DecodeSymbolID

func DecodeSymbolID(encoded string) (types.SymbolID, error)

DecodeSymbolID decodes a base-63 string to a SymbolID. Returns error for invalid input.

func Encode

func Encode(value uint64) string

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

func EncodeComposite

func EncodeComposite(fileID types.FileID, localSymbolID uint32) string

EncodeComposite encodes a FileID and LocalSymbolID into a single base-63 string. The values are packed as: uint64(fileID) | (uint64(localSymbolID) << 32)

func EncodeFileID

func EncodeFileID(id types.FileID) string

EncodeFileID encodes a FileID to a base-63 string.

func EncodeNoZero

func EncodeNoZero(value uint64) string

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

func EncodeSymbolID

func EncodeSymbolID(id types.SymbolID) string

EncodeSymbolID encodes a SymbolID to a base-63 string. This is the canonical function for encoding symbol IDs throughout LCI.

SymbolID in LCI is a raw uint64 index into the symbol store. It is NOT a packed FileID+LocalSymbolID (that's CompositeSymbolID).

func IsValid

func IsValid(encoded string) bool

IsValid checks if a string is a valid base-63 encoded value. Delegates to encoding.Base63IsValid.

func IsValidSymbolID

func IsValidSymbolID(encoded string) bool

IsValidSymbolID checks if a string is a valid base-63 encoded SymbolID.

func MustDecodeSymbolID

func MustDecodeSymbolID(encoded string) types.SymbolID

MustDecodeSymbolID decodes a base-63 string to a SymbolID. Panics on error - use only when the input is known to be valid.

func PackComposite

func PackComposite(fileID types.FileID, localSymbolID uint32) uint64

PackComposite packs FileID and LocalSymbolID into a uint64. Use this when you need the raw packed value.

func UnpackComposite

func UnpackComposite(packed uint64) (types.FileID, uint32)

UnpackComposite unpacks a uint64 into FileID and LocalSymbolID.

Types

type DeletedFileChecker

type DeletedFileChecker interface {
	IsDeleted(fileID types.FileID) bool
}

DeletedFileChecker is the interface for checking if a file is deleted.

type LookupError

type LookupError struct {
	SymbolID types.SymbolID
	Reason   LookupErrorReason
	Detail   string // Optional additional detail
}

LookupError provides context about why a symbol lookup failed.

func NewDeletedFileError

func NewDeletedFileError(id types.SymbolID, filePath string) *LookupError

NewDeletedFileError creates a deleted-file error for a specific symbol ID.

func NewInvalidIDError

func NewInvalidIDError(id types.SymbolID, detail string) *LookupError

NewInvalidIDError creates an invalid-ID error.

func NewNotFoundError

func NewNotFoundError(id types.SymbolID) *LookupError

NewNotFoundError creates a not-found error for a specific symbol ID.

func (*LookupError) Error

func (e *LookupError) Error() string

func (*LookupError) Is

func (e *LookupError) Is(target error) bool

Is implements errors.Is for LookupError.

type LookupErrorReason

type LookupErrorReason int

LookupErrorReason indicates why a symbol lookup failed.

const (
	// ReasonNotFound indicates the symbol ID does not exist in the index.
	ReasonNotFound LookupErrorReason = iota
	// ReasonDeletedFile indicates the symbol's file has been deleted.
	ReasonDeletedFile
	// ReasonInvalidID indicates the provided ID was malformed.
	ReasonInvalidID
)

func (LookupErrorReason) String

func (r LookupErrorReason) String() string

type LookupResult

type LookupResult struct {
	ID     types.SymbolID
	Symbol *types.EnhancedSymbol
	Error  error
}

LookupResult holds a symbol lookup result with possible error.

type SymbolGetter

type SymbolGetter interface {
	GetEnhancedSymbol(symbolID types.SymbolID) *types.EnhancedSymbol
}

SymbolGetter is the interface for symbol lookup. Implemented by ReferenceTracker.

type SymbolLookup

type SymbolLookup struct {
	// contains filtered or unexported fields
}

SymbolLookup provides safe symbol lookup with proper error handling. It wraps a SymbolGetter to provide typed errors.

func NewSymbolLookup

func NewSymbolLookup(getter SymbolGetter, deletedChecker DeletedFileChecker) *SymbolLookup

NewSymbolLookup creates a new SymbolLookup.

func (*SymbolLookup) DecodeAndGet

func (l *SymbolLookup) DecodeAndGet(encoded string) (*types.EnhancedSymbol, error)

DecodeAndGet decodes a base-63 string and looks up the symbol. Combines DecodeSymbolID and Get into a single operation.

func (*SymbolLookup) Get

Get looks up a symbol by ID with proper error handling. Returns (*EnhancedSymbol, nil) on success. Returns (nil, *LookupError) with specific reason on failure.

func (*SymbolLookup) GetMultiple

func (l *SymbolLookup) GetMultiple(ids []types.SymbolID) []LookupResult

GetMultiple looks up multiple symbols, returning results for all. Continues on errors, returning partial results.

func (*SymbolLookup) GetMultipleValid

func (l *SymbolLookup) GetMultipleValid(ids []types.SymbolID) []*types.EnhancedSymbol

GetMultipleValid looks up multiple symbols, returning only valid results. Silently skips errors.

func (*SymbolLookup) GetOrNil

func (l *SymbolLookup) GetOrNil(id types.SymbolID) *types.EnhancedSymbol

GetOrNil looks up a symbol by ID, returning nil without error if not found. Use this when you expect some lookups to fail (e.g., in batch operations).

func (*SymbolLookup) MustGet

MustGet looks up a symbol by ID, panicking if not found. Use this only when you're certain the symbol exists.

Jump to

Keyboard shortcuts

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