Documentation
¶
Index ¶
- Variables
- func CalculateOutputSize(tag *scanner.WireTag) int
- func ExtractPathParams(path string) []string
- func ExtractPrefix(name string) string
- func FileHeader(commentPrefix, langLabel string) string
- func GenerateLicense(logger *slog.Logger, outputDir string) error
- func GenerateReadme(logger *slog.Logger, outputDir string) error
- func GetVersion() (string, error)
- func GetWireFields(md *meta.Metadata, deviceName, direction string) []scanner.WireField
- func GetWireTag(md *meta.Metadata, deviceName, direction string) *scanner.WireTag
- func HasWireTag(md *meta.Metadata, deviceName, direction string) bool
- func NormalizeGoType(goType string) (base string, isSlice bool, isPointer bool)
- func ParseVersion(version string) (major, minor, patch int)
- func SanitizeLeadingDigit(name string) string
- func SortedStringKeys(m map[string]any) []string
- func ToCamelCase(s string) string
- func ToPascalCase(s string) string
- func ToSnakeCase(s string) string
- func TrimPrefixAndSanitize(full string) (prefix, member string)
- func WireTypeSize(wireType string) int
- type MapEntry
Constants ¶
This section is empty.
Variables ¶
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
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
ExtractPathParams parses a route pattern like "bus/{id}/list" and returns the parameter names in order (e.g., ["id"]).
func ExtractPrefix ¶
ExtractPrefix extracts the common prefix from a constant name for enum grouping Examples: "Key_A" -> "Key_", "ModifierShift" -> "Modifier", "LED1" -> "LED"
func FileHeader ¶
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 GetVersion ¶
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
GetWireFields returns the wire fields for a device and direction from metadata.
func GetWireTag ¶ added in v0.2.2
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
HasWireTag returns true if a wire tag exists for the device and direction.
func NormalizeGoType ¶
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 ¶
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 ¶
SanitizeLeadingDigit prefixes names that start with a digit with "Num" to keep identifiers valid in target languages.
func SortedStringKeys ¶
SortedStringKeys returns the sorted keys of a map[string]any.
func ToCamelCase ¶
func ToPascalCase ¶
func ToSnakeCase ¶
func TrimPrefixAndSanitize ¶
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
WireTypeSize returns the size in bytes of a wire protocol type.
Types ¶
type MapEntry ¶ added in v0.2.2
MapEntry is used for sorted iteration over map entries in templates.
func SortedMapEntries ¶ added in v0.2.2
SortedMapEntries returns map entries sorted by key for deterministic output.