packages feed

BufferedSocket 0.1.0.0 → 0.1.1.0

raw patch · 4 files changed

+33/−15 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Core: readToByteMax :: BufferedSocket -> Word8 -> MaxLength -> IO (Maybe ByteString)
+ Core: readToByteStringMax :: BufferedSocket -> ByteString -> MaxLength -> IO (Maybe ByteString)

Files

BufferedSocket.cabal view
@@ -10,7 +10,7 @@ -- PVP summary:      +-+------- breaking API changes --                   | | +----- non-breaking API additions --                   | | | +--- code changes with no API change-version:             0.1.0.0+version:             0.1.1.0  -- A short (one-line) description of the package. synopsis:            A socker wrapper that makes the IO of sockets much cleaner
Core.hs view
@@ -35,7 +35,9 @@ , readLazy , readByte , readToByte+, readToByteMax , sendByteString+, readToByteStringMax , flush , BufferedSocket  , makeBufferedSocket
Reader.hs view
@@ -71,12 +71,16 @@ import Data.Bits   listToValue :: (Bits a, Num a) => [a] -> a -listToValue = foldl xor 0+listToValue = foldl xor zeroBits -convertToShiftedList:: (Bits a, Num a, Integral a, Bits b, Num b) => [a] -> Int -> [b]-convertToShiftedList byteList byteSize = -    [shift (fromIntegral x) (byteSize * 8 * n) | x <- byteList, n <- [0..(length byteList)]] +convertToShiftedList:: (Bits b, Num b) => [Word8] -> Int -> [b]+convertToShiftedList [] _ = []+convertToShiftedList (x:xs) byteIndex = +    let n = byteIndex - 1 -- Since we want the size of the result data the actual index -||- is (-1)+    in (shift (fromIntegral x) (8 * n): convertToShiftedList xs n) ++ readText:: BS.BufferedSocket -> BS.ReadSize -> IO T.Text readText bSocket readSize = do     byteData <- BS.readRaw bSocket readSize@@ -97,29 +101,39 @@  readWord16:: BS.BufferedSocket -> IO Word16 readWord16 bSocket = do -    bytes <- B.unpack <$> BS.readRaw bSocket 2-    let result =  convertToShiftedList bytes 2:: [Word16]+    bytes <- B.unpack <$> BS.readRaw bSocket byteSize+    let result =  convertToShiftedList bytes byteSize:: [Word16]     return $ listToValue result +    where +        byteSize = 2+ readWord32:: BS.BufferedSocket -> IO Word32 readWord32 bSocket = do -    bytes <- B.unpack <$> BS.readRaw bSocket 4-    let result =  convertToShiftedList bytes 4:: [Word32]+    bytes <- B.unpack <$> BS.readRaw bSocket byteSize+    let result =  convertToShiftedList bytes byteSize:: [Word32]     return $ listToValue result +    where +        byteSize = 4+ readWord64:: BS.BufferedSocket -> IO Word64 readWord64 bSocket = do -    bytes <- B.unpack <$> BS.readRaw bSocket 8-    let result =  convertToShiftedList bytes 8:: [Word64]+    bytes <- B.unpack <$> BS.readRaw bSocket byteSize+    let result =  convertToShiftedList bytes byteSize:: [Word64]     return $ listToValue result +    where +        byteSize = 8 readInt8:: BS.BufferedSocket -> IO Int8 readInt8 =  (fromIntegral <$>) . readWord8  readInt16:: BS.BufferedSocket -> IO Int16 readInt16 =  (fromIntegral <$>) . readWord16+ readInt32:: BS.BufferedSocket -> IO Int32 readInt32 =  (fromIntegral <$>) . readWord32+ readInt64:: BS.BufferedSocket -> IO Int64 readInt64 =  (fromIntegral <$>) . readWord64 
Writer.hs view
@@ -65,7 +65,7 @@ bitsToByteStringReal:: (Bits a, Integral a) => a -> Int -> [Word8] bitsToByteStringReal a 0 = [fromIntegral a] bitsToByteStringReal inData size = -    let thisByte = shift inData (- (size * 8 - 1))+    let thisByte = shift inData (- (size * 8 ))     in (fromIntegral thisByte : bitsToByteStringReal inData (size - 1))  bitsToByteString:: (Bits a, Integral a, Storable a) => a -> B.ByteString@@ -79,15 +79,17 @@ sendByte = sendWord8  sendWord16:: BS.BufferedSocket -> Word16 -> IO ()-sendWord16 bSocket word16 = BS.sendByteString bSocket $ bitsToByteString word16+sendWord16 bSocket word16 = let sendData = bitsToByteString word16+                            in do +                                putStrLn $ "sent bytes: " ++ (show $ B.unpack sendData)+                                BS.sendByteString bSocket $ sendData + sendWord32:: BS.BufferedSocket -> Word32 -> IO () sendWord32 bSocket word32 =  BS.sendByteString bSocket $ bitsToByteString word32  sendWord64:: BS.BufferedSocket -> Word64 -> IO () sendWord64 bSocket word64 =  BS.sendByteString bSocket $ bitsToByteString word64-- sendInt8:: BS.BufferedSocket -> Int8 -> IO () sendInt8 bSocket int8 =  sendWord8 bSocket $ fromIntegral int8 sendInt16:: BS.BufferedSocket -> Int16 -> IO ()