為什麼 protobuf 更喜歡代碼生成器而不是運行時動態加載 (why protobuf prefer code-generator other than dynamic loading at runtime)


問題描述

為什麼 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.

(by fanlixBart)

參考文件

  1. why protobuf prefer code‑generator other than dynamic loading at runtime (CC BY‑SA 2.5/3.0/4.0)

#protocol-buffers #Code-Generation #config #auto-generate






相關問題

通過 Method.invoke() 調用靜態方法給了我 NPE (Static method invocation via Method.invoke() gave me NPE)

python中的protobuf到json (Protobuf to json in python)

如何序列化/反序列化使用 ScalaPB 的“oneof”的 protobuf 消息? (How to serialize/deserialize a protobuf message that uses 'oneof' with ScalaPB?)

序列化和反序列化未知的繼承類型 (Serializing and deserializing unknown inherited types)

Thrift 與協議緩衝區 (Thrift vs Protocol buffers)

如何在客戶端排除導入 (How to exclude an import on client side)

為什麼當我安裝了 Tensorflow 的所有庫後,會出現無目錄錯誤? (Why do I get a no directory error, when I have installed all the libraries for Tensorflow?)

如何為 C# <proto/> 定義傳遞experimental_allow_proto3_optional 以在proto3 中啟用可選? (How to pass experimental_allow_proto3_optional for C# <proto/> definitions to enable optional in proto3?)

CentOS7 的 libprotobuf-lite.so 文件在 CentOS8 機器上工作嗎? (is libprotobuf-lite.so file from CentOS7 working in CentOS8 machine?)

protogen - 支持 <Property> 指定的語法 (protogen - support the <Property>Specified syntax)

.Net 字典類型在 protobuff (.Net dictionary type in protobuff)

為什麼 protobuf 更喜歡代碼生成器而不是運行時動態加載 (why protobuf prefer code-generator other than dynamic loading at runtime)







留言討論