是否有任何工具可以将 docorated C# probuff-net class 文件逆向工程为 .proto 文件
is there any tool to reverse engineer docorated C# probuff-net class file to .proto file
以下代码是来自 protobuf-net 的 C# 修饰代码。
using ProtoBuf;
using System;
using System.Collections.Generic;
namespace Lib
{
[Serializable]
[ProtoContract]
public class CAcct
{
[ProtoMember(1)]
public int Acct { get; set; }
[ProtoMember(2)]
public DateTime BalDt { get; set; }
//Serialize bytes to object
public byte[] Serialize()
{
return CUtility.ProtoSerialize<CAcct>(this);
}
//DeSerialize bytes to object
public CAcct DeSerialize(byte[] bytes)
{
return CUtility.ProtoDeserialize<CAcct>(bytes);
}
}
}
在生成 .proto 文件方面需要帮助,以便将其用于 java 实施。
string proto = Serializer.GetProto<CAcct>();
但是! DateTime
是 x-plat 的皇家 PITA,除非您愿意更改为新的 "well known" 时间戳类型。如果你能做到这一点,注意它会改变你的数据布局(因此会破坏兼容性)- 添加 DataFormat = DataFormat.WellKnown
到你的 [DataMember(...)]
.
当我第一次添加 DateTime
处理时,这个 "well known" 时间戳类型不存在,我选择了不同的布局。请注意,"well known" 格式需要最新版本。
如果将 DateTime
属性 更改为:
[ProtoMember(2, DataFormat = DataFormat.WellKnown)]
public DateTime BalDt { get; set; }
然后 .proto 模式变为(如 proto2):
syntax = "proto2";
package Lib;
import "google/protobuf/timestamp.proto";
message CAcct {
optional int32 Acct = 1 [default = 0];
optional .google.protobuf.Timestamp BalDt = 2;
}
或(作为 proto3);
syntax = "proto3";
package Lib;
import "google/protobuf/timestamp.proto";
message CAcct {
int32 Acct = 1;
.google.protobuf.Timestamp BalDt = 2;
}
其中任何一个都可以与 Java 一起正常工作,没有任何痛苦。
以下代码是来自 protobuf-net 的 C# 修饰代码。
using ProtoBuf;
using System;
using System.Collections.Generic;
namespace Lib
{
[Serializable]
[ProtoContract]
public class CAcct
{
[ProtoMember(1)]
public int Acct { get; set; }
[ProtoMember(2)]
public DateTime BalDt { get; set; }
//Serialize bytes to object
public byte[] Serialize()
{
return CUtility.ProtoSerialize<CAcct>(this);
}
//DeSerialize bytes to object
public CAcct DeSerialize(byte[] bytes)
{
return CUtility.ProtoDeserialize<CAcct>(bytes);
}
}
}
在生成 .proto 文件方面需要帮助,以便将其用于 java 实施。
string proto = Serializer.GetProto<CAcct>();
但是! DateTime
是 x-plat 的皇家 PITA,除非您愿意更改为新的 "well known" 时间戳类型。如果你能做到这一点,注意它会改变你的数据布局(因此会破坏兼容性)- 添加 DataFormat = DataFormat.WellKnown
到你的 [DataMember(...)]
.
当我第一次添加 DateTime
处理时,这个 "well known" 时间戳类型不存在,我选择了不同的布局。请注意,"well known" 格式需要最新版本。
如果将 DateTime
属性 更改为:
[ProtoMember(2, DataFormat = DataFormat.WellKnown)]
public DateTime BalDt { get; set; }
然后 .proto 模式变为(如 proto2):
syntax = "proto2";
package Lib;
import "google/protobuf/timestamp.proto";
message CAcct {
optional int32 Acct = 1 [default = 0];
optional .google.protobuf.Timestamp BalDt = 2;
}
或(作为 proto3);
syntax = "proto3";
package Lib;
import "google/protobuf/timestamp.proto";
message CAcct {
int32 Acct = 1;
.google.protobuf.Timestamp BalDt = 2;
}
其中任何一个都可以与 Java 一起正常工作,没有任何痛苦。