-
-
Notifications
You must be signed in to change notification settings - Fork 79
Replace enum_as_bitmask with container_pointer_no_template #1402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This reverts the change made in #1401 as it turned out to not scale well. It was simple enough to continue use container_pointer, but add a new version for non-template values called container_pointer_no_template
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1402 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 22 22
Lines 3310 3310
=========================================
Hits 3310 3310 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
CodSpeed Performance ReportMerging #1402 will not alter performanceComparing Summary
Footnotes |
WalkthroughProtobuf schema changes replace an enum bitmask field option with a container pointer approach across three files. The Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
aioesphomeapi/api.proto(1 hunks)aioesphomeapi/api_options.proto(1 hunks)aioesphomeapi/api_options_pb2.py(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**
⚙️ CodeRabbit configuration file
- Do not generate or add any sequence diagrams
Files:
aioesphomeapi/api_options.protoaioesphomeapi/api.protoaioesphomeapi/api_options_pb2.py
🔇 Additional comments (2)
aioesphomeapi/api.proto (1)
509-509: LGTM on switching to container_pointer_no_template; confirm generator + type exist.Change aligns with the new option. Please verify the C++ symbol light::ColorModeMask exists and the codegen path for container_pointer_no_template is implemented and tested end-to-end.
aioesphomeapi/api_options.proto (1)
74-82: Based on my verification:Evidence gathered:
- ✅ No
enum_as_bitmaskusages remain anywhere in the codebase (confirmed zero matches across all files)- ✅ Tag 50014 reuse is safe; the old bool-typed
enum_as_bitmaskis completely removed- ✅
container_pointer_no_templateis already in active use inapi.proto:509with the new string-typed option at tag 50014, indicating the generator supports it- ✅
container_pointerdocumentation at lines 42–66 explicitly mentions lifetime requirements ("remains valid during message encoding"), butcontainer_pointer_no_template(lines 74–82) omits this crucial detailThe documentation improvement is valid and necessary to prevent misuse. The tag reuse is safe.
Add explicit lifetime requirements to match container_pointer documentation.
The docs reference similarity to
container_pointerbut omit the lifetime constraint that exists there. Add the safety requirement to prevent accidental use-after-free:// container_pointer_no_template: Use a non-template container type for repeated fields // Similar to container_pointer, but for containers that don't take template parameters. + // + // The corresponding C++ code must provide const reference access to a container + // that remains valid during message encoding (same lifetime requirement as container_pointer). // The container type is used as-is without appending element type. // The container must have: // - begin() and end() methods returning iterators
|
|
||
|
|
||
| DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x11\x61pi_options.proto\x1a google/protobuf/descriptor.proto\"\x06\n\x04void*F\n\rAPISourceType\x12\x0f\n\x0bSOURCE_BOTH\x10\x00\x12\x11\n\rSOURCE_SERVER\x10\x01\x12\x11\n\rSOURCE_CLIENT\x10\x02:E\n\x16needs_setup_connection\x12\x1e.google.protobuf.MethodOptions\x18\x8e\x08 \x01(\x08:\x04true:C\n\x14needs_authentication\x12\x1e.google.protobuf.MethodOptions\x18\x8f\x08 \x01(\x08:\x04true:/\n\x02id\x12\x1f.google.protobuf.MessageOptions\x18\x8c\x08 \x01(\r:\x01\x30:M\n\x06source\x12\x1f.google.protobuf.MessageOptions\x18\x8d\x08 \x01(\x0e\x32\x0e.APISourceType:\x0bSOURCE_BOTH:/\n\x05ifdef\x12\x1f.google.protobuf.MessageOptions\x18\x8e\x08 \x01(\t:3\n\x03log\x12\x1f.google.protobuf.MessageOptions\x18\x8f\x08 \x01(\x08:\x04true:9\n\x08no_delay\x12\x1f.google.protobuf.MessageOptions\x18\x90\x08 \x01(\x08:\x05\x66\x61lse:4\n\nbase_class\x12\x1f.google.protobuf.MessageOptions\x18\x91\x08 \x01(\t:3\n\x0b\x66ield_ifdef\x12\x1d.google.protobuf.FieldOptions\x18\x92\x08 \x01(\t:9\n\x10\x66ixed_array_size\x12\x1d.google.protobuf.FieldOptions\x18\xd7\x86\x03 \x01(\r:<\n\x0cno_zero_copy\x12\x1d.google.protobuf.FieldOptions\x18\xd8\x86\x03 \x01(\x08:\x05\x66\x61lse:E\n\x15\x66ixed_array_skip_zero\x12\x1d.google.protobuf.FieldOptions\x18\xd9\x86\x03 \x01(\x08:\x05\x66\x61lse:@\n\x17\x66ixed_array_size_define\x12\x1d.google.protobuf.FieldOptions\x18\xda\x86\x03 \x01(\t:G\n\x1e\x66ixed_array_with_length_define\x12\x1d.google.protobuf.FieldOptions\x18\xdb\x86\x03 \x01(\t:A\n\x11pointer_to_buffer\x12\x1d.google.protobuf.FieldOptions\x18\xdc\x86\x03 \x01(\x08:\x05\x66\x61lse::\n\x11\x63ontainer_pointer\x12\x1d.google.protobuf.FieldOptions\x18\xd1\x86\x03 \x01(\t:<\n\x0c\x66ixed_vector\x12\x1d.google.protobuf.FieldOptions\x18\xdd\x86\x03 \x01(\x08:\x05\x66\x61lse:?\n\x0f\x65num_as_bitmask\x12\x1d.google.protobuf.FieldOptions\x18\xde\x86\x03 \x01(\x08:\x05\x66\x61lse') | ||
| DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x11\x61pi_options.proto\x1a google/protobuf/descriptor.proto\"\x06\n\x04void*F\n\rAPISourceType\x12\x0f\n\x0bSOURCE_BOTH\x10\x00\x12\x11\n\rSOURCE_SERVER\x10\x01\x12\x11\n\rSOURCE_CLIENT\x10\x02:E\n\x16needs_setup_connection\x12\x1e.google.protobuf.MethodOptions\x18\x8e\x08 \x01(\x08:\x04true:C\n\x14needs_authentication\x12\x1e.google.protobuf.MethodOptions\x18\x8f\x08 \x01(\x08:\x04true:/\n\x02id\x12\x1f.google.protobuf.MessageOptions\x18\x8c\x08 \x01(\r:\x01\x30:M\n\x06source\x12\x1f.google.protobuf.MessageOptions\x18\x8d\x08 \x01(\x0e\x32\x0e.APISourceType:\x0bSOURCE_BOTH:/\n\x05ifdef\x12\x1f.google.protobuf.MessageOptions\x18\x8e\x08 \x01(\t:3\n\x03log\x12\x1f.google.protobuf.MessageOptions\x18\x8f\x08 \x01(\x08:\x04true:9\n\x08no_delay\x12\x1f.google.protobuf.MessageOptions\x18\x90\x08 \x01(\x08:\x05\x66\x61lse:4\n\nbase_class\x12\x1f.google.protobuf.MessageOptions\x18\x91\x08 \x01(\t:3\n\x0b\x66ield_ifdef\x12\x1d.google.protobuf.FieldOptions\x18\x92\x08 \x01(\t:9\n\x10\x66ixed_array_size\x12\x1d.google.protobuf.FieldOptions\x18\xd7\x86\x03 \x01(\r:<\n\x0cno_zero_copy\x12\x1d.google.protobuf.FieldOptions\x18\xd8\x86\x03 \x01(\x08:\x05\x66\x61lse:E\n\x15\x66ixed_array_skip_zero\x12\x1d.google.protobuf.FieldOptions\x18\xd9\x86\x03 \x01(\x08:\x05\x66\x61lse:@\n\x17\x66ixed_array_size_define\x12\x1d.google.protobuf.FieldOptions\x18\xda\x86\x03 \x01(\t:G\n\x1e\x66ixed_array_with_length_define\x12\x1d.google.protobuf.FieldOptions\x18\xdb\x86\x03 \x01(\t:A\n\x11pointer_to_buffer\x12\x1d.google.protobuf.FieldOptions\x18\xdc\x86\x03 \x01(\x08:\x05\x66\x61lse::\n\x11\x63ontainer_pointer\x12\x1d.google.protobuf.FieldOptions\x18\xd1\x86\x03 \x01(\t:<\n\x0c\x66ixed_vector\x12\x1d.google.protobuf.FieldOptions\x18\xdd\x86\x03 \x01(\x08:\x05\x66\x61lse:F\n\x1d\x63ontainer_pointer_no_template\x12\x1d.google.protobuf.FieldOptions\x18\xde\x86\x03 \x01(\t') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Regenerate pb2: serialized descriptor looks corrupted (“void”).*
The AddSerializedFile payload contains a literal “void*” in the message name area, which strongly suggests a stray byte and a broken FileDescriptorProto. Hand-editing pb2 is unsafe and can cause import-time DecodeError or incorrect extension registration. Please re-generate this file with protoc (same compiler/runtime 6.30.0) and commit the unmodified output.
Run this read-only check to highlight the suspicious byte sequence:
I can help script a clean re-gen flow if needed.
🏁 Script executed:
#!/bin/bash
rg -nP -C2 'void\*' aioesphomeapi/api_options_pb2.pyLength of output: 1976
Regenerate pb2: serialized descriptor looks corrupted ("void").*
The api.proto file uses "void" as a return type in RPC method definitions (e.g., returns (void)), which is a keyword, not a message type. The AddSerializedFile payload in line 29 contains a literal "void*" string that should not exist in a legitimate serialized FileDescriptorProto. Do not edit the api_pb2 files manually; instead, regenerate using protoc to resolve this corruption.
🤖 Prompt for AI Agents
In aioesphomeapi/api_options_pb2.py around line 29 the serialized
FileDescriptorProto is corrupted (contains "void*"), so do not edit this
generated file; instead fix and regenerate the .pb2. Open the corresponding
.proto (api.proto), replace any RPCs that use the invalid returns (void) with a
proper message type (e.g., google.protobuf.Empty from
google/protobuf/empty.proto or a defined Void message), ensure import
"google/protobuf/empty.proto" if using Empty, then re-run protoc with the
correct include paths (protoc -I. -I<protobuf_include> --python_out=. api.proto)
to regenerate aioesphomeapi/api_options_pb2.py and verify the AddSerializedFile
payload no longer contains "void*".
What does this implement/fix?
This reverts the change made in #1401 as it turned out to not scale well. It was simple enough to continue use container_pointer, but add a new version for non-template values called container_pointer_no_template
Types of changes
Related issue or feature (if applicable):
Pull request in esphome (if applicable):
Checklist:
tests/folder).