問題描述
為什麼 protobuf 更喜歡代碼生成器而不是運行時動態加載 (why protobuf prefer code‑generator other than dynamic loading at runtime)
Protobuf 更喜歡將 xxx.proto 編譯為源代碼(如 protoc)
除了庫之外只是 加載 xxx .proto at runtime(如DynamicMessage,protobuf‑dynamic)
為什麼更多的項目更喜歡這種方式?
一些比較:
- compute: 編譯 vs runtime
- reload: recompile‑proto + recompile‑program + restart vs reload config
- 檢查語法:隨時編譯vs
- 客戶端更新:rebuild‑client + download vs download‑proto + reload
參考解法
方法 1:
Many programming languages are not scripting languages, C++ for instance. For those type of languages it is preferred and often required to know what you are dealing with at compile time. This instead of generating the message class format at run time. If you do that you need a lot of type checking and availability checking to have the code working properly and consistent. In theory you could supply a different proto file in which case the code should not crash.