TMX 地图文件到底是如何进行 base_64 编码的?
我正在为 iOS 编写一个使用 .tmx 地图文件的游戏。我在应用程序“Tiled”中创建地图,然后在它们到达 iOS 之前的某个时刻,我用 Perl 解析它们。
当我将文件另存为直接 XML 时,perl 解析它们就很容易了。然而,cocos2d 坚持要求文件采用 Base64 编码。 “平铺”地图编辑器使用这种编码方案保存文件没有问题,iOS 可以很好地读取它们,但它给我的 Perl 代码带来了问题。
由于某种原因,perl 中的标准 MIME::Base64decode_base64() 方法在这里并没有起到作用——当我解码字符串时,我得到一两个二进制字符——菱形框中的问号等。
TMX 文件格式的模糊文档使得我们不清楚在 Base64 编码之前或之后是否存在其他可能导致此问题的编码。我查看了编码器的 cpp 源代码,看到了很多对 Latin1 的引用,但我无法详细解释发生了什么。
我注意到,当我尝试使用 MIME::Base64 进行自己的测试、编码然后解码测试字符串时,编码后的文本看起来与我从 TMX 文件中看到的文本显着不同 - 例如,我的 Base64 编码的文本短字符串的文本看起来像这样:
aGVyZSBpcyBhIHNlbnRlbmNl
但是来自 TMX 文件的 base64 编码文本看起来像这样: 关于
9QAAAAABAAANAQAAGAEAAA==
我在尝试解码看起来像这样的字符串时可能尝试的其他方法,有什么建议吗?
I am writing a game for iOS that uses .tmx map files. I am creating the maps in the application 'Tiled' and then at some point before they get to iOS, I'm parsing them with Perl.
When I save the files as straight XML, it's a cinch for perl to parse them. However, cocos2d insists that the files be base64-encoded. The 'Tiled' map editor has no problem saving files with this encoding scheme, and iOS reads them just fine, but it's presenting problems for my perl code.
For some reason, the standard MIME::Base64 decode_base64() method in perl is not cutting the mustard here- when I decode the strings, I get one or two binary characters-- question marks in diamond boxes and such.
And the vague documentation for the TMX file format makes it unclear if there is some other encoding going on before or after the base64 encoding which might be causing this problems. I looked at the cpp source for the encoder, and I saw lots of references to Latin1, but I couldn't decipher what's going on in detail.
I noticed that when I tried doing my own tests with MIME::Base64, encoding and then decoding a test string, the encoded text looks dramatically different than that which I see coming out of the TMX files-- for instance, my base64-encoded text for a short string looks like this:
aGVyZSBpcyBhIHNlbnRlbmNl
But the base64-encoded text coming from the TMX files looks like this:
9QAAAAABAAANAQAAGAEAAA==
Any suggestions on what else I might try in attempts to decode a string that looks like that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为此页面可能就是您正在寻找的内容。它建议您首先 decode_base64,然后(如果
compression=" gzip"
属性存在)使用 gunzip 解压,最后使用unpack( 'V*', $data)
提取 4 字节小端整数列表。I think this page might be what you're looking for. It suggests that first you decode_base64, then (if the
compression="gzip"
attribute is present) use gunzip to uncompress it, and finally useunpack('V*', $data)
to extract the list of 4-byte little-endian integers.