如何描述 protobuf-net 中的 Any 类型?

How can I describe the Any type in protobuf-net?

在 google protobuf v3 中,有 Any 类型允许您序列化 name/url 标识消息 (https://developers.google.com/protocol-buffers/docs/proto3#any, https://github.com/google/protobuf/blob/master/src/google/protobuf/any.proto)。

是否可以描述这个构造并拥有 protobuf-net serialize/deserialize?我需要它遵循 protobuf v3 标准,所以 DynamicType/bcl.NetObjectProxy 很接近,但二进制不兼容。

如果不是,使用 protobuf-net 使用 Any 构造序列化对象的最佳方法是什么?我真的不想切换到 protobuf-csharp 版本。

最终,Any 可以被视为:

[ProtoContract]
public sealed class Any {
    [ProtoMember(1)] public string type_url {get;set;}
    [ProtoMember(2)] public byte[] value {get;set;}
}

从那里,您可以在 url 上执行 switch(或字典查找),将值加载到 MemoryStream,然后回调到 protobuf-net.对于序列化,类型 url 或许可以存储在针对该类型的属性中,但这是更棘手的雾反序列化。也许 string-to-Type 字典和 non-generic API.