List的 .proto 等价物是什么?在 protobuf 网络中?

发布于 2024-09-06 10:37:17 字数 307 浏览 1 评论 0原文

为了保持一定的一致性,我们对许多对象模型使用代码生成,其分支之一是通过单独的生成模块为 ProtocolBuffers 生成 .proto 文件。但此时,我对如何在 List 对象上实现生成感到困惑。

看起来这可以通过合同实现:

[ProtoMember(1)]
public List<SomeType> MyList {get; set;} 

但除此之外,我不确定如何或是否可以仅通过创建 .proto 文件/使用 VS 自定义工具来做到这一点。有什么想法吗?

To keep some consistency, we use code generation for a lot of our object models, and one of the offshoots of that has been generating the .proto files for ProtocolBuffers via a separate generation module. At this point though, I'm stumped at how to implement the generation for when it happens upon a List<T> object.

It looks like this is possible via contracts:

[ProtoMember(1)]
public List<SomeType> MyList {get; set;} 

but outside of that, I'm not sure how or if it's possible to do this only from creating the .proto file/using the VS custom tool. Any thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

童话 2024-09-13 10:37:17
repeated SomeType MyList = 1;

另外 - 它不是 100% 完美,但您可以尝试 GetProto():

class Program
{
    static void Main()
    {
        Console.WriteLine(Serializer.GetProto<Foo>());
    }
}
[ProtoContract]
public class Foo
{
    [ProtoMember(1)]
    public List<Bar> Items { get; set; }
}
[ProtoContract]
public class Bar { }

给出:

message Foo {
   repeated Bar Items = 1;
}

message Bar {
}

最后 - 如果您需要不同的输出,xslt 是用户可编辑的。

repeated SomeType MyList = 1;

Also - it is not 100% perfect, but you can try GetProto():

class Program
{
    static void Main()
    {
        Console.WriteLine(Serializer.GetProto<Foo>());
    }
}
[ProtoContract]
public class Foo
{
    [ProtoMember(1)]
    public List<Bar> Items { get; set; }
}
[ProtoContract]
public class Bar { }

gives:

message Foo {
   repeated Bar Items = 1;
}

message Bar {
}

Finally - if you need different output, the xslt is user-editable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文