chenBright commented on issue #3287:
URL: https://github.com/apache/brpc/issues/3287#issuecomment-4552550621

   Thanks for the heads-up and the offer to help with the migration. After 
surveying the codebase, here's the planned proposal.
   
     **Scope**
   
     39 .proto files in the repo enable cc_generic_services (7 in brpc's own 
builtin services, 23 in examples, 7 in tests, 1 in tools). We plan to migrate 
all of
     them to a brpc-owned protoc plugin before xx_generic_services becomes a 
no-op.
   
   **Plan**
   
     1. New protoc-gen-brpc C++ plugin, modeled after the existing 
protoc-gen-mcpack plugin we already ship (src/mcpack2pb/generator.cpp). Single 
binary, standard PluginMain entry point.
     2. Inject into the stock *.pb.h / *.pb.cc via OpenForInsert 
(namespace_scope for declarations, global_scope for definitions). This keeps 
#include "foo.pb.h" working unchanged — zero source-code changes
     for users. Since the plugin is only active on protobuf versions where 
cc_generic_services is already a no-op, there's no risk of duplicate-symbol 
collisions with the legacy stubs.
     3. Generated output is source-compatible with what cc_generic_services 
produces today: same class names, same namespaces, same virtual signatures, 
same _Stub(RpcChannel*) constructor. We're aiming for
     source-level compatibility only — old/new outputs never coexist in the 
same binary, so byte-level ABI alignment isn't required.
     4. No dependency on protobuf private symbols. Instead of 
internal::AssignDescriptors + descriptor_table_xxx + 
file_level_service_descriptors_xxx, we resolve descriptors via the public
     DescriptorPool::generated_pool()->FindServiceByName(...) API, cached at 
module-init time into file-scope pointers — runtime cost is a single load, no 
call_once check on the hot path.
     5. Misuse detection — to catch users who forget to remove option 
cc_generic_services from their .proto or forget to wire the plugin into their 
build:
       - Compile-time: generated classes embed a BrpcGeneratedTag typedef; 
Server::AddService does a static_assert on it.
       - Runtime: each generated service registers its full name in a global 
set at static init; AddServiceInternal rejects services not produced by the 
plugin, with an actionable error message.
       - Hand-written google::protobuf::Service subclasses (we have one — 
BaiduMasterService) can declare the tag manually or go through an 
AddServiceUnchecked escape hatch.
   
     @haberman I would be grateful for any feedback or suggestions you may have 
on my proposal.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to