交错protobuf-net和文件 [英] interleave protobuf-net and file

查看:70
本文介绍了交错protobuf-net和文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在计算机之间交换protobuf-net对象和文件,并试图找出实现此目的的最佳方法。 A是否有办法通知B紧随其后的对象是协议缓冲区还是文件?或者,在传输文件时,是否有办法知道文件已结束并且其后的Byte []是protobuf?

I need to exchange both protobuf-net objects and files between computers and am trying to figure out the best way to do that. Is there a way for A to inform B that the object that follows is a protobuf or a file? Alternately, when a file is transmitted, is there a way to know that the file has ended and the Byte[] that follows is a protobuf?

使用C#4.0,Visual Studio 2010

Using C# 4.0, Visual Studio 2010

谢谢Manish

推荐答案

这无关与protobuf或文件,以及与通讯协议有关的一切,特别是成帧。这意味着简单:如何在单个流中标记子消息。例如,如果这是原始套接字,则可以选择发送(全部)

This has nothing to do with protobuf or files, and everything to do with your comms protocol, specifically "framing". This means simply: how you demark sub-messages in a single stream. For example, if this is a raw socket you might choose to send (all of)


  • 简短的消息类型,也许是字节: 01表示文件,02表示特定文件的protobuf消息

  • 长度前缀(通常为4字节,网络字节顺序)

  • 有效负载,由先前的字节数组成。

然后冲洗并重复每条消息。

Then rinse and repeat for each message.

您没有说明您要问的是什么通讯,所以我可以更具体一些。

You don't state what comms you are asking, so I can be more specific.

顺便说一句,另一种方法是将文件视为protobuf带有byte []成员的消息-尽管主要适用于小文件

Btw, another approach would be to treat a file as a protobuf message with a byte[] member - mainly suitable for small files, though

这篇关于交错protobuf-net和文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆