Protobuf net 如何使用基元类型作为代理?

Protobuf net 如何使用基元类型作为代理?,protobuf-net,Protobuf Net,我使用定点类型,例如 public struct Fixed16 { public int N; public static implicit operator double(Fixed16 x) { return (double)x / 65536.0; } public static implicit operator Fixed16(double x) { return Fixed16.FromFixed((int)(x * 6553

我使用定点类型,例如

public struct Fixed16 {
    public int N;
    public static implicit operator double(Fixed16 x)
        { return (double)x / 65536.0; }
    public static implicit operator Fixed16(double x)
        { return Fixed16.FromFixed((int)(x * 65536.0)); }
    public static Fixed16 FromFixed(int n) { return new Fixed16 { N = n }; }
    ...
}

为了提高效率,在协议缓冲区中,每次在其他类型中使用时,我都希望将其存储为普通整数。怎么做?

AFAIK,protobuf net目前不支持原始类型作为代理。它可能会工作,但它会花一点时间,我看它。选项:

延迟这些更改的发生,并使用原始代理 将pass-thru属性添加到修复了16个实例的代码中,以将数据公开为int,并将这些属性标记为序列化,即

public Fixed16 Foo {get;set;}
[ProtMember(17)]
private int FooSerialized { get { return Foo; } set { Foo = value; } }
标记Fixed16以序列化单个内部标头,并接受额外的字段标头

注意前两个选项应该是字节兼容的;第三个选项具有不同的布局,并且与其他两个选项不兼容字节