我想序列化一个'Player'类,并通过我的网络流发送给客户端.
球员类
[ProtoMember(1)]
public int flag;
[ProtoMember(2)]
public Int16 id;
[ProtoMember(3)]
public MyVector3 CharPos;
[ProtoMember(7)]
public bool spawned;
Run Code Online (Sandbox Code Playgroud)
MyVector3(由于protobuf不支持序列化的事实Vector3)
[ProtoContract]
public class MyVector3
{
[ProtoMember(4)]
public float X { get; set; }
[ProtoMember(5)]
public float Y { get; set; }
[ProtoMember(6)]
public float Z { get; set; }
public MyVector3()
{
this.X = 0.0f;
this.Y = 0.0f;
this.Z = 0.0f;
}
public MyVector3(float x, float y, float z)
{
this.X = x;
this.Y = y;
this.Z = …Run Code Online (Sandbox Code Playgroud) 我有,List<HtmlAgilityPack.HtmlNode>但protobuf-net给我错误,它没有合同.当我没有源时,如何为它指定合同?它实际上说它无法推断出类型,但我认为这是因为我没有使用它的属性,对吗?
默认的二进制序列化程序也会抱怨,因为类型未标记为可序列化.
编辑:错误消息是:
Type is not expected, and no contract can be inferred: HtmlAgilityPack.HtmlNode
Run Code Online (Sandbox Code Playgroud)