writer

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BackupAndWrite

func BackupAndWrite(filePath, content string, backup bool) error

BackupAndWrite creates a backup and writes to a file

func CalculatePadding

func CalculatePadding(fields []optimizer.FieldInfo) int64

CalculatePadding computes the total padding size

func CompareFields

func CompareFields(orig, new []string) bool

CompareFields compares two field lists

func CreateFieldInfo

func CreateFieldInfo(name string, size, align int64, isEmbed bool, typeName string) optimizer.FieldInfo

CreateFieldInfo creates a field info entry (for testing)

func FieldsChanged

func FieldsChanged(orig, new []optimizer.FieldInfo) bool

FieldsChanged checks whether fields have changed

func GenerateStructCode

func GenerateStructCode(name string, fields []optimizer.FieldInfo) string

GenerateStructCode generates struct source code

func GetStructFields

func GetStructFields(filePath, structName string) ([]string, error)

GetStructFields returns the field list of a struct (for debugging)

func GroupFieldsBySize

func GroupFieldsBySize(fields []optimizer.FieldInfo) map[int64][]optimizer.FieldInfo

GroupFieldsBySize groups fields by their size

func PrintFields

func PrintFields(fields []optimizer.FieldInfo)

PrintFields prints field info (for debugging)

func ReadFile

func ReadFile(filePath string) (string, error)

ReadFile reads file content

func SortFieldInfos

func SortFieldInfos(fields []optimizer.FieldInfo, sortSameSize bool) []optimizer.FieldInfo

SortFieldInfos sorts field info entries

func WriteFile

func WriteFile(filePath string, content string) error

WriteFile writes content to a file

Types

type Config

type Config struct {
	Backup  bool
	Verbose int
}

Config holds writer configuration

type SourceWriter

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

SourceWriter writes optimized source code

func NewSourceWriter

func NewSourceWriter(cfg *Config) *SourceWriter

NewSourceWriter creates a new source writer

func (*SourceWriter) BackupFile

func (w *SourceWriter) BackupFile(filePath string) (string, error)

BackupFile creates a timestamped backup of the source file (to avoid overwriting)

func (*SourceWriter) FormatNode

func (w *SourceWriter) FormatNode(node ast.Node) (string, error)

FormatNode formats an AST node

func (*SourceWriter) GetFileSet

func (w *SourceWriter) GetFileSet() *token.FileSet

GetFileSet returns the file set

func (*SourceWriter) RewriteFile

func (w *SourceWriter) RewriteFile(filePath string, optimizedStructs map[string]*optimizer.StructInfo) error

RewriteFile rewrites the entire file using optimized structs

func (*SourceWriter) WriteFiles

func (w *SourceWriter) WriteFiles(optimized map[string]*optimizer.StructInfo) error

WriteFiles writes multiple files

func (*SourceWriter) WriteStruct

func (w *SourceWriter) WriteStruct(filePath string, info *optimizer.StructInfo) error

WriteStruct writes the optimized struct to the source file

Jump to

Keyboard shortcuts

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