Skip to content

Commit

Permalink
use bytestring (not bytestring.char8)
Browse files Browse the repository at this point in the history
  • Loading branch information
toschoo committed Dec 1, 2016
1 parent d85e003 commit a6cb993
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
19 changes: 10 additions & 9 deletions src/stompl/Network/Mom/Stompl/Frame.hs
Expand Up @@ -73,9 +73,10 @@ where
-- Todo:
-- - conformance to protocol

import qualified Data.ByteString.Char8 as B
import qualified Data.ByteString as B
import qualified Data.ByteString.UTF8 as U
import Data.Char (toUpper, isDigit)
import Data.Word8 (Word8)
import Data.List (find, sortBy, foldl', nub)
import Data.List.Split (splitWhen)
import Data.Maybe (catMaybes, fromMaybe)
Expand Down Expand Up @@ -1026,9 +1027,9 @@ where
-- | append
(>|<) :: B.ByteString -> B.ByteString -> B.ByteString
-- | snoc
(|>) :: B.ByteString -> Char -> B.ByteString
(|>) :: B.ByteString -> Word8 -> B.ByteString
-- | cons
(<|) :: Char -> B.ByteString -> B.ByteString
(<|) :: Word8 -> B.ByteString -> B.ByteString
x >|< y = x `B.append` y
x <| y = x `B.cons` y
x |> y = x `B.snoc` y
Expand Down Expand Up @@ -1232,7 +1233,7 @@ where
Receipt -> "RECEIPT"
Error -> "ERROR"
HeartBeat -> ""
in B.pack (s ++ "\n")
in U.fromString s |> 0x0a

------------------------------------------------------------------------
-- Convert headers to ByteString
Expand All @@ -1241,7 +1242,7 @@ where
putHeaders f =
let hs = toHeaders f
s = B.concat $ map putHeader hs
in s |> '\n'
in s |> 0x0a

------------------------------------------------------------------------
-- Convert header to ByteString
Expand Down Expand Up @@ -1365,10 +1366,10 @@ where
putBody :: Frame -> Body
putBody f =
case f of
x@SndFrame {} -> frmBody x |> '\x00'
x@ErrFrame {} -> frmBody x |> '\x00'
x@MsgFrame {} -> frmBody x |> '\x00'
_ -> B.pack "\x00"
x@SndFrame {} -> frmBody x |> 0x00
x@ErrFrame {} -> frmBody x |> 0x00
x@MsgFrame {} -> frmBody x |> 0x00
_ -> B.singleton 0x00

------------------------------------------------------------------------
-- find a header and return it as string value (with default)
Expand Down
10 changes: 5 additions & 5 deletions src/stompl/Network/Mom/Stompl/Parser.hs
Expand Up @@ -213,7 +213,7 @@ where
then failBodyLen l (B.length b)
else do
_ <- word8 nul
body' l (b |> '\x00')
body' l (b |> 0x00)

------------------------------------------------------------------------
-- escape header key and value;
Expand All @@ -235,10 +235,10 @@ where
_ <- word8 esc
x <- anyWord8
c <- case x of
92 -> return '\\'
99 -> return ':'
110 -> return '\n'
114 -> return '\r'
92 -> return esc
99 -> return col
110 -> return eol
114 -> return cr
_ -> fail $ "Unknown escape sequence: " ++ show x
go (t >|< n |> c)

Expand Down
Binary file removed src/test/common/Test.hi
Binary file not shown.
Binary file removed src/test/common/Test.o
Binary file not shown.

0 comments on commit a6cb993

Please sign in to comment.