[remove more instances of building things with Word8 in favor of ByteStrings
John Meacham <john@repetae.net>**20080717042105] {
hunk ./Gale/Gale.hs 269
-    retry 3.0 "error sending puff" $ withMVar (gHandle gc) $ \h -> putRaw h d >> hFlush h
+    retry 3.0 "error sending puff" $ withMVar (gHandle gc) $ \h -> LBS.hPut h d >> hFlush h
hunk ./Gale/Gale.hs 275
-    retry 3.0 "error sending puff" $ withMVar (gHandle gc) $ \h -> putRaw h d >> hFlush h
+    retry 3.0 "error sending puff" $ withMVar (gHandle gc) $ \h -> LBS.hPut h d >> hFlush h
hunk ./Gale/Gale.hs 289
-createPuff :: GaleContext -> Bool -> Puff -> IO [Word8]
+
+tagWord :: Int -> Put -> Put
+tagWord i p = putWord32be (fromIntegral i) >> p
+
+class RawPut a where
+    rawPut :: a -> Put
+
+instance RawPut BS.ByteString where
+    rawPut = putByteString
+
+instance RawPut LBS.ByteString where
+    rawPut = putLazyByteString
+
+instance RawPut [Word8] where
+    rawPut = putByteString . BS.pack
+
+runPutBS = BS.concat . LBS.toChunks . runPut
+
+createPuff :: GaleContext -> Bool -> Puff -> IO LBS.ByteString
hunk ./Gale/Gale.hs 309
-    let cn = galeEncodeString (concatInter ":" (map catShowOld $ cats puff))
-    let ad = xdrWriteUInt (fromIntegral $ length cn) (cn ++ xdrWriteUInt 0 []) ++ createFragments (fragments puff)
-    let pd = xdrWriteUInt (if will then 1 else 0) (xdrWriteUInt (fromIntegral $ length ad) ad)
-    evaluate pd
+    let cn = runPut $ putGaleString (concatInter ":" (map catShowOld $ cats puff))
+    let ad = runPut $ tagWord (fromIntegral $ LBS.length cn) $ do putLazyByteString cn; tagWord 0 $ putFragments (fragments puff)
+    let pd = tagWord (if will then 1 else 0) (tagWord (fromIntegral $ LBS.length ad) (putLazyByteString ad))
+    evaluate $ runPut pd
hunk ./Gale/Gale.hs 320
-	    let fl = xdrWriteUInt 0 (createFragments (fragments p `mergeFrags` sfl))
-	    sig <- signAll pkey (BS.pack fl)
-	    let sd = signature_magic1 ++ xdrWriteUInt (fromIntegral $ BS.length sig) [] ++ BS.unpack sig ++ pubkey_magic3 ++ xdrWriteUInt (fromIntegral $ length kn) [] ++ galeEncodeString kn
-                fd = xdrWriteUInt (fromIntegral $ length sd) $ sd ++ fl
-                fragments = [(f_securitySignature,FragmentData (BS.pack fd))]
+	    let fl = runPutBS $ tagWord 0 (putFragments (fragments p `mergeFrags` sfl))
+	    sig <- signAll pkey fl
+	    let sd = runPutBS $ do
+                    putByteString bs_signature_magic1
+                    tagWord (BS.length sig) (putByteString sig)
+                    putByteString (BS.pack pubkey_magic3)
+                    tagWord (fromIntegral $ length kn) (putGaleString kn)
+                fd = tagWord (BS.length sd) (putByteString sd) >> putByteString fl
+                fragments = [(f_securitySignature,FragmentData (runPutBS fd))]
hunk ./Gale/Gale.hs 339
-        fl' = xdrWriteUInt 0 (createFragments fl)
+        fl' = putWord32be 0 >> (putFragments fl)
hunk ./Gale/Gale.hs 342
-    (d,ks,iv) <- encryptAll (snds ks') (BS.pack fl')
+    (d,ks,iv) <- encryptAll (snds ks') (BS.concat (LBS.toChunks $ runPut fl'))
hunk ./Gale/Gale.hs 345
-    return [(f_securityEncryption,FragmentData $ (bs_cipher_magic2 `BS.append` iv `BS.append` BS.pack (xdrWriteUInt n (foldr f (BS.unpack d) $ zip (fsts ks') (map BS.unpack ks)) )))]
+    return [(f_securityEncryption,FragmentData . BS.concat $ [bs_cipher_magic2,iv] ++ LBS.toChunks (runPut $ do putWord32be n;  mapM_ g (zip (fsts ks') ks) ; putByteString d))]
hunk ./Gale/Gale.hs 347
-     f (kn,kd) x = xdrWriteUInt (fromIntegral $ length kn) $ galeEncodeString kn ++ xdrWriteUInt (fromIntegral $ length kd) (kd ++ x)
+     --f (kn,kd) x = xdrWriteUInt (fromIntegral $ length kn) $ galeEncodeString kn ++ xdrWriteUInt (fromIntegral $ length kd) (kd ++ x)
+     g (kn,kd) = do
+        putWord32be (fromIntegral $ length kn)
+        putGaleString kn
+        putWord32be (fromIntegral $ BS.length kd)
+        putByteString kd
hunk ./Gale/Gale.hs 369
+putGaleString :: String -> Put
hunk ./Gale/Gale.hs 566
-        retry 3.0 "error sending puff" $ withMVar (gHandle gc) $ \h -> putRaw h d >> hFlush h
+        retry 3.0 "error sending puff" $ withMVar (gHandle gc) $ \h -> LBS.hPut h d >> hFlush h
hunk ./Gale/Gale.hs 658
-signature_magic1 :: [Word8]
+bs_signature_magic1 :: BS.ByteString
hunk ./Gale/Gale.hs 666
-signature_magic1 = stons "h\DC3\001\000"
+bs_signature_magic1 = BS.pack $ stons "h\DC3\001\000"
}
