我应该如何序列化

我应该如何序列化

本文介绍了我应该如何序列化 Moose 对象数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 MooseX::StorageMoose 对象的序列化.我可以用它来将多个 Moose 对象序列化到同一个文件,或者更具体地说,是一个 Moose 对象的数组或散列吗?

I use MooseX::Storage for serialization of Moose objects. Can I use it for serialization of multiple Moose objects to the same file, or more specifically, an array or a hash of Moose objects?

我想我可以定义另一个 Moose 对象('array_of_myobj'),但这不是很优雅.

I guess I can define another Moose objects ('array_of_myobj') but this isn't very elegant.

那么,您建议如何序列化 Moose 对象的数组(或哈希)?

So, how would you recommend to serialize an array (or a hash) of Moose objects?

推荐答案

您不必因为文件 IO 可用而让 MooseX::Storage 管理您的文件 IO.你可以用它把你的对象打包到 hashrefs 中,然后用 YAML 或 Storable 或任何你自己的东西转储它们.这就是为什么 MooseX::Storage 区分三个级别的序列化.

You don't have to let MooseX::Storage manage your file IO just because it's available. You could use it to pack your objects into hashrefs and then dump them with YAML or Storable or whatever yourself. This is why MooseX::Storage distinguishes between three levels of serialization.

也就是说,我不同意创建一个包含您想要在给定上下文中序列化的所有其他对象的单个顶级对象是不雅的.

That said, I disagree that it is inelegant to make a single top-level object that contains all the other objects you want to serialize in a given context.

这篇关于我应该如何序列化 Moose 对象数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 05:10