You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Sim**ple **ser**ialization code generator for GO structs with unexported fields
2
+
**Sim**ple **ser**ialization code generator for GO structs with unexported fields.
3
+
4
+
Like `binary.Read`, but a bit different and without reflection.
5
+
6
+
## Features
7
+
8
+
### Core
9
+
- go module mode only
10
+
- simple sequential [de]serialization of simple structs
11
+
- supports non-exported fields, as well as exported
12
+
- basic (`int32`, `float64`, etc.), named (`type My uint64`, etc.) field types, and arrays of them (struct type fields,
13
+
array of arrays and slice of arrays are not supported right now)
14
+
- no reflection in generated code, it is simple and fast
15
+
- possibility to select type[s] to serialize via `-types` CLI flag
16
+
- possibility to select output function names (and exportability, as implied by Go)
17
+
18
+
### Advanced
19
+
- slice field length can be set to any expression that returns `int`, by using tags. Currently [de]serialized instance can be referred to as "`o`", within expression.
20
+
E.g. `simser:"len=o.PreviousIntegerField-5"`.
21
+
Or `simser:"len=otherFunc()"`
22
+
Remember that only fields that get read _before_ the slice field will have meaningful values (unless some tricks were used)
23
+
24
+
## Usage
25
+
26
+
#### Basic
27
+
28
+
`//go:generate go run github.com/am4n0w4r/simser -types=Header,body`
29
+
`//go:generate go run github.com/am4n0w4r/simser -types=all`
30
+
31
+
-`-types` (required): can be a comma-separated list of types you want to process, or reserved keyword `all` for processing all top-level `struct`s, found in file.
32
+
`all` usage and requiredness of the argument can change in the future.
33
+
34
+
#### Custom
35
+
36
+
`//go:generate go run github.com/am4n0w4r/simser -types=Header -read-fn-name=customReadFnName -write-fn-name=CustomWriteFnName`
37
+
38
+
-`-read-fn-name` (optional): custom name for deserializing function. Is set per-file.
39
+
-`-write-fn-name` (optional): custom name for deserializing function. Is set per-file.
3
40
4
-
This is a generator that should help with simple sequential reading/writing of structs to/from binary file.
5
-
`binary.Read` actually does the same thing and, probably, does this well, but it has a drawback - it doesn't work with non-exported fields.
6
-
Also, `binary` stuff is a runtime handler, so it has some overhead, while code, generated by this module tries to be simple and fast.
7
41
8
42
## Project state
9
43
10
-
A bit messy, probably unoptimal, but simple and working. It was developed quickly from scratch, to serve a purpose, so the code itself is rather not perfect, but generated code should be at least ok.
11
-
It's the first time I saw go's ast, so it was a lot of try-and-fail behind the scenes. Feel free to file issues.
44
+
A bit messy, not very optimal, but simple and working. It was developed quickly from scratch, to serve a particular practical purpose, so the code itself is rather not perfect, but generated code should be good and do the job.
45
+
It's the first time I worked with go's ast, so it was a lot of try-and-fail behind the scenes. Feel free to file issues.
0 commit comments