In protobuf-net can i have a byte field?
In protobuf-net can i have a byte field? Is a byte array field part of the protocol buffers spec?开发者_如何转开发
Basically I want to transmit various objects over the wire. In this case the byte[] Payload will be another protocol buffer serialised object. I do this so i don't need to specificy type
thanks
public sealed class CellUpdateTransmission
{
public int RowIndex { get; private set; }
public int CellIndex { get; private set; }
public byte[] Payload {get;private set;}
yes you can. In your second phase, move the bytes into a memory stream and then deserialize as per normal.
byte[] Payload= datafromsomewhere;
var ms = new MemoryStream(Payload);
var req = Serializer.Deserialize<AbcClass>(ms);
Yes, both byte
and byte[]
are supported; the latter maps to bytes
in the .proto spec. This is actually the same as how a sub-message is normally represented anyway. Just let the serializer know about the member (most simply: by adding an attribute such as [ProtoMember(3)]
).
精彩评论