The best and safest way to transfer data through a pipe on another platform

I am currently facing a problem when I pass a buffer object over a channel from x64 arch to x86 arch. The object also contains some pointer values, which is 8 bytes in x64, which has the same x86 pointer size, equal to 4 bytes. Now, when I pass the object through the pipe, its bit size is larger than the x86 platform expected for the same object (since the size of the pointer is smaller here). What I could understand from a similar post on this forum is that I might need to use serialization, but I don’t know how I never used serialization before. Will serialization solve this problem? I am using C ++ with the GCC compiler. I want the product to work on all arches (ia64, x64 or x86).

+6
source share
3 answers

Boost serialization designed specifically for:

Here we use the term “serialization” to mean the reversible deconstruction of an arbitrary set of C ++ data structures for a sequence of bytes. Such a system can be used for an equivalent structure in another context of the program. Depending on the context, this could use object retention, remote parameter passing, or another object. In this system, we use the term “archive” to refer to the specific rendering of this byte stream. It can be a binary data file, text data, XML, or some other file created by the user of this library.

By the way, use POD structures and make sure that you are using data types of a specific type. Use predefined types for this (see here for example)

+2
source

A pointer is an address in a memory location in the local program *. It is useless to send it to another program, more useless for a program running on another machine, even more useless if the architecture of another machine is different.

Using serialization in your context means sending the contents of what the pointer points to, rather than sending the most meaningless pointer.

To enable data transfer using cross-architecture, it is easier to use text to transfer data. Most, if not all, commonly used cross-architecture protocols use text: HTTP, IMAP, IRC ...

*: I use program instead of process .

+4
source

http://code.google.com/apis/protocolbuffers/

Protocol buffers are a Google-neutral language, platform-neutral, an extensible mechanism for serializing structured data - I think XML, but smaller, faster and easier. You determine how you want your data to be structured once, then you can use the special generated source code to easily write and read your structured data to and from various data streams and use different languages ​​- Java, C ++ or Python

Worked for me on x86 / 64, hand

+1
source

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


All Articles