{-# LANGUAGE RankNTypes #-}
module Pinch.Protocol
( Protocol(..)
, deserializeValue
, deserializeMessage
) where
import Data.ByteString (ByteString)
import Data.Serialize.Get (Get, runGet)
import Pinch.Internal.Builder (Builder)
import Pinch.Internal.Message (Message)
import Pinch.Internal.TType (IsTType)
import Pinch.Internal.Value (Value)
data Protocol = Protocol
{ Protocol -> forall a. IsTType a => Value a -> Builder
serializeValue :: forall a. IsTType a => Value a -> Builder
, Protocol -> Message -> Builder
serializeMessage :: Message -> Builder
, Protocol -> forall a. IsTType a => Get (Value a)
deserializeValue'
:: forall a. IsTType a => Get (Value a)
, Protocol -> Get Message
deserializeMessage' :: Get Message
}
deserializeValue :: forall a. IsTType a
=> Protocol -> ByteString -> Either String (Value a)
deserializeValue :: Protocol -> ByteString -> Either String (Value a)
deserializeValue Protocol
proto = Get (Value a) -> ByteString -> Either String (Value a)
forall a. Get a -> ByteString -> Either String a
runGet (Get (Value a) -> ByteString -> Either String (Value a))
-> Get (Value a) -> ByteString -> Either String (Value a)
forall a b. (a -> b) -> a -> b
$ Protocol -> forall a. IsTType a => Get (Value a)
deserializeValue' Protocol
proto
deserializeMessage :: Protocol -> ByteString -> Either String Message
deserializeMessage :: Protocol -> ByteString -> Either String Message
deserializeMessage Protocol
proto = Get Message -> ByteString -> Either String Message
forall a. Get a -> ByteString -> Either String a
runGet (Get Message -> ByteString -> Either String Message)
-> Get Message -> ByteString -> Either String Message
forall a b. (a -> b) -> a -> b
$ Protocol -> Get Message
deserializeMessage' Protocol
proto