Interleave protobuf-net and file

I need to exchange both protobuf-net objects and files between computers, and I'm trying to find a better way to do this. Is there a way for A to tell B that the next object is a proto-buf or file? Otherwise, when the file is transferred, is there a way to find out that the file has ended and the subsequent Byte [] is protobuf?

Using C # 4.0, Visual Studio 2010

Thank you Manish

+1
source share
1 answer

This has nothing to do with protobuf or files, and everything related to your comms protocol, in particular "framing". It just means: how you produce sub-messages in a single thread. For example, if it is a raw socket that you can send (all)

  • short message type, possibly byte: 01 for a file, 02 for a protobuf message for a specific file.
  • length prefix (usually 4 bytes in byte order)
  • payload consisting of the previous number of bytes

Then rinse and repeat for each message.

You do not indicate which comments you ask, so I can be more specific.

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

+1
source

Source: https://habr.com/ru/post/1412644/


All Articles