Skip to content

Commit 697996c

Browse files
authored
Merge pull request #19 from YuhanLiin/reduce-generated-code
Reduce generated code
2 parents d814999 + e54589b commit 697996c

11 files changed

Lines changed: 644 additions & 4005 deletions

File tree

CHANGELOG.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Added
6+
7+
- Add `no_accessors` configuration to reduce generated file size
8+
- Add new setting to disable generating `MAX_SIZE` calculations
9+
10+
### Changed
11+
12+
- Use derives for `PartialEq` and `Default` when possible
13+
314
## 0.2.0
415

516
### Added
@@ -11,8 +22,8 @@
1122
- Add `field_lifetime` configuration to set lifetime of message fields
1223
- Add container trait impls for `Cow`
1324
- Add const constructor `_new` to hazzer structs and add const to all hazzer methods
14-
- Add `Generator::configure_many`
15-
- Add `Config::recursive_field`
25+
- Add `Generator::configure_many` method for configuring multiple paths at once
26+
- Add `recursive_field` configuration to box and handle max size for recursive fields
1627

1728
### Changed
1829

examples/file-descriptor-set/build.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,23 @@ fn main() {
66
.encode_decode(EncodeDecode::DecodeOnly)
77
.configure(
88
".",
9-
Config::new().no_clone_impl(true).no_partial_eq_impl(true),
9+
Config::new()
10+
.no_clone_impl(true)
11+
.no_partial_eq_impl(true)
12+
.no_accessors(true),
13+
)
14+
// Override minimal accessors setting for specific paths, since the generator calls `set_`
15+
// APIs on specific messages
16+
.configure_many(
17+
&[
18+
".google.protobuf.DescriptorProto",
19+
".google.protobuf.FieldDescriptorProto",
20+
".google.protobuf.FieldOptions",
21+
".google.protobuf.OneofDescriptorProto",
22+
".google.protobuf.MessageOptions",
23+
".google.protobuf.EnumValueDescriptorProto",
24+
],
25+
Config::new().no_accessors(false),
1026
)
1127
.compile_protos(&["google/protobuf/descriptor.proto"], "descriptor.rs")
1228
.unwrap();

micropb-gen/src/config.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,13 @@ config_decl! {
423423
/// ```
424424
field_lifetime: [deref] Option<String>,
425425

426+
/// Disable field accessors.
427+
///
428+
/// Do not generate accessors for this field other than the getter method on optional fields,
429+
/// which is required by the encoding logic. This won't reduce the compiled code size, but it
430+
/// will significantly reduce the size of the output source file.
431+
no_accessors: Option<bool>,
432+
426433
// Type configs
427434

428435
/// Override the integer size of Protobuf enums.

0 commit comments

Comments
 (0)