简体   繁体   English

如何为 C# 传递实验性_allow_proto3_optional<proto /> 在 proto3 中启用可选的定义?

[英]How to pass experimental_allow_proto3_optional for C# <proto/> definitions to enable optional in proto3?

I've looked everywhere for this.我到处找这个。 The C# grpc people don't know how to do it, and point to the grpc/grpc people for the tooling but you're not allowed to ask questions there. C# grpc 的人不知道该怎么做,并指向 grpc/grpc 人的工具,但你不能在那里提问。 I guess I could phrase this as a feature but that feels like cheating.我想我可以将其表述为一项功能,但这感觉就像在作弊。 (please add documentation too show how...) (请添加文档也显示如何...)

How does one pass the parameter for this to C# grpc in the <proto> definition so that we can use the optional keyword?如何在 <proto> 定义中将此参数传递给 C# grpc 以便我们可以使用 optional 关键字?

Thanks!谢谢!

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 :至于 2021 年 1 月,解决此问题的唯一方法是让您的 proto 文件名(或目录名)包含字符串test_proto3_optional ,正如protobuf 文档所指出的那样:

If you try to run protoc on a file with proto3 optional fields, you will get an error because the feature is still experimental.如果您尝试在具有 proto3 可选字段的文件上运行 protoc,您将收到错误消息,因为该功能仍处于试验阶段。 [...] There are two options for getting around this error: [...] 有两种方法可以解决此错误:

  1. Pass --experimental_allow_proto3_optional to protoc. --experimental_allow_proto3_optional传递给 protoc。
  2. Make your filename (or a directory name) contain the string test_proto3_optional .使您的文件名(或目录名)包含字符串test_proto3_optional This indicates that the proto file is specifically for testing proto3 optional support, so the check is suppressed.这表明 proto 文件是专门用于测试 proto3 可选支持的,因此禁止检查。

For more information see #977 (grpc-dotnet), #19164 (AspNetCore.Docs) and #23686 (grpc) issues.有关详细信息,请参阅#977 (grpc-dotnet)、 #19164 (AspNetCore.Docs) 和#23686 (grpc) 问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM