简体   繁体   English

在不同平台上通过管道传输数据的最佳和安全方式

[英]Best and safe way to transfer data over a pipe on different platform

Currently I am facing an issue where i am passing a buffer object over a pipe from x64 arch to x86 arch. 目前我正面临一个问题,我将缓冲区对象从x64 arch传递到x86 arch。 The object also contains some pointer values, which is 8 bytes in x64 which the same pointer size on x86 is 4 bytes. 该对象还包含一些指针值,在x64中为8个字节,x86上的相同指针大小为4个字节。 Now when i am transmitting the object over pipe then size of it is bit more than what x86 platform was expecting for the same object (because pointer size in here is less). 现在,当我通过管道传输对象时,它的大小比x86平台对同一对象所期望的要多一些(因为这里的指针大小较小)。 What i could understood from similar post in this forum that i might need to use serialization but i do not know how as i have never used serialization before. 我可以从这个论坛中的类似帖子中了解到我可能需要使用序列化,但我不知道我以前从未使用过序列化。 Will serialization will solve this problem? 序列化会解决这个问题吗? I am using C++ with GCC compiler. 我正在使用C ++与GCC编译器。 I want the product would work on all arch (ia64, x64 or x86). 我希望该产品适用于所有拱门(ia64,x64或x86)。

A pointer is an address to a memory location within your local running program*. 指针是本地运行程序*中内存位置的地址。 It is useless to send it to another program, more useless to a program running on another machine, even more useless if the architecture of the other machine is different. 将它发送到另一个程序是没用的,对于在另一台机器上运行的程序更无用,如果另一台机器的架构不同则更无用。

Using serialization in your context means sending the content of what is pointed to by the pointer instead of sending the meaningless pointer itself. 在上下文中使用序列化意味着发送指针所指向的内容,而不是发送无意义的指针本身。

To achieve cross-architecture data sending, the easier is to use text for data transfers. 要实现跨架构数据发送,更容易使用文本进行数据传输。 Most if not all of widely used cross-architecture protocols use text: HTTP, IMAP, IRC ... 大多数(如果不是全部)广泛使用的跨架构协议都使用文本:HTTP,IMAP,IRC ......

*: I use program instead of process . *:我使用program而不是process

boost serialization is designed specifically to : boost序列化专门用于:

Here, we use the term "serialization" to mean the reversible deconstruction of an arbitrary set of C++ data structures to a sequence of bytes. 在这里,我们使用术语“序列化”来表示将任意一组C ++数据结构可逆地解构为字节序列。 Such a system can be used to reconstitute an equivalent structure in another program context. 这样的系统可用于在另一个程序上下文中重构等效结构。 Depending on the context, this might used implement object persistence, remote parameter passing or other facility. 根据上下文,这可能使用实现对象持久性,远程参数传递或其他工具。 In this system we use the term "archive" to refer to a specific rendering of this stream of bytes. 在这个系统中,我们使用术语“archive”来指代这个字节流的特定呈现。 This could be a file of binary data, text data, XML, or some other created by the user of this library. 这可以是二进制数据,文本数据,XML或由该库的用户创建的一些其他文件。

By the way, use POD structures, and make sure to have use data types of a specific type. 顺便说一句,使用POD结构,并确保使用特定类型的数据类型。 For that use predefined types (for example, take a look here ) 为此使用预定义类型(例如,看看这里

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

Protocol buffers are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data – think XML, but smaller, faster, and simpler. 协议缓冲区是Google的语言中立,平台中立,可扩展的机制,用于序列化结构化数据 - 想想XML,但更小,更快,更简单。 You define how you want your data to be structured once, then you can use special generated source code to easily write and read your structured data to and from a variety of data streams and using a variety of languages – Java, C++, or Python. 您可以定义数据的结构化时间,然后可以使用特殊生成的源代码轻松地在各种数据流中使用各种语言(Java,C ++或Python)编写和读取结构化数据。

Worked for me on x86/64, arm 在x86 / 64上为我工作,手臂

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM