问题标签 [binary-serialization]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
268 浏览

c# - 反序列化没有类型的对象

有没有办法在不知道序列化对象的情况下查看序列化对象的元数据和属性信息?

我有一堆二进制序列化对象,需要数据挖掘,但我无权访问原始类。现在,可以定义虚拟类来填充数据,但不知道反序列化对象中保存了哪些信息,我无法验证是否缺少任何属性。

0 投票
3 回答
1106 浏览

c# - 在使用 BinaryFormatter 反序列化期间跳过元素

反序列化时是否有可能跳过序列化流的下一个“条目”?关于面向插件的架构,序列化对象图的不同部分可能会在另一个环境中成为未知类型(假设它们可以被安全地忽略)。试图反序列化这些当然会失败。

如何使它与二进制格式化程序一起使用?我是否必须计算长度并检索序列化条目的明确类型名称(例如字符串)并将其存储在条目本身之前,以便在反序列化时跳过它(通过增加流指针)?或者是否有更好的选择,对序列化表示的特定问题操作较少?

0 投票
4 回答
539 浏览

java - Malformed binary serialization of HashMap

I wrote some code to serialize a HashMap<String,Double> by iterating entries and serializing each of them instead of using ObjectOutputStream.readObject(). The reason is just efficiency: the resulting file is much smaller and it is much faster to write and read (eg. 23 MB in 0.6 seconds vs. 29 MB in 9.9 seconds).

This is what I did to serialize:

As you can see, I get the byte array for each key String, serialize its length and then the array itself. This is what I did to deserialize:

The problem is that at some point the key is not serialized correctly. I've been debugging to the point where I could see that ois.read(bytes) read 8 bytes instead of 16 as it was supposed to, so the key String was not properly formed and the double value was read using the last 8 bytes from the key that were not read yet. In the end, Exceptions everywhere.

Using the sample data below, the output will be like this at some point:

The problem can be seen in the serialized file (it should read 2010-00-008.html):

enter image description here

two bytes are added in between the String key. See MxyL's answer for further info about this. So it all boils down to: why are those two bytes added, and why readFully works ok?

Why isn't the String properly (de)serialized? Might it be some kind of padding to a fixed block size or something like that? Is there a better way to manually serialize a String when looking for efficiency? I was expecting some kind of writeString and readString, but seems there is no such thing in Java's ObjectStream.

I've been trying using buffered streams just in case there is something wrong there, explicitly saying how many bytes to write and to read, using different encodings, but no luck.

This is some sample data to reproduce the problem:

0 投票
1 回答
49 浏览

c# - 多个进程尝试同时写入,序列化时间过长

我们在通过多个进程序列化文件时面临性能问题。

这是问题所在:我们正在创建多个进程(在分布式计算环境中)来进行计算,然后将每个进程的输出写在一个文件中。主进程使用这些文件,将其合并到内存中并进行进一步的计算。

我们的服务器数量有限。发生的情况是可以在同一台服务器上创建 2-3 个进程。发生这种情况时(在同一台服务器上创建 2-3 个进程),我们会遇到这些进程尝试同时在磁盘上写入\序列化计算文件(文件大小约为 80-90 MB)的情况。发生这种情况时,序列化文件大约需要 3m。在正常情况下,80-90 MB 只需要 30 秒。

我们在性能监视器(和我们的日志计时)中监控了这种情况,并且可以看到由于 2-3 个进程试图同时写入,它所花费的时间大约是正常计时的 6 倍。

任何改善时间(3分钟场景)的建议都值得赞赏。

我们使用 .Net 框架,代码是用 c# 编写的。

0 投票
1 回答
605 浏览

wcf - WCF 不处理二进制格式的 MSMQ 消息

我有一个检索 MSMQ 消息的 WCF Windows 服务。SubmitPurchaseOrderInMessage 似乎没有被调用,我也没有看到队列中的任何消息。代码如下所示。

WCF 类:

接口契约:

数组参数可以是客户端可以传递的任何动态可序列化类型。我认为问题出在这个参数上。如果我删除此参数和可序列化属性以及客户端中的 binding.SerializationFormat,那么一切都可以正常工作。

可序列化类:

客户 :

0 投票
2 回答
71 浏览

c# - 二进制文件生成性能

我在一个文件中有大约 30 000 个要二进制序列化的对象,我正在使用一个简单的 foreach 循环这个基本代码来做到这一点:

我可以使用多线程或其他方式加速进程吗?(内存流等)

0 投票
1 回答
1300 浏览

c++ - 使用 Boost 和 uint8_t 进行二进制序列化

在处理二进制数据时,我倾向于使用uint8_t. 我想这对我来说似乎是一个字节的类型。但是,我无法弄清楚如何让二进制序列化在 boost 中使用该类型。我是在问不可能的事情还是只是错过了一些简单的事情?

此示例程序无法在 VS2013 上编译,并抱怨不会将流转换为std::ostreamor std::istream

该程序可以正常工作,char而不是uint8_t,但这让我很烦恼。:)

0 投票
1 回答
359 浏览

c# - 在将参数传递给基类时如何反序列化派生类

我有一个派生类,它继承自一个绘制圆圈的低音类

我正在尝试使用二进制序列化来序列化此类。

我像这样序列化它:

序列化似乎没问题,但是当我像下面这样对它进行反序列化时;我将数据字段(大括号、半径和中心点)恢复正常;但我没有让圈子回来!我怀疑这是因为我没有反序列化基类。但是我尝试了,我不知道该怎么做!

我的问题是如何反序列化它。我正在寻找这样的东西,这可能吗?

0 投票
2 回答
498 浏览

scala - Scala 位域序列化

我是 Scala 的新手,我对位操作功能感到困惑。我希望有人能指出我正确的方向吗?

我有一个用以下位字段定义的字节数组:

我想将它来回序列化为一个结构,例如:

在这种情况下,您如何以最佳方式处理比特?我见过的大多数示例都处理更高级别的序列化,例如 JSON。在这种情况下,我正在尝试序列化和反序列化 TCP 二进制数据。

0 投票
3 回答
265 浏览

c# - 为什么他反序列化两次

这不是我的代码,我只需要理解它。无法联系到原始程序员。dobj 只是一个对象类型。我的主要问题是:为什么当 dobj 从未更改时他再次反序列化? 请忽略他所有的 goto,因为现在它们在这个程序中无处不在。

编辑我添加了其余的方法