交错protobuf

编程入门 行业动态 更新时间:2024-10-25 01:21:05
本文介绍了交错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

本文发布于:2023-07-27 00:20:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1219201.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:protobuf

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!