在 protobuf-net 中我可以有一个字节字段吗?
在 protobuf-net 中我可以有一个字节字段吗?字节数组字段是协议缓冲区规范的一部分吗?
基本上我想通过电线传输各种对象。在这种情况下,byte[]有效负载将是另一个协议缓冲区序列化对象。我这样做是为了不需要具体输入,
谢谢
public sealed class CellUpdateTransmission
{
public int RowIndex { get; private set; }
public int CellIndex { get; private set; }
public byte[] Payload {get;private set;}
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;}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,你可以。在第二阶段,将字节移动到内存流中,然后按正常方式反序列化。
yes you can. In your second phase, move the bytes into a memory stream and then deserialize as per normal.
是的,
byte
和byte[]
均受支持;后者映射到 .proto 规范中的字节。这实际上与子消息通常的表示方式相同。只需让序列化程序了解该成员(最简单:通过添加一个属性,例如[ProtoMember(3)]
)。Yes, both
byte
andbyte[]
are supported; the latter maps tobytes
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)]
).