[BitTorrent] Bencoding: How to sort keys for dictionaries ?

skybuckflying skybuck2000 at hotmail.com
Sat Nov 20 16:29:57 EST 2004



Hi,

The wiki page reads:

"
dictionaries

Dictionaries are encoded as follows: d<bencoded string><bencoded 
element>e 
The initial d and trailing e are the beginning and ending delimiters.

Note that the keys must be bencoded strings. The values may be any 
bencoded type, including integers, strings, lists, and other 
dictionaries. Keys must be strings and appear in sorted order (sorted 
as raw strings, not alphanumerics).

Example: d3:cow3:moo4:spam4:eggse represents the dictionary { "cow" 
=> "moo", "spam" => "eggs" } 
Example: d4:spaml1:a1:bee represents the dictionary { "spam" => 
["a", "b"] }
"

I don't understand this line:

"Keys must be strings and appear in sorted order (sorted as raw 
strings, not alphanumerics)."

How do I need to sort ?

Do I have to convert the chars to "byte values" and then sort them on 
their byte values ?

Also why do keys have to be strings.. is that really necessary.. 
(since my implementation can easily handle other stuff as well... 
though I haven't tried yet for searching for keys :) I might 
need/make an Equals or so... function for that :) )

I can see two reasons why the key has to be a string:

1. The python language is limited to strings for dictionary which 
might be part of the language ?

2. It's designed that way ? :)

Also why is the sort needed ?

I think it's to make sure that all torents more or less look the 
same... like some fields are before others etc... ? ;) or it might be 
a python thing again :) ?

Bye,
  Skybuck.





------------------------ Yahoo! Groups Sponsor --------------------~--> 
$9.95 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/dkFolB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/BitTorrent/

<*> To unsubscribe from this group, send an email to:
    BitTorrent-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 





More information about the BitTorrent mailing list