common

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Version = ""

Version is set via ldflags at build time: -ldflags "-X viiper/internal/codegen/common.Version=x.y.z"

Functions

func CalculateOutputSize added in v0.2.2

func CalculateOutputSize(tag *scanner.WireTag) int

CalculateOutputSize computes the exact size in bytes of a device's output (s2c) message. Returns 0 if the tag is nil or device has no output. For variable-length fields (e.g., "u8*count"), returns 0 to indicate dynamic size.

func ExtractPathParams added in v0.2.2

func ExtractPathParams(path string) []string

ExtractPathParams parses a route pattern like "bus/{id}/list" and returns the parameter names in order (e.g., ["id"]).

func ExtractPrefix

func ExtractPrefix(name string) string

ExtractPrefix extracts the common prefix from a constant name for enum grouping Examples: "Key_A" -> "Key_", "ModifierShift" -> "Modifier", "LED1" -> "LED"

func FileHeader

func FileHeader(commentPrefix, langLabel string) string

FileHeader returns a standard two-line autogenerated header for generated files. commentPrefix is the line comment token for the target language (e.g., "//"). langLabel is a human readable language label to include (e.g., "TypeScript", "C#").

func GenerateLicense

func GenerateLicense(logger *slog.Logger, outputDir string) error

func GenerateReadme

func GenerateReadme(logger *slog.Logger, outputDir string) error

func GetVersion

func GetVersion() (string, error)

GetVersion returns the version string that was set at build time via ldflags. Returns "0.0.1-dev" if Version is empty (development builds only). For production releases, Version MUST be set via: go build -ldflags "-X viiper/internal/codegen/common.Version=x.y.z"

func GetWireFields added in v0.2.2

func GetWireFields(md *meta.Metadata, deviceName, direction string) []scanner.WireField

GetWireFields returns the wire fields for a device and direction from metadata.

func GetWireTag added in v0.2.2

func GetWireTag(md *meta.Metadata, deviceName, direction string) *scanner.WireTag

GetWireTag returns the wire tag for a device and direction from metadata. Direction can be "input"/"c2s" or "output"/"s2c".

func HasWireTag added in v0.2.2

func HasWireTag(md *meta.Metadata, deviceName, direction string) bool

HasWireTag returns true if a wire tag exists for the device and direction.

func NormalizeGoType

func NormalizeGoType(goType string) (base string, isSlice bool, isPointer bool)

NormalizeGoType strips pointer and slice prefixes from a Go type string and reports whether the original type was a slice or pointer. Examples: "*MyType" -> ("MyType", false, true), "[]uint8" -> ("uint8", true, false)

func ParseVersion

func ParseVersion(version string) (major, minor, patch int)

ParseVersion extracts major, minor, patch from version string like "1.2.3" or "1.2.3-dirty" Returns major, minor, patch as integers.

func SanitizeLeadingDigit

func SanitizeLeadingDigit(name string) string

SanitizeLeadingDigit prefixes names that start with a digit with "Num" to keep identifiers valid in target languages.

func SortedStringKeys

func SortedStringKeys(m map[string]any) []string

SortedStringKeys returns the sorted keys of a map[string]any.

func ToCamelCase

func ToCamelCase(s string) string

func ToPascalCase

func ToPascalCase(s string) string

func ToSnakeCase

func ToSnakeCase(s string) string

func TrimPrefixAndSanitize

func TrimPrefixAndSanitize(full string) (prefix, member string)

TrimPrefixAndSanitize splits a constant full name into its enum prefix and member, and sanitizes the member (e.g., leading digits -> "Num..."). Example: "Key_1" => ("Key_", "Num1"), "ModifierShift" => ("Modifier", "Shift").

func WireTypeSize added in v0.2.2

func WireTypeSize(wireType string) int

WireTypeSize returns the size in bytes of a wire protocol type.

Types

type MapEntry added in v0.2.2

type MapEntry struct {
	Key   string
	Value any
}

MapEntry is used for sorted iteration over map entries in templates.

func SortedMapEntries added in v0.2.2

func SortedMapEntries(entries map[string]interface{}) []MapEntry

SortedMapEntries returns map entries sorted by key for deterministic output.

Jump to

Keyboard shortcuts

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