What type of encoding is this? I am told it's Bencode, but it doesn't look standard [closed]

杀马特。学长 韩版系。学妹 提交于 2019-12-23 20:14:40

问题


I'm working on a project in which they have stored the following type of encoded data in a BLOB type column of a mysql database. I've asked around and have been told this is Bencode, however, from what I'm seeing online it doesn't appear to be standard Bencode.

Wiki for Bencode

http://en.wikipedia.org/wiki/Bencode

Example of encoded data

a:11:{i:0;a:3:{s:11:"question_id";s:2:"46";s:6:"answer";s:1:"2";s:7:"correct";b:1;}i:1;a:3:{s:11:"question_id";s:2:"45";s:6:"answer";s:1:"2";s:7:"correct";b:0;}i:2;a:3:{s:11:"question_id";s:2:"44";s:6:"answer";s:1:"2";s:7:"correct";b:0;}i:3;a:3:{s:11:"question_id";s:2:"43";s:6:"answer";s:1:"1";s:7:"correct";b:0;}i:4;a:3:{s:11:"question_id";s:2:"42";s:6:"answer";s:1:"3";s:7:"correct";b:0;}i:5;a:3:{s:11:"question_id";s:2:"41";s:6:"answer";s:1:"2";s:7:"correct";b:0;}i:6;a:3:{s:11:"question_id";s:2:"40";s:6:"answer";s:1:"0";s:7:"correct";b:1;}i:7;a:3:{s:11:"question_id";s:2:"39";s:6:"answer";s:1:"0";s:7:"correct";b:0;}i:8;a:3:{s:11:"question_id";s:2:"38";s:6:"answer";s:1:"1";s:7:"correct";b:1;}i:9;a:3:{s:11:"question_id";s:2:"37";s:6:"answer";s:1:"3";s:7:"correct";b:0;}i:10;a:3:{s:11:"question_id";s:2:"36";s:6:"answer";s:1:"2";s:7:"correct";b:1;}}

What I've noticed so far

I've noticed that the encoding describes different types of data using letters and integers similar to Bencode.

Example: s:11:"question_id";

I'm assuming s stands for 'string', and that 11 is defining the length of the string question_id. Also, it would appear that the beginning of the data (a:11:) describes an array with a length of 11. While this is similar to standard Bencode, it doesn't seem to use the standard syntax that Bencode uses.

Does anyone have any ideas what type of encoding this is? Is this a non-standard Bencode format, or something entirely different? I'm looking for a parser in PHP or Python, and having a name for the encoding would definitely help in my search.


回答1:


It's the PHP serialization format, unserializable using unserialize.
See http://codepad.org/l7Z9cITo.



来源:https://stackoverflow.com/questions/12320327/what-type-of-encoding-is-this-i-am-told-its-bencode-but-it-doesnt-look-stand

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!