on master help sign in
switch to using Network.ByteOrder module
commit30122a0233e662dabeb64f1d29c637100bc6f2e1 authorAgentM <agentm@themactionfaction.com> dateSun 11 Oct 2020, 15:04 (6 years ago) parentc95cb38
2 files changed+4−17
curryer.cabal+1 src/Network/RPC/Curryer/Server.hs+3−17
curryer.cabal+1
@@ -32,6 +32,7 @@ Library
3232 , stm-containers
3333 , hashable
3434 , time
35+ , network-byte-order
3536 Hs-Source-Dirs: ./src
3637 Default-Language: Haskell2010
3738 ghc-options: -Wall -fwarn-unused-binds -fwarn-unused-imports
src/Network/RPC/Curryer/Server.hs+3−17
@@ -21,8 +21,6 @@ import qualified Data.ByteString.Lazy as BSL
2121import qualified Data.ByteString.FastBuilder as BB
2222import Streamly.Data.Fold as FL
2323import qualified Streamly.Internal.Data.Stream.IsStream as S
24−import Data.Foldable
25−import Data.Bits
2624import qualified Data.Binary as B
2725import qualified Data.UUID as UUIDBase
2826import qualified Data.UUID.V4 as UUIDBase
@@ -31,6 +29,7 @@ import qualified Network.RPC.Curryer.StreamlyAdditions as SA
3129import Control.Monad
3230import Data.Hashable
3331import System.Timeout
32+import qualified Network.ByteOrder as BO
3433
3534-- for toArrayS conversion
3635import qualified Data.ByteString.Internal as BSI
@@ -108,7 +107,7 @@ messageBoundaryP = do
108107 let x = FL.toList
109108 w4x8 <- PD.take 4 x
110109 traceShowM ("w4x8"::String, w4x8)
111− let c = fromIntegral (fromOctets w4x8)
110+ let c = fromIntegral (BO.word32 (BS.pack w4x8))
112111 traceShowM ("c"::String, c)
113112 vals <- PD.take c x
114113 let bytes = BS.pack vals
@@ -189,19 +188,6 @@ drainSocketMessages sock msgHandler = do
189188 msgHandler val --add response function
190189 S.drain $ serially $ S.parseManyD messageBoundaryP sockStream & S.mapM handler
191190
192−fromOctets :: [Word8] -> Word32
193−fromOctets = foldl' accum 0
194− where
195− accum a o = (a `shiftL` 8) .|. fromIntegral o
196−
197−octets :: Word32 -> [Word8]
198−octets w =
199− [ fromIntegral (w `shiftR` 24)
200− , fromIntegral (w `shiftR` 16)
201− , fromIntegral (w `shiftR` 8)
202− , fromIntegral w
203− ]
204−
205191--send length-tagged bytestring, perhaps should be in network byte order?
206192sendMessage :: Serialise a => Message a -> Socket -> IO ()
207193sendMessage msg socket' = do
@@ -210,7 +196,7 @@ sendMessage msg socket' = do
210196 msgbytes = serialise msg
211197 fullbytes = lenbytes <> msgbytes
212198 len = BS.length msgbytes
213− lenbytes = BS.pack (octets (fromIntegral len))
199+ lenbytes = BO.bytestring32 (fromIntegral len)
214200 --when (dbgByteString /= msgbytes) (error "mismatch!")
215201
216202 byteCount <- Socket.send socket' fullbytes