ネットワークのトラフィックを減らすために、 の代わりに protobuf-net を使用したいのですがBinaryFormatter
、次のエラーが発生しました。
No serializer defined for type: System.Drawing.Color
WB メッセージ:
[ProtoContract]
[Serializable]
public abstract class WBMessage
{
[ProtoMember(1)]
public Color setColor1;
[ProtoMember(2)]
public UInt16 userNo;
public abstract WHITEBOARD_MESSAGE_TYPE MessageType
{
get;
}
[ProtoMember(3)]
public string age;
public enum WHITEBOARD_MESSAGE_TYPE
{
enWBBegin,
enWBLine,
enWBRectangle,
enWBRectangleF,
enWBEllipse,
enWBEllipseF,
enWBClearScreen,
enWBText,
enWBEnd
};
}
WBMsgDrawBegin:
[ProtoContract]
[ProtoInclude(1, typeof(WBMessage))]
public class WBMsgDrawBegin : WBMessage
{
private const WHITEBOARD_MESSAGE_TYPE m_enMsgType = WHITEBOARD_MESSAGE_TYPE.enWBBegin;
public override WHITEBOARD_MESSAGE_TYPE MessageType
{
get
{
return m_enMsgType;
}
}
[ProtoMember(4)]
public int x;
[ProtoMember(5)]
public int y;
[ProtoMember(6)]
public bool m_bMouseDown;
[ProtoMember(7)]
public string name;
}
使用法:
WBMsgDrawBegin item1 = new WBMsgDrawBegin();
item1.setColor1 = Color.AliceBlue;
item1.name = "test";
item1.age = "31";
item1.x = 10998;
item1.y = 10089;
Stream stream = new MemoryStream();
MemoryStream ms = new MemoryStream();
Serializer.SerializeWithLengthPrefix<WBMsgDrawBegin>(ms, item1, PrefixStyle.Base128, 0);