mirror of
https://github.com/ankitects/anki.git
synced 2025-11-06 12:47:11 -05:00
Protobuf 3.15 introduced support for marking scalar fields like uint32 as optional, and all of our tooling appears to support it now. This allows us to use simple optional/null checks in our Rust/ TypeScript code, without having to resort to an inner message. I had to apply a minor patch to protobufjs to get this working with the json-module output; this has also been submitted upstream: https://github.com/protobufjs/protobuf.js/pull/1693 I've modified CardStatsResponse as an example of the new syntax. One thing to note: while the Rust and TypeScript bindings use optional/ null fields, as that is the norm in those languages, Google's Python bindings are not very Pythonic. Referencing an optional field that is missing will yield the default value, and a separate HasField() call is required, eg: ``` >>> from anki.stats_pb2 import CardStatsResponse as R ... msg = R.FromString(b"") ... print(msg.first_review) ... print(msg.HasField("first_review")) 0 False ``` |
||
|---|---|---|
| .. | ||
| .cargo | ||
| benches | ||
| build | ||
| cargo | ||
| i18n | ||
| i18n_helpers | ||
| linkchecker | ||
| src | ||
| tests/support | ||
| .gitignore | ||
| bench.sh | ||
| BUILD.bazel | ||
| Cargo.toml | ||
| empty.rs | ||
| README.md | ||
| rustfmt.bzl | ||
| rustfmt.toml | ||
Anki's Rust code.
backend.proto stores the interfaces used to communicate backend messages between Rust, Python and TypeScript.