THRIFT-3580 THeader for Haskell
Client: hs

This closes #820
This closes #1423
diff --git a/lib/hs/src/Thrift/Protocol.hs b/lib/hs/src/Thrift/Protocol.hs
index ed779a2..67a9175 100644
--- a/lib/hs/src/Thrift/Protocol.hs
+++ b/lib/hs/src/Thrift/Protocol.hs
@@ -22,12 +22,11 @@
 
 module Thrift.Protocol
     ( Protocol(..)
+    , StatelessProtocol(..)
     , ProtocolExn(..)
     , ProtocolExnType(..)
     , getTypeOf
     , runParser
-    , versionMask
-    , version1
     , bsToDouble
     , bsToDoubleLE
     ) where
@@ -35,7 +34,6 @@
 import Control.Exception
 import Data.Attoparsec.ByteString
 import Data.Bits
-import Data.ByteString.Lazy (ByteString, toStrict)
 import Data.ByteString.Unsafe
 import Data.Functor ((<$>))
 import Data.Int
@@ -44,37 +42,26 @@
 import Data.Typeable (Typeable)
 import Data.Word
 import Foreign.Ptr (castPtr)
-import Foreign.Storable (Storable, peek, poke)
+import Foreign.Storable (peek, poke)
 import System.IO.Unsafe
 import qualified Data.ByteString as BS
 import qualified Data.HashMap.Strict as Map
+import qualified Data.ByteString.Lazy as LBS
 
-import Thrift.Types
 import Thrift.Transport
-
-versionMask :: Int32
-versionMask = fromIntegral (0xffff0000 :: Word32)
-
-version1 :: Int32
-version1 = fromIntegral (0x80010000 :: Word32)
+import Thrift.Types
 
 class Protocol a where
-  getTransport :: Transport t => a t -> t
+  readByte :: a -> IO LBS.ByteString
+  readVal :: a -> ThriftType -> IO ThriftVal
+  readMessage :: a -> ((Text, MessageType, Int32) -> IO b) -> IO b
 
-  writeMessageBegin :: Transport t => a t -> (Text, MessageType, Int32) -> IO ()
-  writeMessageEnd :: Transport t => a t -> IO ()
-  writeMessageEnd _ = return ()
-  
-  readMessageBegin :: Transport t => a t -> IO (Text, MessageType, Int32)
-  readMessageEnd :: Transport t => a t -> IO ()
-  readMessageEnd _ = return ()
+  writeVal :: a -> ThriftVal -> IO ()
+  writeMessage :: a -> (Text, MessageType, Int32) -> IO () -> IO ()
 
-  serializeVal :: Transport t => a t -> ThriftVal -> ByteString
-  deserializeVal :: Transport t => a t -> ThriftType -> ByteString -> ThriftVal
-
-  writeVal :: Transport t => a t -> ThriftVal -> IO ()
-  writeVal p = tWrite (getTransport p) . serializeVal p
-  readVal :: Transport t => a t -> ThriftType -> IO ThriftVal
+class Protocol a => StatelessProtocol a where
+  serializeVal :: a -> ThriftVal -> LBS.ByteString
+  deserializeVal :: a -> ThriftType -> LBS.ByteString -> ThriftVal
 
 data ProtocolExnType
     = PE_UNKNOWN
@@ -105,10 +92,10 @@
   TBinary{} -> T_BINARY
   TDouble{} -> T_DOUBLE
 
-runParser :: (Protocol p, Transport t, Show a) => p t -> Parser a -> IO a
+runParser :: (Protocol p, Show a) => p -> Parser a -> IO a
 runParser prot p = refill >>= getResult . parse p
   where
-    refill = handle handleEOF $ toStrict <$> tReadAll (getTransport prot) 1
+    refill = handle handleEOF $ LBS.toStrict <$> readByte prot
     getResult (Done _ a) = return a
     getResult (Partial k) = refill >>= getResult . k
     getResult f = throw $ ProtocolExn PE_INVALID_DATA (show f)