Permalink
Browse files

Benc: fixes

  • Loading branch information...
astro committed Jul 9, 2012
1 parent a56ab0f commit 4e03a730bb9940ef3c9a9b90f57e31f3d39735cc
Showing with 12 additions and 8 deletions.
  1. +12 −8 Benc.hs
View
20 Benc.hs
@@ -18,27 +18,31 @@ data BValue = BInt Integer
instance IsString BValue where
fromString = BString . LBC.pack
+-- FIXME: Builder inserts newlines between each chunk?
toBuilder :: BValue -> Builder
toBuilder (BString s) =
- insertLazyByteString s
+ mconcat [ fromByteString $ BC.pack $ show $ LBC.length s
+ , fromByteString ":"
+ , fromLazyByteString s
+ ]
toBuilder (BInt i) =
- mconcat [ insertByteString "i"
- , insertByteString $ BC.pack $ show i
- , insertByteString "e"
+ mconcat [ fromByteString "i"
+ , fromByteString $ BC.pack $ show i
+ , fromByteString "e"
]
toBuilder (BList xs) =
- mconcat [ insertByteString "l"
+ mconcat [ fromByteString "l"
, mconcat $ map toBuilder xs
- , insertByteString "e"
+ , fromByteString "e"
]
toBuilder (BDict xs) =
let xs' = sort xs
- in mconcat [ insertByteString "d"
+ in mconcat [ fromByteString "d"
, mconcat $
map (\(k, v) ->
toBuilder k `mappend`
toBuilder v
) xs'
- , insertByteString "e"
+ , fromByteString "e"
]

0 comments on commit 4e03a73

Please sign in to comment.