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


問題描述

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

我到處找這個。C# grpc 的人不知道怎麼做,並指向 grpc/grpc 的人提供工具,但你不能在那裡提問。我想我可以將其表述為一項功能,但這感覺就像在作弊。(請添加文檔也顯示如何...)

如何將參數傳遞給中的C# grpc 定義以便我們可以使用可選關鍵字?

謝謝!


參考解法

方法 1:

As for January 2021, the only ‑ yet hacky ‑ way around this is to make your proto filename (or a directory name) contain the string test_proto3_optional, as pointed out by protobuf documentation:

If you try to run protoc on a file with proto3 optional fields, you will get an error because the feature is still experimental. [...] There are two options for getting around this error:

  1. Pass ‑‑experimental_allow_proto3_optional to protoc.
  2. Make your filename (or a directory name) contain the string test_proto3_optional. This indicates that the proto file is specifically for testing proto3 optional support, so the check is suppressed.

For more information see #977 (grpc‑dotnet), #19164 (AspNetCore.Docs) and #23686 (grpc) issues.

(by James HancockSezi)

參考文件

  1. How to pass experimental_allow_proto3_optional for C# definitions to enable optional in proto3? (CC BY‑SA 2.5/3.0/4.0)

#protocol-buffers #gRPC #C#






相關問題

通過 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)







留言討論