Documentation
¶
Index ¶
- func BackupAndWrite(filePath, content string, backup bool) error
- func CalculatePadding(fields []optimizer.FieldInfo) int64
- func CompareFields(orig, new []string) bool
- func CreateFieldInfo(name string, size, align int64, isEmbed bool, typeName string) optimizer.FieldInfo
- func FieldsChanged(orig, new []optimizer.FieldInfo) bool
- func GenerateStructCode(name string, fields []optimizer.FieldInfo) string
- func GetStructFields(filePath, structName string) ([]string, error)
- func GroupFieldsBySize(fields []optimizer.FieldInfo) map[int64][]optimizer.FieldInfo
- func PrintFields(fields []optimizer.FieldInfo)
- func ReadFile(filePath string) (string, error)
- func SortFieldInfos(fields []optimizer.FieldInfo, sortSameSize bool) []optimizer.FieldInfo
- func WriteFile(filePath string, content string) error
- type Config
- type SourceWriter
- func (w *SourceWriter) BackupFile(filePath string) (string, error)
- func (w *SourceWriter) FormatNode(node ast.Node) (string, error)
- func (w *SourceWriter) GetFileSet() *token.FileSet
- func (w *SourceWriter) RewriteFile(filePath string, optimizedStructs map[string]*optimizer.StructInfo) error
- func (w *SourceWriter) WriteFiles(optimized map[string]*optimizer.StructInfo) error
- func (w *SourceWriter) WriteStruct(filePath string, info *optimizer.StructInfo) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BackupAndWrite ¶
BackupAndWrite creates a backup and writes to a file
func CalculatePadding ¶
CalculatePadding computes the total padding size
func CompareFields ¶
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 ¶
FieldsChanged checks whether fields have changed
func GenerateStructCode ¶
GenerateStructCode generates struct source code
func GetStructFields ¶
GetStructFields returns the field list of a struct (for debugging)
func GroupFieldsBySize ¶
GroupFieldsBySize groups fields by their size
func PrintFields ¶
PrintFields prints field info (for debugging)
func SortFieldInfos ¶
SortFieldInfos sorts field info entries
Types ¶
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