THRIFT-906. hs: Improve type mappings
This patch fixes the type mappings to be more sane. It *will* break existing code, but the breakages should be well worth it.
Patch: Christian Lavoie
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@999700 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/hs/src/Thrift/Protocol.hs b/lib/hs/src/Thrift/Protocol.hs
index c7c2d69..b34e806 100644
--- a/lib/hs/src/Thrift/Protocol.hs
+++ b/lib/hs/src/Thrift/Protocol.hs
@@ -29,9 +29,10 @@
import Control.Monad ( replicateM_, unless )
import Control.Exception
-
-import Data.Typeable ( Typeable )
import Data.Int
+import Data.Typeable ( Typeable )
+import Data.Word
+import Data.ByteString.Lazy
import Thrift.Transport
@@ -102,53 +103,53 @@
class Protocol a where
getTransport :: Transport t => a t -> t
- writeMessageBegin :: Transport t => a t -> (String, MessageType, Int) -> IO ()
+ writeMessageBegin :: Transport t => a t -> (String, MessageType, Int32) -> IO ()
writeMessageEnd :: Transport t => a t -> IO ()
writeStructBegin :: Transport t => a t -> String -> IO ()
writeStructEnd :: Transport t => a t -> IO ()
- writeFieldBegin :: Transport t => a t -> (String, ThriftType, Int) -> IO ()
+ writeFieldBegin :: Transport t => a t -> (String, ThriftType, Int16) -> IO ()
writeFieldEnd :: Transport t => a t -> IO ()
writeFieldStop :: Transport t => a t -> IO ()
- writeMapBegin :: Transport t => a t -> (ThriftType, ThriftType, Int) -> IO ()
+ writeMapBegin :: Transport t => a t -> (ThriftType, ThriftType, Int32) -> IO ()
writeMapEnd :: Transport t => a t -> IO ()
- writeListBegin :: Transport t => a t -> (ThriftType, Int) -> IO ()
+ writeListBegin :: Transport t => a t -> (ThriftType, Int32) -> IO ()
writeListEnd :: Transport t => a t -> IO ()
- writeSetBegin :: Transport t => a t -> (ThriftType, Int) -> IO ()
+ writeSetBegin :: Transport t => a t -> (ThriftType, Int32) -> IO ()
writeSetEnd :: Transport t => a t -> IO ()
writeBool :: Transport t => a t -> Bool -> IO ()
- writeByte :: Transport t => a t -> Int -> IO ()
- writeI16 :: Transport t => a t -> Int -> IO ()
- writeI32 :: Transport t => a t -> Int -> IO ()
+ writeByte :: Transport t => a t -> Word8 -> IO ()
+ writeI16 :: Transport t => a t -> Int16 -> IO ()
+ writeI32 :: Transport t => a t -> Int32 -> IO ()
writeI64 :: Transport t => a t -> Int64 -> IO ()
writeDouble :: Transport t => a t -> Double -> IO ()
writeString :: Transport t => a t -> String -> IO ()
- writeBinary :: Transport t => a t -> String -> IO ()
+ writeBinary :: Transport t => a t -> ByteString -> IO ()
- readMessageBegin :: Transport t => a t -> IO (String, MessageType, Int)
+ readMessageBegin :: Transport t => a t -> IO (String, MessageType, Int32)
readMessageEnd :: Transport t => a t -> IO ()
readStructBegin :: Transport t => a t -> IO String
readStructEnd :: Transport t => a t -> IO ()
- readFieldBegin :: Transport t => a t -> IO (String, ThriftType, Int)
+ readFieldBegin :: Transport t => a t -> IO (String, ThriftType, Int16)
readFieldEnd :: Transport t => a t -> IO ()
- readMapBegin :: Transport t => a t -> IO (ThriftType, ThriftType, Int)
+ readMapBegin :: Transport t => a t -> IO (ThriftType, ThriftType, Int32)
readMapEnd :: Transport t => a t -> IO ()
- readListBegin :: Transport t => a t -> IO (ThriftType, Int)
+ readListBegin :: Transport t => a t -> IO (ThriftType, Int32)
readListEnd :: Transport t => a t -> IO ()
- readSetBegin :: Transport t => a t -> IO (ThriftType, Int)
+ readSetBegin :: Transport t => a t -> IO (ThriftType, Int32)
readSetEnd :: Transport t => a t -> IO ()
readBool :: Transport t => a t -> IO Bool
- readByte :: Transport t => a t -> IO Int
- readI16 :: Transport t => a t -> IO Int
- readI32 :: Transport t => a t -> IO Int
+ readByte :: Transport t => a t -> IO Word8
+ readI16 :: Transport t => a t -> IO Int16
+ readI32 :: Transport t => a t -> IO Int32
readI64 :: Transport t => a t -> IO Int64
readDouble :: Transport t => a t -> IO Double
readString :: Transport t => a t -> IO String
- readBinary :: Transport t => a t -> IO String
+ readBinary :: Transport t => a t -> IO ByteString
skip :: (Protocol p, Transport t) => p t -> ThriftType -> IO ()
@@ -165,13 +166,13 @@
skipFields p
readStructEnd p
skip p T_MAP = do (k, v, s) <- readMapBegin p
- replicateM_ s (skip p k >> skip p v)
+ replicateM_ (fromIntegral s) (skip p k >> skip p v)
readMapEnd p
skip p T_SET = do (t, n) <- readSetBegin p
- replicateM_ n (skip p t)
+ replicateM_ (fromIntegral n) (skip p t)
readSetEnd p
skip p T_LIST = do (t, n) <- readListBegin p
- replicateM_ n (skip p t)
+ replicateM_ (fromIntegral n) (skip p t)
readListEnd p