将plist转换为二进制plist [英] Converting plist to binary plist

查看:444
本文介绍了将plist转换为二进制plist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Apple强烈建议在将大型基于XML的数据集读入iPhone应用程序时使用二进制plist格式。在他们的推理中,XML解析对iPhone非常重要。但是,这要求首先转换驻留在远程Web服务器上的文件。

Apple strongly recommends using the binary plist format when reading large XML-based data sets into iPhone apps. Among their reasoning is the fact that XML parsing is very taxing on the iPhone. However, this requires that files residing on the remote web server be converted first.

对于频繁更改的内容,手动执行此操作是不可接受的。如果可能的话,我想避免让基于Web的app调用命令行来执行转换(即plutil)。

For frequently-changing content, it is not acceptable to do this manually. If at all possible, I'd like to avoid having a web based app call the command line to perform the conversion (i.e., plutil).

是否有公开的算法来执行此转换?

Are there publicly available algorithms to perform this conversion?

推荐答案

是。所有plist代码都是CoreFoundation的一部分,它是开源的。 CoreFoundation可以直接在Linux和Windows上构建和运行,因此您可以使用在Mac OS X上使用的普通API编写CF工具,但可以在其他平台上构建和运行它。

Yes. All the plist code is part of CoreFoundation, which is opensource. CoreFoundation can be directly built and run on Linux and Windows, so you can write a CF tool using the normal APIs you would use on Mac OS X, but build and run it on other platforms.

您想要查看的特定API是 CFPropertyListWriteToStream()。 CoreFoundation的代码可从 Apple 获取( tarball ),以及其他地方。

The particular API you want to be looking at is CFPropertyListWriteToStream(). The code for CoreFoundation is available from Apple (tarball), among other places.

最后,根据您更新文件的频率,服务器上需要多少处理器,以及您的数据重复次数,可能会有一个显着的增强离开你可以做到的。默认情况下,二进制plist中的某些元素是唯一的(例如字符串)。其他元素不是(例如数组和字典)。二进制plist格式允许它们是唯一的,问题是实际遍历并且独特的数组和字典是昂贵的。如果您的内容中有许多相同的数组或词组,您可以通过单独使用它们来显着减小尺寸。你可以通过在 CFBinaryPlist中删除_flattenPlist()来启用它。 c

Finally depending on how often you update the file, how much processor you have to spare on the server, and how much repetition there is your data there may be one significant enhancement left that you can do. By default certain elements in binary plists are uniqued (such as strings). Other elements are not (such as arrays and dictionarts). The binary plist format allows them to be uniqued, the issue is that it is expensive to actually walk through and unique arrays and dictionaries. If you have a lot of identical arrays or dicts in your content you may see a significant size reduction by uniquing them. You can enable that by hacking up _flattenPlist() in CFBinaryPlist.c.

如果你这样做,请确保彻底测试,不要对你无法通过网络更新的任何文件进行测试,以防万一未来的版本会使任何优化都能打破这种局面。此外,请确保您准备好立即关闭它。

If you do that make sure to test it very thoroughly, and do not do on any files you cannot update over the network, just in case a future release makes any optimizations that break that. Also, make sure you are ready to turn it off at a moments notice.

这篇关于将plist转换为二进制plist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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