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
Run `zig fmt` before committing. The CI enforces formatting.
18
+
19
+
```sh
20
+
zig fmt src/ build.zig
21
+
```
22
+
23
+
Use `const` by default. Prefer explicit types over `auto`-style inference when it improves readability. Follow the patterns already present in the codebase.
24
+
25
+
## Making Changes
26
+
27
+
1. Fork the repository.
28
+
2. Create a feature branch from `master`.
29
+
3. Make your changes with tests.
30
+
4. Ensure all tests pass: `zig build test`.
31
+
5. Ensure formatting is clean: `zig fmt --check src/ build.zig`.
32
+
6. Open a pull request against `master`.
33
+
34
+
## Commit Messages
35
+
36
+
Use concise, imperative-style messages:
37
+
38
+
```
39
+
feat: add CBOR format support
40
+
fix: handle empty structs in XML deserializer
41
+
docs: clarify union tagging in README
42
+
refactor: deduplicate scanner logic
43
+
```
44
+
45
+
Prefix with a label when it makes sense: `feat`, `fix`, `docs`, `refactor`, `test`, `chore`.
46
+
47
+
## Adding a New Format
48
+
49
+
Each format lives in `src/formats/<name>/` and must provide:
50
+
51
+
-`mod.zig` — public API (`toSlice`, `fromSlice`, `toWriter`, `fromReader`, schema-aware variants)
52
+
-`serializer.zig` — a type implementing the `Serializer` interface from `src/core/interface.zig`
53
+
-`deserializer.zig` — a type implementing the `Deserializer` interface
54
+
55
+
Both interfaces are verified at comptime by `isSerializer` / `isDeserializer` in `src/core/interface.zig`.
56
+
57
+
Add the new format to:
58
+
-`src/root.zig` — import and re-export
59
+
-`build.zig` — add fuzz target if applicable
60
+
-`README.md` — add to the Formats table
61
+
62
+
## Adding Tests
63
+
64
+
- Unit tests go in the same file as the code they test (using `test` blocks).
65
+
- Cross-format roundtrip tests go in `test/roundtrip_test.zig`.
66
+
- Stress and edge-case tests go in `test/` with descriptive file names.
67
+
- Fuzz harnesses go in `test/fuzz_<format>.zig`.
68
+
69
+
## Reporting Issues
70
+
71
+
When filing a bug, please include:
72
+
73
+
- Zig version (`zig version`)
74
+
- Minimal reproducible example
75
+
- Expected vs actual behavior
76
+
77
+
## License
78
+
79
+
By contributing, you agree that your changes will be licensed under the [MIT License](LICENSE).
Copy file name to clipboardExpand all lines: README.md
+57-4Lines changed: 57 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,59 @@ Serialization framework for Zig
8
8
9
9
Uses Zig's comptime reflection (`@typeInfo`) to serialize and deserialize any Zig type across JSON, MessagePack, TOML, YAML, XML, ZON, and CSV without macros, code generation, or runtime type information.
-[Out-of-Band Type Overrides](#out-of-band-type-overrides)
45
+
-[Custom Serialization](#custom-serialization)
46
+
-[Error Handling](#error-handling)
47
+
-[Tests](#tests)
48
+
-[License](#license)
49
+
50
+
## Why serde.zig?
51
+
52
+
**No boilerplate.** No macros, no code generation, no build steps. Just declare a struct and serialize it. Zig's comptime reflection handles everything at compile time.
53
+
54
+
**Seven formats, one API.** JSON, MessagePack, TOML, YAML, XML, ZON, and CSV all share the same `toSlice`/`fromSlice`/`toWriter`/`fromReader` interface. Learn once, use everywhere.
55
+
56
+
**Out-of-band schemas.** Serialize the same type differently in different contexts without modifying the type itself. Essential for third-party types and API versioning.
57
+
58
+
**Zero-copy JSON.**`fromSliceBorrowed` returns string slices that point directly into the input buffer when no escape sequences are present. No allocation, no copying.
59
+
60
+
**Comptime validation.** Invalid types, missing fields, and incorrect option names are caught at compile time, not at runtime.
0 commit comments