# gen-bsa **Repository Path**: FlyingOnion/gen-bsa ## Basic Information - **Project Name**: gen-bsa - **Description**: Gen-bsa is a code generator that could help `wtflog` log complex data structures more efficiently. - **Primary Language**: Go - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-05-12 - **Last Updated**: 2024-05-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Gen-bsa Gen-bsa is a code generator that could help `wtflog` log complex data structures more efficiently. ## Usage 1. `go install gitee.com/FlyingOnion/gen-bsa` 2. Change dir to your project (should have `go.mod` in it or its ancestor directory) 3. Run `gen-bsa dir1 dir2 ...` (or just `gen-bsa` if target dir is current dir) ## Example Output Change dir to the gen-bsa root and run `gen-bsa gbt`, and run tests in the gbt package. Or just see Readme.md of gbt. Note that some structures, like `error`, `[]byte`, struct pointer, map will have a different output from `fmt.Printf("%+v", v)`. ## Benchmark (Temporary) The benchmarks are temporary, because some features remains unfinished. We will update them in the future. Benchmarks of gen-bsa cover custom type structs only. We are currently working on other features. Multiple types of fields are mixxed because it spend too much time to seperate each field type to different benchs. The benchmark outputs shows that gen-bsa can increase efficiency and reduce costs. ```shell goos: windows goarch: amd64 cpu: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz ``` |Bench|Time (ns/op)|Memory (B/op)|Allocs (allocs/op)| |-|-|-|-| |basic|206.0|80|1| |basic no bsa|887.7|176|9| |struct/error|199.8|40|2| |struct/error no bsa|681.2|104|5| |time.Time|621.3|208|7| |time.Time no bsa|980.8|264|9| |slice|664.8|208|6| |slice no bsa|1615|360|13| ## Work Progress Brief: - custom type struct: 80%+ - custom type map: 50% - custom type slice/array: 50% - generate `String() string` method: TODO Struct Field: - deal with more than 1 field in 1 line: Done - skip all `_` fields: Done - basic types (like `int`, `string`, `error`): Done - basic pointer (like `*int`): Done - named struct and pointer: Done - builtin struct and pointer: Experimental - function, channel: Done - `[]byte`: Done - other slice: Done - external type (like `time.Time`): Done - external type but use local import (`import .`): Done - map: WIP Map: - with key of string, int family, uint family, byte type: Done - with key of other type: WIP - sort keys: Done - log values: Experimental Slice/Array: - with basic element type: WIP - with other type: WIP Pointer: May not be supported, because we cannot fully handled all indents. There are too many conditions to consider. ~~- with basic element type: WIP~~ ~~- with struct element type: WIP~~ ~~- with other type: WIP~~