|
1 | | -# STEF Generator |
| 1 | +# STEF Compiler |
| 2 | + |
| 3 | +stefc is a command-line compiler and code generator that takes STEF schema files as |
| 4 | +input and generates type-safe serialization and deserialization code for multiple |
| 5 | +programming languages. For usage instructions, please refer to |
| 6 | +[STEFC documentation](https://www.stefdata.net/stefc.html). |
| 7 | + |
| 8 | +## Design |
| 9 | + |
| 10 | +stefc is implemented in Go and uses Go [text/template](https://pkg.go.dev/text/template) |
| 11 | +for code generation. There is a set of templates for each target language: |
| 12 | + |
| 13 | +- [Templates for Go](./templates/go) |
| 14 | +- [Templates for Java](./templates/java) |
| 15 | + |
| 16 | +stefc parses the input STEF schema file, then generates code by applying the parsed schema |
| 17 | +to the appropriate templates for the specified target language. See generator |
| 18 | +implementation in [generator](./generator) package. |
| 19 | + |
| 20 | +Template files contain templated code to represent in-memory and to serialize and |
| 21 | +deserialize supported types (structs, oneofs, enums, arrays, maps). |
| 22 | + |
| 23 | +## Building and Testing |
| 24 | + |
| 25 | +Pre-requisites: |
| 26 | + |
| 27 | +- make |
| 28 | +- Go 1.24 or newer |
| 29 | + |
| 30 | +To build stefc, run `make build`. To run tests, use `make test`. |
| 31 | + |
| 32 | +[generator/testdata](./generator/testdata) contains STEF schema files that are used in |
| 33 | +unit tests for the code generator. For each of these schema files, a test is run that |
| 34 | +generates Go and Java code from the schema, then runs generated tests that verify |
| 35 | +correctness of serialization and deserialization. Generated tests use randomized input |
| 36 | +from an initial seed of a random number generator. "seeds" directory contains recorded |
| 37 | +seeds for each test case that previously resulted in detected bugs. These seeds are used |
| 38 | +to avoid regressions. |
| 39 | + |
| 40 | +If you make any changes to template files or to the generator code, rerun `make all` |
| 41 | +to ensure that all generated code is up to date and all tests are run. |
| 42 | + |
| 43 | +stefc is also used for generating code in [examples](../examples) directory and |
| 44 | +in [otel](../go/otel) directory. |
0 commit comments