什么是对象编组?

发布于 2024-07-06 02:19:45 字数 28 浏览 6 评论 0原文

我经常听说这个概念,但我不太清楚它是什么。

I have heard this concept used frequently, but I don't have a really good grasp of what it is.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

哀由 2024-07-13 02:19:47

Marshalling 是将对象的内存表示形式转换为数据格式的过程被存储或传输。 它也称为序列化(尽管在某些情况下可能有所不同)。 对象的内存表示形式可以存储为二进制或 XML 或任何适合存储和/或传输的格式,以便您可以对其进行解组并取回原始对象。

作为使用示例,如果您有一些带有客户端和服务器组件的在线游戏,并且您想要将包含玩家统计数据和世界坐标的玩家对象从客户端发送到服务器(或相反),您可以简单地编组它在客户端,通过网络发送它,并在另一端解组它,对于服务器来说,它看起来就像该对象是在服务器本身上创建的一样。 这是一个红宝石示例:

srcplayer = Player.new
# marshal (store it as string)
str = Marshal.dump(srcplayer)
#unmarshal (get it back)
destplayer = Marshal.load(str)

Marshalling is the process of transforming the memory representation of an object to a data format that could be stored or transmitted. It's also called serialization (although it could be different in certain contexts). The memory representation of the object could be stored as binary or XML or any format suitable for storage and/or transmission in a way that allows you to unmarshal it and get the original object back.

For an example of usage, if you have some online game with a client and server components and you wanted to send the player object containing player stats and world coordinates from the client to the server (or the other way around), you could simply marshal it at the client, send it over the network, and unmarshal it at the other end and it would appear for the server as if the object was created on the server itself. Here's a ruby example:

srcplayer = Player.new
# marshal (store it as string)
str = Marshal.dump(srcplayer)
#unmarshal (get it back)
destplayer = Marshal.load(str)
不一样的天空 2024-07-13 02:19:47

我澄清了谷歌搜索“数据编组”,第一个点击是 在某个名为 webopedia 的地方 这非常好。 其要点是将数据来回转换为某种形式,例如通过网络传输。 它解决的问题是您无法真正以程序可用的形式通过网络传输数据。 您必须解决许多问题,包括数据的字节序、如何存储复杂的数据类型(例如字符串)等。

编组不仅仅是为了解决网络传输问题,还包括其他问题,例如从一种体系结构到另一种体系结构(可能是不同的语言)特别是那些可能使用虚拟机之类的东西以及其他“翻译”问题的人。

I clarified a google search to "data marshalling" and the first hit was on some place called webopedia which is pretty good. The gist is that you transform data back and forth to a form for things like transmission over a network. The problem it solves is that you can't really transmit data over a network in a form that is usable by a program. You have to solve a number of issues including things like endianness of data, how you store complex data types like strings, etc.

Marshalling is not just to solve network transmission problems but other problems such as going from one architecture to another, maybe different languages especially those that might use things like virtual machines, and other "translation" problems.

没有心的人 2024-07-13 02:19:47

这意味着将任何数据转换为另一种数据类型以传输到另一个系统。

例如,将结构编组到 XML 文档中以发送到 Web 服务,或者编组指针以发送到不同的线程单元。

It means turning any data into another data type to transfer to another system.

E.g., marshalling a struct into an XML document to send to the webservice, or marshalling a pointer to send to a different thread apartment.

去了角落 2024-07-13 02:19:47

基本上,它是一个表达式,用于一般地将对象(或类似对象)转换为另一种表示形式,(例如)可以通过线路发送或存储到磁盘(通常是字符串或二进制流)。相反,解组,描述了读取编组的相反方向表示和重新创建对象或任何早期存在的内存结构

是 JSON 。

Basically it's an expression for generically transforming an object (or similar) into another representation that (e.g.) can be sent over the wire or stored to disk (typically string or binary stream. The opposite, unmarshalling, describes the opposite direction of reading the marshalled representation and re-creating an object or whatever in-memory-structure existed earlier.

Another current everyday example is JSON

闻呓 2024-07-13 02:19:47

编组是跨应用程序边界或不同数据格式之间传输数据的过程。 编组非常常见,例如将数据写入磁盘或数据库在技术上就是编组,但是该术语往往用于描述“外部”API 或进程间通信的数据转换。

例如,在 .NET 中,托管和非托管代码之间的通信(例如访问某些 win32 API)可能需要编组,以便在托管 C# 对象和 C/C++ 样式对象(结构、句柄、输出缓冲区、等)静态 Marshal 类的帮助 可能会有所帮助。

Marshalling is the process of transferring data across application boundaries or between different data formats. Marshalling is very common, for example writing data to disk or to a database is technically marshalling, however the term tends to be used to describe data conversion for "foreign" APIs or for interprocess communication.

For example, in .NET, communicating between managed and unmanaged code (such as accessing certain win32 APIs) will likely require marshalling in order to convert back and forth between managed C# objects and C/C++ style objects (structs, handles, output buffers, etc.) The help for the static Marshal class might be helpful.

素衣风尘叹 2024-07-13 02:19:47

编组是跨 ABI 边界调用时需要发生的调用参数的转换。 边界可能是在 COM 客户端和 COM 服务器之间,其中 COM 客户端的 ABI 类型需要由 COM 库编组为 COM 二进制文件的 ABI(在 COM 中,编组也可以指转换将跨越同一进程内的单元边界时所需的参数设置为要发送到所属线程的消息队列的消息格式,然后由 COM 窗口过程处理和解组,并且在跨越进程边界的情况下,附加由COM代理编组到RPC/LPC的步骤,即到LPC端口的LPC消息)。 边界可能是在虚拟环境中执行高级代码与在其中实现/设置环境的本机代码之间,其中在在虚拟环境中实现的高级代码的 ABI 之间发生转换。母语的 ABI,以及关于这些类型的母语的典型 ABI。

第二种情况的一个例子是 Mono .NET。 您可以从非托管(本机)代码(C++,不由虚拟机库管理,而是由内部对象和结构表示)调用托管代码(高级语言,由虚拟机库管理和运行,并由内部对象和结构表示)链接到库),并且在使用虚拟机库 API 设置虚拟机时,您还可以基于 C++ 代码进行的内部绑定,执行从 C# 到非托管(本机)代码 (C++) 的本机调用。 例如,C# 中的 System.String 在内部由 MonoString 表示。 MonoString 是一个使用 C++ ABI 的 C++ 对象,但其标准使用方式以及本机代码期望在 ABI 中表示字符串类型的参数的方式不同,因为 VM库使用 C++ ABI 的某种排列在逻辑上实现了自己的 ABI——装箱在 MonoString* 类型的 C++ 对象中,而不是 const wchar_t*。 使用 P/Invoke 将 System.String 传递到 C# 中的本机调用 (执行自动编组)会导致在自动编组发生时将 const wchar_t* 传递给本机调用。 但是,当您使用内部调用时,它将作为 MonoString* 传递,C++ 函数必须对其自身进行编组,然后编组返回到 VM 逻辑 ABI 类型所需的任何内容。 使用内部调用时,只有 blittable 类型不需要编组,例如 int,这是一个 System.Int32 作为 gint32 传递,这只是一个int

另一个例子是 Spidermonkey JS 引擎,它在 HTMLElement 的 C++ 本机类型和内部运行时表示,JSObject,它表示 JavaScript 中的 HTMLElement 类型。

Marshalling is the conversion of call parameters that needs to occur when calling across an ABI boundary. The boundary may be between a COM client and a COM server, where the types of the ABI of the COM client need to be marshalled by the COM library to the ABI of the COM binary (in COM, marshalling can also refer to the conversion of parameters required when crossing an apartment boundary within the same process to the format of a message to be sent to the owning thread's message queue to be then handled and unmarshalled by the COM window procedure, and in the event of crossing a process boundary, the additional step of marshalling to an RPC/LPC by a COM proxy, i.e. an LPC message to an LPC port). The boundary may be between the execution of high-level code in a virtual environment and the native code that the environment is implemented in / set up the environment, where a conversion takes place between the ABI of the high-level code, implemented in an ABI of the native language, and a typical ABI of the native language concerning those types.

One example of the second case is Mono .NET. You can call managed code (high level language, which is managed and run by the virtual machine library and represented by internal objects and structures) from unmanaged (native) code (C++, which isn't managed by the virtual machine library, but instead is linked to the library), and you can also perform native calls from C# to unmanaged (native) code (C++) based on internal bindings made by C++ code when setting up the virtual machine using the virtual machine library API. For instance, System.String in C# is internally represented by a MonoString. MonoString is a C++ object which uses the C++ ABI, but in a different way to how it is used standardly and how the native code expects parameters of a string type to be represented in the ABI, because the VM library has logically implemented its own ABI using a certain arrangement of the C++ ABI -- boxed in a C++ object of type MonoString* instead of const wchar_t*. Passing a System.String to a native call in C# using P/Invoke (which performs automatic marshalling) causes a const wchar_t* to be passed to the native call as automatic marshalling takes place. When you use internal calls however, it will be passed as a MonoString*, which the C++ function will have to marshal itself and then marshal whatever it needs to return back to a type of the VM's logical ABI. Only blittable types don't need to be marshalled when using internal calls, for instance, int, which is a System.Int32 is passed as a gint32, which is just an int.

Another example is Spidermonkey JS engine, which marshals between a C++ native type of HTMLElement and an internal runtime representation, JSObject, which represents the HTMLElement type in javascript.

绅士风度i 2024-07-13 02:19:47

从编程的一般意义上来说,它只是意味着以一种格式获取数据并将其转换为其他子系统可接受的格式。

In a very generic sense in programming it simply means taking data in one format and transforming it into a format that is acceptable by some other sub-system.

养猫人 2024-07-13 02:19:46

人们已经非常清楚地定义了编组,因此我将跳过定义并跳至示例。

远程过程调用使用编组。 调用远程函数时,您必须将参数编组为某种标准格式,以便可以通过网络传输。

People have defined marshalling quite clearly already, so I'll skip the definition and jump to an example.

Remote procedure call uses marshalling. When invoking remote functions you will have to marshall the arguments to some kind of standard format so it can be transport across the network.

对不⑦ 2024-07-13 02:19:45

将内存中的对象转换为可以写入磁盘或通过线路发送等的格式。

维基百科的描述

Converting an object in memory into a format that can be written to disk, or sent over the wire, etc.

Wikipedia's description.

岁月如刀 2024-07-13 02:19:45

我不敢苟同,维基百科对此非常清楚。

在计算机科学中,编组
(类似于序列化)是
记忆转化的过程
对象到数据的表示
适合存储的格式或
传播。 通常使用它
当数据必须在之间移动时
计算机程序的不同部分
或从一个程序到另一个程序。

http://en.wikipedia.org/wiki/Marshalling_(computer_science)

I beg to differ, Wikipedia is pretty clear on this.

In computer science, marshalling
(similar to serialization) is the
process of transforming the memory
representation of an object to a data
format suitable for storage or
transmission. It is typically used
when data must be moved between
different parts of a computer program
or from one program to another.

http://en.wikipedia.org/wiki/Marshalling_(computer_science)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文