-- >>> parse bencDict "Bdict" (BC.pack "d9:publisher3:bob17:publisher-webpage15:www.example.com18:publisher.location4:homee")
-- Right (fromList [("publisher","bob"),("publisher-webpage","www.example.com"),("publisher.location","home")])
bencDict :: ParsecBS.Parser (M.Map BVal BVal)
-- >>> parse bencDict "Bdict" (BC.pack "d9:publisher3:bob17:publisher-webpage15:www.example.com18:publisher.location4:homee")
-- Right (fromList [("publisher","bob"),("publisher-webpage","www.example.com"),("publisher.location","home")])
bencDict :: ParsecBS.Parser (M.Map BVal BVal)
in show (length s) ++ ":" ++ s
encode (Bint i) = "i" ++ show i ++ "e"
encode (Blist xs) = "l" ++ encodeList xs ++ "e"
in show (length s) ++ ":" ++ s
encode (Bint i) = "i" ++ show i ++ "e"
encode (Blist xs) = "l" ++ encodeList xs ++ "e"
encode (Bdict d) = "d" ++ encodeDict d ++ "e"
where encodeDict m = concat [encode k ++ encode (m M.! k) | k <- M.keys m]
encode (Bdict d) = "d" ++ encodeDict d ++ "e"
where encodeDict m = concat [encode k ++ encode (m M.! k) | k <- M.keys m]