Size: 1165 bytes.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Code generation for C++/JSON bindings

## Validation attributes

- Annotate fields in `.proto.hh` with `[[...]]` (fields
  only). Prefix `validate::` is optional (e.g.,
  `[[required]]` or `[[validate::required]]`).
  - Examples: `[[required]] std::string email;`
  - `[[gt(8)]] int age;`
  - `[[email, len_lt(255)]] std::string email;`
- Supported atoms: `required`, `email`, `gt/ge/lt/le`,
  `len_gt/len_lt`, `enum_in(...)`, `matches("regex")`,
  `oneof_set`, `custom("token")`.
- Codegen emits `<proto>.validate.hh` with
  `using <Proto>Rules = all<...>;` and path strings from
  field names; validation collects all errors.
- Include the generated `*.validate.hh` and call
  `cs::net::proto::validation::Validate(msg, <Proto>Rules{});`.

## Testing & goldens

- Tests live in `cs/net/proto/codegen/tests` and rely on
  deterministic set ordering. Run them with:
  `PYTHONHASHSEED=0 python -m unittest discover cs/net/proto/codegen/tests`.
- Golden outputs for fixtures are checked in under
  `cs/net/proto/codegen/testdata/golden`. Refresh after
  intentional generator changes with:
  `PYTHONHASHSEED=0 python cs/net/proto/codegen/tests/refresh_goldens.py`.
v0 (commit) © 2025 @p13i.io | Load balancer proxied to: cs-code-viewer-3:8080 in 3ms.