feat(proto): Wire custom SchemaHandler for proto field metadata#5310
Draft
jamesarich wants to merge 2 commits into
Draft
feat(proto): Wire custom SchemaHandler for proto field metadata#5310jamesarich wants to merge 2 commits into
jamesarich wants to merge 2 commits into
Conversation
e788874 to
b1ba48e
Compare
Adds build-time codegen that auto-generates a ConfigFieldMetadataRegistry from (meshtastic.config_field) annotations in .proto files. - New FieldMetadataSchemaHandler in build-logic walks all message fields - Emits a static Kotlin registry mapping (messageType, fieldTag) → metadata - Zero runtime cost, no wire-schema dep in app binary - Adding annotations to new fields requires no code changes Companion to: meshtastic/protobufs#905
b1ba48e to
f610789
Compare
…hemaHandler The upstream proto (meshtastic/protobufs#905) has been simplified to use a scalar bool extension instead of a message wrapper: [(meshtastic.diy_only) = true] Wire 6's emitAppliedOptions now natively generates @DiyOnlyOption(true) annotations on fields, eliminating the need for our custom FieldMetadataSchemaHandler. Changes: - Delete FieldMetadataSchemaHandler.kt (~200 LOC) - Remove wire-schema dependency from build-logic - Remove custom {} handler block from core:proto build - Add emitAppliedOptions = true to Wire kotlin {} config - Update FieldMetadataDemo to demonstrate the native annotation - Bump protobufs submodule to metadata-experiment branch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a build-time Wire
SchemaHandlerthat auto-generates aConfigFieldMetadataRegistryfrom(meshtastic.config_field)annotations in.protofiles.Companion to: meshtastic/protobufs#905
Problem
Jonathan's protobufs PR #905 adds custom field options (
diy_only) to proto fields viaextend google.protobuf.FieldOptions. The question was whether Android (Wire) could access this metadata without hacks.Solution
Wire 6 handles proto extensions cleanly — it flattens them into typed properties on
FieldOptions. However, the metadata lives at the schema level, not on generated message fields directly. To make it easily queryable at runtime without shipping the heavywire-schemalibrary in the APK, we use Wire's custom SchemaHandler mechanism:FieldMetadataSchemaHandler(inbuild-logic/convention) walks every message field at codegen time(meshtastic.config_field)options viafield.options.get(ProtoMember)ConfigFieldMetadataRegistryKotlin objectGenerated output (auto-created at build time):
Usage example:
Key properties
wire-schemais only a build-logic dependency, not shipped in APKConfigFieldMetadatamessage gains new sub-fields (e.g.admin_only,min_value)Changes
gradle/libs.versions.toml— addedwire-schemalibrary entrybuild-logic/convention/build.gradle.kts— addedwire-schemadependencybuild-logic/convention/.../FieldMetadataSchemaHandler.kt— the custom handler + factorycore/proto/build.gradle.kts— addedcustom {}target + source dir registration