如何解包msgpack文件? [英] How to unpack a msgpack file?

查看:992
本文介绍了如何解包msgpack文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写msgpack恩codeD数据到一个文件中。在写作,我只是使用C API的fbuffer。如(i条纹的所有错误处理的例子):

I am writing msgpack-encoded data to a file. On writing, I am just using the fbuffer of the C API. As in (I striped all error handling for the example):

FILE *fp = fopen(filename, "ab");
msgpack_packer pk;
msgpack_packer_init(pk, fp, msgpack_fbuffer_write);
msgpack_pack_int(pk, 42);
// more data ...

我如何在读取此文件回来?我发现假设数据在内存中,但是,我的文件是否为5GB的所有例子中,它是不完全在内存完全持此一个好主意。此外,我不想读块我自己。毕竟,我不知道msgpack对象有多长,因此机会是我结束了我的缓冲半整数。

How do I read this file back in? All the example I found assume that the data is in memory, however, my files are up to 5GB, it is not exactly a good idea to hold this in memory completely. Also I do not want to read in chunks myself. After all, I do not know how long the msgpack objects are, so chances are I end up with half an integer in my buffer.

能否msgpack的解压不知何故从磁盘直接读取?或者是有一些标准的模式来做到这一点?

Can msgpack's unpack somehow read from disk directly? Or is there some standard pattern to do this?

推荐答案

您可能会考虑使用msgpack_unpacker为代替,这似乎是MessagePack实现了流式解串器的官方途径。看看msgpack-C /例子/ C / lib_buffer_unpack.c

You might consider using "msgpack_unpacker" for that instead, which seems to be the official way that MessagePack implements a 'streaming' deserializer. Have a look at msgpack-c/example/c/lib_buffer_unpack.c

问候,NiteHawk

Regards, NiteHawk

这篇关于如何解包msgpack文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆