BDecoder - ready

Hi everybody,

The BDecoder together with its documentation and test are ready. BDecoder decodes a bencoded QByteArray. For this purpose six more classes are added – BItem, BInt, BString, BList, BDictionary and BErrorItem. BItem is the basis of all other classes – it contains only the type of the item. BInt, BString, BList and BDictionary represent respectively the four bencoding types: integer, string, list and dictionary. BErrorItem represent an invalid data type. Such objects are returned in case of inconsistency in the raw data.

The BDecoder uses the BinaryReader from Peter in little endian mode reading from start. I extendet the BinaryReader by adding two functions lookAhead and canRead. The lookAhead function “looks ahead” in the raw data without reading it. It is needed in order to see what is to be read next (an int, a string, a list or a dictionary).In order to know how many bytes ahead one can look the user should call the canRead function.

I have added two tests. The first test is just reading at least from one of all the types. The second test reads a torrent file. The file is a real torrent which is changed a little by me so that I can avoid any advertisingJ. You can find the torrent in two versions. The first is the torrent like it normally is, whereas the second is a version with the same data but formatted more read friendly so that the test can be easily understood.

I’d like to get feedback from you.

Regards Slavcho

Attached Files:

Would you like to post a relpy?


This post starts a thread.
Follow-ups:
Re: BDecoder - ready
Hi Slavcho, Thanks for the patch! You’ve done some really neat job! I also find that lookAhead() is a pretty nice addition to BinaryReader! Here some comments and possible bugs though: BDecoder::readInt() (more...)