{-# Language BangPatterns #-}
module Text.ProtocolBuffers.WireMessage
(
messageSize,messagePut,messageGet,messagePutM,messageGetM
, messageWithLengthSize,messageWithLengthPut,messageWithLengthGet,messageWithLengthPutM,messageWithLengthGetM
, messageAsFieldSize,messageAsFieldPutM,messageAsFieldGetM
, Put,PutM,Get,runPut,runPutM,runGet,runGetOnLazy,getFromBS
, Wire(..)
, size'WireTag,size'WireSize,toWireType,toWireTag,toPackedWireTag,mkWireTag
, prependMessageSize,putSize,putVarUInt,getVarInt,putLazyByteString,splitWireTag,fieldIdOf
, wireSizeReq,wireSizeOpt,wireSizeRep,wireSizePacked
, wirePutReq,wirePutOpt,wirePutRep,wirePutPacked
, wirePutReqWithSize,wirePutOptWithSize,wirePutRepWithSize,wirePutPackedWithSize
, sequencePutWithSize
, wireSizeErr,wirePutErr,wireGetErr
, getMessageWith,getBareMessageWith,wireGetEnum,wireGetPackedEnum
, unknownField,unknown,wireGetFromWire
, castWord64ToDouble,castWord32ToFloat,castDoubleToWord64,castFloatToWord32
, zzEncode64,zzEncode32,zzDecode64,zzDecode32
) where
import Control.Monad(when,foldM)
import Control.Monad.Error.Class(throwError)
import Control.Monad.ST
import Data.Array.ST(newArray,readArray)
import Data.Array.Unsafe(castSTUArray)
import Data.Bits (Bits(..))
import qualified Data.ByteString.Lazy as BS (length)
import qualified Data.Foldable as F(foldl', Foldable)
import Data.Maybe(fromMaybe)
import Data.Sequence ((|>))
import qualified Data.Sequence as Seq(length,empty)
import qualified Data.Set as Set(delete,null)
import Data.Typeable (Typeable,typeOf)
import Data.Binary.Put (Put,PutM,runPutM,runPut,putWord8,putWord32le,putWord64le,putLazyByteString)
import Text.ProtocolBuffers.Basic
import Text.ProtocolBuffers.Get as Get (Result(..),Get,runGet,runGetAll,bytesRead,isReallyEmpty,decode7unrolled
,spanOf,skip,lookAhead,highBitRun
,getWord32le,getWord64le,getLazyByteString)
import Text.ProtocolBuffers.Reflections(ReflectDescriptor(reflectDescriptorInfo,getMessageInfo)
,DescriptorInfo(..),GetMessageInfo(..))
trace :: a -> b -> b
trace :: a -> b -> b
trace _ = b -> b
forall a. a -> a
id
messageSize :: (ReflectDescriptor msg,Wire msg) => msg -> WireSize
messageSize :: msg -> WireSize
messageSize msg :: msg
msg = FieldType -> msg -> WireSize
forall b. Wire b => FieldType -> b -> WireSize
wireSize 10 msg
msg
messageWithLengthSize :: (ReflectDescriptor msg,Wire msg) => msg -> WireSize
messageWithLengthSize :: msg -> WireSize
messageWithLengthSize msg :: msg
msg = FieldType -> msg -> WireSize
forall b. Wire b => FieldType -> b -> WireSize
wireSize 11 msg
msg
messageAsFieldSize :: (ReflectDescriptor msg,Wire msg) => FieldId -> msg -> WireSize
messageAsFieldSize :: FieldId -> msg -> WireSize
messageAsFieldSize fi :: FieldId
fi msg :: msg
msg = let headerSize :: WireSize
headerSize = WireTag -> WireSize
size'WireTag (FieldId -> FieldType -> WireTag
toWireTag FieldId
fi 11)
in WireSize
headerSize WireSize -> WireSize -> WireSize
forall a. Num a => a -> a -> a
+ msg -> WireSize
forall msg. (ReflectDescriptor msg, Wire msg) => msg -> WireSize
messageWithLengthSize msg
msg
messagePut :: (ReflectDescriptor msg, Wire msg) => msg -> ByteString
messagePut :: msg -> ByteString
messagePut msg :: msg
msg = Put -> ByteString
runPut (msg -> Put
forall msg. (ReflectDescriptor msg, Wire msg) => msg -> Put
messagePutM msg
msg)
messageWithLengthPut :: (ReflectDescriptor msg, Wire msg) => msg -> ByteString
messageWithLengthPut :: msg -> ByteString
messageWithLengthPut msg :: msg
msg = Put -> ByteString
runPut (msg -> Put
forall msg. (ReflectDescriptor msg, Wire msg) => msg -> Put
messageWithLengthPutM msg
msg)
messagePutM :: (ReflectDescriptor msg, Wire msg) => msg -> Put
messagePutM :: msg -> Put
messagePutM msg :: msg
msg = FieldType -> msg -> Put
forall b. Wire b => FieldType -> b -> Put
wirePut 10 msg
msg
messageWithLengthPutM :: (ReflectDescriptor msg, Wire msg) => msg -> Put
messageWithLengthPutM :: msg -> Put
messageWithLengthPutM msg :: msg
msg = FieldType -> msg -> Put
forall b. Wire b => FieldType -> b -> Put
wirePut 11 msg
msg
messageAsFieldPutM :: (ReflectDescriptor msg, Wire msg) => FieldId -> msg -> Put
messageAsFieldPutM :: FieldId -> msg -> Put
messageAsFieldPutM fi :: FieldId
fi msg :: msg
msg = let wireTag :: WireTag
wireTag = FieldId -> FieldType -> WireTag
toWireTag FieldId
fi 11
in WireTag -> FieldType -> msg -> Put
forall v. Wire v => WireTag -> FieldType -> v -> Put
wirePutReq WireTag
wireTag 11 msg
msg
messageGet :: (ReflectDescriptor msg, Wire msg) => ByteString -> Either String (msg,ByteString)
messageGet :: ByteString -> Either String (msg, ByteString)
messageGet bs :: ByteString
bs = Get msg -> ByteString -> Either String (msg, ByteString)
forall r. Get r -> ByteString -> Either String (r, ByteString)
runGetOnLazy Get msg
forall msg. (ReflectDescriptor msg, Wire msg) => Get msg
messageGetM ByteString
bs
messageWithLengthGet :: (ReflectDescriptor msg, Wire msg) => ByteString -> Either String (msg,ByteString)
messageWithLengthGet :: ByteString -> Either String (msg, ByteString)
messageWithLengthGet bs :: ByteString
bs = Get msg -> ByteString -> Either String (msg, ByteString)
forall r. Get r -> ByteString -> Either String (r, ByteString)
runGetOnLazy Get msg
forall msg. (ReflectDescriptor msg, Wire msg) => Get msg
messageWithLengthGetM ByteString
bs
messageGetM :: (ReflectDescriptor msg, Wire msg) => Get msg
messageGetM :: Get msg
messageGetM = FieldType -> Get msg
forall b. Wire b => FieldType -> Get b
wireGet 10
messageWithLengthGetM :: (ReflectDescriptor msg, Wire msg) => Get msg
messageWithLengthGetM :: Get msg
messageWithLengthGetM = FieldType -> Get msg
forall b. Wire b => FieldType -> Get b
wireGet 11
messageAsFieldGetM :: (ReflectDescriptor msg, Wire msg) => Get (FieldId,msg)
messageAsFieldGetM :: Get (FieldId, msg)
messageAsFieldGetM = do
WireTag
wireTag <- (Word32 -> WireTag) -> Get Word32 -> Get WireTag
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Word32 -> WireTag
WireTag Get Word32
forall a. (Show a, Integral a, Bits a) => Get a
getVarInt
let (fieldId :: FieldId
fieldId,wireType :: WireType
wireType) = WireTag -> (FieldId, WireType)
splitWireTag WireTag
wireTag
Bool -> Get () -> Get ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (WireType
wireType WireType -> WireType -> Bool
forall a. Eq a => a -> a -> Bool
/= 2) (String -> Get ()
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (String -> Get ()) -> String -> Get ()
forall a b. (a -> b) -> a -> b
$ "messageAsFieldGetM: wireType was not 2 "String -> String -> String
forall a. [a] -> [a] -> [a]
++(FieldId, WireType) -> String
forall a. Show a => a -> String
show (FieldId
fieldId,WireType
wireType))
msg
msg <- FieldType -> Get msg
forall b. Wire b => FieldType -> Get b
wireGet 11
(FieldId, msg) -> Get (FieldId, msg)
forall (m :: * -> *) a. Monad m => a -> m a
return (FieldId
fieldId,msg
msg)
getFromBS :: Get r -> ByteString -> r
getFromBS :: Get r -> ByteString -> r
getFromBS parser :: Get r
parser bs :: ByteString
bs = case Get r -> ByteString -> Either String (r, ByteString)
forall r. Get r -> ByteString -> Either String (r, ByteString)
runGetOnLazy Get r
parser ByteString
bs of
Left msg :: String
msg -> String -> r
forall a. HasCallStack => String -> a
error String
msg
Right (r :: r
r,_) -> r
r
runGetOnLazy :: Get r -> ByteString -> Either String (r,ByteString)
runGetOnLazy :: Get r -> ByteString -> Either String (r, ByteString)
runGetOnLazy parser :: Get r
parser bs :: ByteString
bs = Result r -> Either String (r, ByteString)
forall r. Result r -> Either String (r, ByteString)
resolve (Get r -> ByteString -> Result r
forall a. Get a -> ByteString -> Result a
runGetAll Get r
parser ByteString
bs)
where resolve :: Result r -> Either String (r,ByteString)
resolve :: Result r -> Either String (r, ByteString)
resolve (Failed i :: WireSize
i s :: String
s) = String -> Either String (r, ByteString)
forall a b. a -> Either a b
Left ("Failed at "String -> String -> String
forall a. [a] -> [a] -> [a]
++WireSize -> String
forall a. Show a => a -> String
show WireSize
iString -> String -> String
forall a. [a] -> [a] -> [a]
++" : "String -> String -> String
forall a. [a] -> [a] -> [a]
++String
s)
resolve (Finished bsOut :: ByteString
bsOut _i :: WireSize
_i r :: r
r) = (r, ByteString) -> Either String (r, ByteString)
forall a b. b -> Either a b
Right (r
r,ByteString
bsOut)
resolve (Partial op :: Maybe ByteString -> Result r
op) = Result r -> Either String (r, ByteString)
forall r. Result r -> Either String (r, ByteString)
resolve (Maybe ByteString -> Result r
op Maybe ByteString
forall a. Maybe a
Nothing)
prependMessageSize :: WireSize -> WireSize
prependMessageSize :: WireSize -> WireSize
prependMessageSize n :: WireSize
n = WireSize
n WireSize -> WireSize -> WireSize
forall a. Num a => a -> a -> a
+ WireSize -> WireSize
size'WireSize WireSize
n
{-# INLINE sequencePutWithSize #-}
sequencePutWithSize :: F.Foldable f => f (PutM WireSize) -> PutM WireSize
sequencePutWithSize :: f (PutM WireSize) -> PutM WireSize
sequencePutWithSize =
let combine :: b -> m b -> m b
combine size :: b
size act :: m b
act =
do b
size2 <- m b
act
b -> m b
forall (m :: * -> *) a. Monad m => a -> m a
return (b -> m b) -> b -> m b
forall a b. (a -> b) -> a -> b
$! b
size b -> b -> b
forall a. Num a => a -> a -> a
+ b
size2
in (WireSize -> PutM WireSize -> PutM WireSize)
-> WireSize -> f (PutM WireSize) -> PutM WireSize
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldM WireSize -> PutM WireSize -> PutM WireSize
forall (m :: * -> *) b. (Monad m, Num b) => b -> m b -> m b
combine 0
{-# INLINE wirePutReqWithSize #-}
wirePutReqWithSize :: Wire v => WireTag -> FieldType -> v -> PutM WireSize
wirePutReqWithSize :: WireTag -> FieldType -> v -> PutM WireSize
wirePutReqWithSize wireTag :: WireTag
wireTag fieldType :: FieldType
fieldType v :: v
v =
let startTag :: Word32
startTag = WireTag -> Word32
getWireTag WireTag
wireTag
endTag :: Word32
endTag = Word32 -> Word32
forall a. Enum a => a -> a
succ Word32
startTag
putTag :: Word32 -> PutM WireSize
putTag tag :: Word32
tag = Word32 -> Put
forall a. (Integral a, Bits a) => a -> Put
putVarUInt Word32
tag Put -> PutM WireSize -> PutM WireSize
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> WireSize -> PutM WireSize
forall (m :: * -> *) a. Monad m => a -> m a
return (Word32 -> WireSize
size'Word32 Word32
tag)
putAct :: PutM WireSize
putAct = FieldType -> v -> PutM WireSize
forall b. Wire b => FieldType -> b -> PutM WireSize
wirePutWithSize FieldType
fieldType v
v
in case FieldType
fieldType of
10 -> [PutM WireSize] -> PutM WireSize
forall (f :: * -> *).
Foldable f =>
f (PutM WireSize) -> PutM WireSize
sequencePutWithSize [Word32 -> PutM WireSize
putTag Word32
startTag, PutM WireSize
putAct, Word32 -> PutM WireSize
putTag Word32
endTag]
_ -> [PutM WireSize] -> PutM WireSize
forall (f :: * -> *).
Foldable f =>
f (PutM WireSize) -> PutM WireSize
sequencePutWithSize [Word32 -> PutM WireSize
putTag Word32
startTag, PutM WireSize
putAct]
{-# INLINE wirePutOptWithSize #-}
wirePutOptWithSize :: Wire v => WireTag -> FieldType -> Maybe v -> PutM WireSize
wirePutOptWithSize :: WireTag -> FieldType -> Maybe v -> PutM WireSize
wirePutOptWithSize _wireTag :: WireTag
_wireTag _fieldType :: FieldType
_fieldType Nothing = WireSize -> PutM WireSize
forall (m :: * -> *) a. Monad m => a -> m a
return 0
wirePutOptWithSize wireTag :: WireTag
wireTag fieldType :: FieldType
fieldType (Just v :: v
v) = WireTag -> FieldType -> v -> PutM WireSize
forall v. Wire v => WireTag -> FieldType -> v -> PutM WireSize
wirePutReqWithSize WireTag
wireTag FieldType
fieldType v
v
{-# INLINE wirePutRepWithSize #-}
wirePutRepWithSize :: Wire v => WireTag -> FieldType -> Seq v -> PutM WireSize
wirePutRepWithSize :: WireTag -> FieldType -> Seq v -> PutM WireSize
wirePutRepWithSize wireTag :: WireTag
wireTag fieldType :: FieldType
fieldType vs :: Seq v
vs =
Seq (PutM WireSize) -> PutM WireSize
forall (f :: * -> *).
Foldable f =>
f (PutM WireSize) -> PutM WireSize
sequencePutWithSize (Seq (PutM WireSize) -> PutM WireSize)
-> Seq (PutM WireSize) -> PutM WireSize
forall a b. (a -> b) -> a -> b
$ (v -> PutM WireSize) -> Seq v -> Seq (PutM WireSize)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (WireTag -> FieldType -> v -> PutM WireSize
forall v. Wire v => WireTag -> FieldType -> v -> PutM WireSize
wirePutReqWithSize WireTag
wireTag FieldType
fieldType) Seq v
vs
{-# INLINE wirePutPackedWithSize #-}
wirePutPackedWithSize :: Wire v => WireTag -> FieldType -> Seq v -> PutM WireSize
wirePutPackedWithSize :: WireTag -> FieldType -> Seq v -> PutM WireSize
wirePutPackedWithSize wireTag :: WireTag
wireTag fieldType :: FieldType
fieldType vs :: Seq v
vs =
let actInner :: PutM WireSize
actInner = Seq (PutM WireSize) -> PutM WireSize
forall (f :: * -> *).
Foldable f =>
f (PutM WireSize) -> PutM WireSize
sequencePutWithSize (Seq (PutM WireSize) -> PutM WireSize)
-> Seq (PutM WireSize) -> PutM WireSize
forall a b. (a -> b) -> a -> b
$ (v -> PutM WireSize) -> Seq v -> Seq (PutM WireSize)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (FieldType -> v -> PutM WireSize
forall b. Wire b => FieldType -> b -> PutM WireSize
wirePutWithSize FieldType
fieldType) Seq v
vs
(size :: WireSize
size, _) = PutM WireSize -> (WireSize, ByteString)
forall a. PutM a -> (a, ByteString)
runPutM PutM WireSize
actInner
tagSize :: WireSize
tagSize = WireTag -> WireSize
size'WireTag WireTag
wireTag
putTag :: WireTag -> PutM WireSize
putTag tag :: WireTag
tag = Word32 -> Put
forall a. (Integral a, Bits a) => a -> Put
putVarUInt (WireTag -> Word32
getWireTag WireTag
tag) Put -> PutM WireSize -> PutM WireSize
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> WireSize -> PutM WireSize
forall (m :: * -> *) a. Monad m => a -> m a
return WireSize
tagSize
in [PutM WireSize] -> PutM WireSize
forall (f :: * -> *).
Foldable f =>
f (PutM WireSize) -> PutM WireSize
sequencePutWithSize [WireTag -> PutM WireSize
putTag WireTag
wireTag, WireSize -> Put
putSize WireSize
sizePut -> PutM WireSize -> PutM WireSize
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>WireSize -> PutM WireSize
forall (m :: * -> *) a. Monad m => a -> m a
return (WireSize -> WireSize
size'WireSize WireSize
size), PutM WireSize
actInner]
{-# INLINE wirePutReq #-}
wirePutReq :: Wire v => WireTag -> FieldType -> v -> Put
wirePutReq :: WireTag -> FieldType -> v -> Put
wirePutReq wireTag :: WireTag
wireTag fieldType :: FieldType
fieldType v :: v
v = WireTag -> FieldType -> v -> PutM WireSize
forall v. Wire v => WireTag -> FieldType -> v -> PutM WireSize
wirePutReqWithSize WireTag
wireTag FieldType
fieldType v
v PutM WireSize -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> () -> Put
forall (m :: * -> *) a. Monad m => a -> m a
return ()
{-# INLINE wirePutOpt #-}
wirePutOpt :: Wire v => WireTag -> FieldType -> Maybe v -> Put
wirePutOpt :: WireTag -> FieldType -> Maybe v -> Put
wirePutOpt wireTag :: WireTag
wireTag fieldType :: FieldType
fieldType v :: Maybe v
v = WireTag -> FieldType -> Maybe v -> PutM WireSize
forall v.
Wire v =>
WireTag -> FieldType -> Maybe v -> PutM WireSize
wirePutOptWithSize WireTag
wireTag FieldType
fieldType Maybe v
v PutM WireSize -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> () -> Put
forall (m :: * -> *) a. Monad m => a -> m a
return ()
{-# INLINE wirePutRep #-}
wirePutRep :: Wire v => WireTag -> FieldType -> Seq v -> Put
wirePutRep :: WireTag -> FieldType -> Seq v -> Put
wirePutRep wireTag :: WireTag
wireTag fieldType :: FieldType
fieldType vs :: Seq v
vs = WireTag -> FieldType -> Seq v -> PutM WireSize
forall v. Wire v => WireTag -> FieldType -> Seq v -> PutM WireSize
wirePutRepWithSize WireTag
wireTag FieldType
fieldType Seq v
vs PutM WireSize -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> () -> Put
forall (m :: * -> *) a. Monad m => a -> m a
return ()
{-# INLINE wirePutPacked #-}
wirePutPacked :: Wire v => WireTag -> FieldType -> Seq v -> Put
wirePutPacked :: WireTag -> FieldType -> Seq v -> Put
wirePutPacked wireTag :: WireTag
wireTag fieldType :: FieldType
fieldType vs :: Seq v
vs = WireTag -> FieldType -> Seq v -> PutM WireSize
forall v. Wire v => WireTag -> FieldType -> Seq v -> PutM WireSize
wirePutPackedWithSize WireTag
wireTag FieldType
fieldType Seq v
vs PutM WireSize -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> () -> Put
forall (m :: * -> *) a. Monad m => a -> m a
return ()
{-# INLINE wireSizeReq #-}
wireSizeReq :: Wire v => Int64 -> FieldType -> v -> Int64
wireSizeReq :: WireSize -> FieldType -> v -> WireSize
wireSizeReq tagSize :: WireSize
tagSize 10 v :: v
v = WireSize
tagSize WireSize -> WireSize -> WireSize
forall a. Num a => a -> a -> a
+ FieldType -> v -> WireSize
forall b. Wire b => FieldType -> b -> WireSize
wireSize 10 v
v WireSize -> WireSize -> WireSize
forall a. Num a => a -> a -> a
+ WireSize
tagSize
wireSizeReq tagSize :: WireSize
tagSize fieldType :: FieldType
fieldType v :: v
v = WireSize
tagSize WireSize -> WireSize -> WireSize
forall a. Num a => a -> a -> a
+ FieldType -> v -> WireSize
forall b. Wire b => FieldType -> b -> WireSize
wireSize FieldType
fieldType v
v
{-# INLINE wireSizeOpt #-}
wireSizeOpt :: Wire v => Int64 -> FieldType -> Maybe v -> Int64
wireSizeOpt :: WireSize -> FieldType -> Maybe v -> WireSize
wireSizeOpt _tagSize :: WireSize
_tagSize _i :: FieldType
_i Nothing = 0
wireSizeOpt tagSize :: WireSize
tagSize i :: FieldType
i (Just v :: v
v) = WireSize -> FieldType -> v -> WireSize
forall v. Wire v => WireSize -> FieldType -> v -> WireSize
wireSizeReq WireSize
tagSize FieldType
i v
v
{-# INLINE wireSizeRep #-}
wireSizeRep :: Wire v => Int64 -> FieldType -> Seq v -> Int64
wireSizeRep :: WireSize -> FieldType -> Seq v -> WireSize
wireSizeRep tagSize :: WireSize
tagSize i :: FieldType
i vs :: Seq v
vs = (WireSize -> v -> WireSize) -> WireSize -> Seq v -> WireSize
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
F.foldl' (\n :: WireSize
n v :: v
v -> WireSize
n WireSize -> WireSize -> WireSize
forall a. Num a => a -> a -> a
+ WireSize -> FieldType -> v -> WireSize
forall v. Wire v => WireSize -> FieldType -> v -> WireSize
wireSizeReq WireSize
tagSize FieldType
i v
v) 0 Seq v
vs
{-# INLINE wireSizePacked #-}
wireSizePacked :: Wire v => Int64 -> FieldType -> Seq v -> Int64
wireSizePacked :: WireSize -> FieldType -> Seq v -> WireSize
wireSizePacked tagSize :: WireSize
tagSize i :: FieldType
i vs :: Seq v
vs = WireSize
tagSize WireSize -> WireSize -> WireSize
forall a. Num a => a -> a -> a
+ WireSize -> WireSize
prependMessageSize ((WireSize -> v -> WireSize) -> WireSize -> Seq v -> WireSize
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
F.foldl' (\n :: WireSize
n v :: v
v -> WireSize
n WireSize -> WireSize -> WireSize
forall a. Num a => a -> a -> a
+ FieldType -> v -> WireSize
forall b. Wire b => FieldType -> b -> WireSize
wireSize FieldType
i v
v) 0 Seq v
vs)
{-# INLINE putSize #-}
putSize :: WireSize -> Put
putSize :: WireSize -> Put
putSize = WireSize -> Put
forall a. (Integral a, Bits a) => a -> Put
putVarUInt
toPackedWireTag :: FieldId -> WireTag
toPackedWireTag :: FieldId -> WireTag
toPackedWireTag fieldId :: FieldId
fieldId = FieldId -> WireType -> WireTag
mkWireTag FieldId
fieldId 2
toWireTag :: FieldId -> FieldType -> WireTag
toWireTag :: FieldId -> FieldType -> WireTag
toWireTag fieldId :: FieldId
fieldId fieldType :: FieldType
fieldType
= FieldId -> WireType -> WireTag
mkWireTag FieldId
fieldId (FieldType -> WireType
toWireType FieldType
fieldType)
mkWireTag :: FieldId -> WireType -> WireTag
mkWireTag :: FieldId -> WireType -> WireTag
mkWireTag fieldId :: FieldId
fieldId wireType :: WireType
wireType
= ((Int32 -> WireTag
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32 -> WireTag) -> (FieldId -> Int32) -> FieldId -> WireTag
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FieldId -> Int32
getFieldId (FieldId -> WireTag) -> FieldId -> WireTag
forall a b. (a -> b) -> a -> b
$ FieldId
fieldId) WireTag -> Int -> WireTag
forall a. Bits a => a -> Int -> a
`shiftL` 3) WireTag -> WireTag -> WireTag
forall a. Bits a => a -> a -> a
.|. (Word32 -> WireTag
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32 -> WireTag) -> (WireType -> Word32) -> WireType -> WireTag
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WireType -> Word32
getWireType (WireType -> WireTag) -> WireType -> WireTag
forall a b. (a -> b) -> a -> b
$ WireType
wireType)
splitWireTag :: WireTag -> (FieldId,WireType)
splitWireTag :: WireTag -> (FieldId, WireType)
splitWireTag (WireTag wireTag :: Word32
wireTag) = ( Int32 -> FieldId
FieldId (Int32 -> FieldId) -> (Word32 -> Int32) -> Word32 -> FieldId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word32 -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32 -> FieldId) -> Word32 -> FieldId
forall a b. (a -> b) -> a -> b
$ Word32
wireTag Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
`shiftR` 3
, Word32 -> WireType
WireType (Word32 -> WireType) -> (Word32 -> Word32) -> Word32 -> WireType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word32 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32 -> WireType) -> Word32 -> WireType
forall a b. (a -> b) -> a -> b
$ Word32
wireTag Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
.&. 7 )
fieldIdOf :: WireTag -> FieldId
fieldIdOf :: WireTag -> FieldId
fieldIdOf = (FieldId, WireType) -> FieldId
forall a b. (a, b) -> a
fst ((FieldId, WireType) -> FieldId)
-> (WireTag -> (FieldId, WireType)) -> WireTag -> FieldId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WireTag -> (FieldId, WireType)
splitWireTag
{-# INLINE wireGetPackedEnum #-}
wireGetPackedEnum :: (Typeable e,Enum e) => (Int -> Maybe e) -> Get (Seq e)
wireGetPackedEnum :: (Int -> Maybe e) -> Get (Seq e)
wireGetPackedEnum toMaybe'Enum :: Int -> Maybe e
toMaybe'Enum = do
WireSize
packedLength <- Get WireSize
forall a. (Show a, Integral a, Bits a) => Get a
getVarInt
WireSize
start <- Get WireSize
bytesRead
let stop :: WireSize
stop = WireSize
packedLengthWireSize -> WireSize -> WireSize
forall a. Num a => a -> a -> a
+WireSize
start
next :: Seq e -> Get (Seq e)
next !Seq e
soFar = do
WireSize
here <- Get WireSize
bytesRead
case WireSize -> WireSize -> Ordering
forall a. Ord a => a -> a -> Ordering
compare WireSize
stop WireSize
here of
EQ -> Seq e -> Get (Seq e)
forall (m :: * -> *) a. Monad m => a -> m a
return Seq e
soFar
LT -> WireSize -> Seq e -> WireSize -> WireSize -> Get (Seq e)
tooMuchData WireSize
packedLength Seq e
soFar WireSize
start WireSize
here
GT -> do
e
value <- (Int -> Maybe e) -> Get e
forall e. (Typeable e, Enum e) => (Int -> Maybe e) -> Get e
wireGetEnum Int -> Maybe e
toMaybe'Enum
e -> Get (Seq e) -> Get (Seq e)
forall a b. a -> b -> b
seq e
value (Get (Seq e) -> Get (Seq e)) -> Get (Seq e) -> Get (Seq e)
forall a b. (a -> b) -> a -> b
$ Seq e -> Get (Seq e)
next (Seq e
soFar Seq e -> e -> Seq e
forall a. Seq a -> a -> Seq a
|> e
value)
Seq e -> Get (Seq e)
next Seq e
forall a. Seq a
Seq.empty
where
Just e :: e
e = Maybe e
forall a. HasCallStack => a
undefined Maybe e -> Maybe e -> Maybe e
forall a. a -> a -> a
`asTypeOf` (Int -> Maybe e
toMaybe'Enum Int
forall a. HasCallStack => a
undefined)
tooMuchData :: WireSize -> Seq e -> WireSize -> WireSize -> Get (Seq e)
tooMuchData packedLength :: WireSize
packedLength soFar :: Seq e
soFar start :: WireSize
start here :: WireSize
here =
String -> Get (Seq e)
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError ("Text.ProtocolBuffers.WireMessage.wireGetPackedEnum: overran expected length."
String -> String -> String
forall a. [a] -> [a] -> [a]
++ "\n The type and count of values so far is " String -> String -> String
forall a. [a] -> [a] -> [a]
++ (TypeRep, Int) -> String
forall a. Show a => a -> String
show (e -> TypeRep
forall a. Typeable a => a -> TypeRep
typeOf (e
forall a. HasCallStack => a
undefined e -> e -> e
forall a. a -> a -> a
`asTypeOf` e
e),Seq e -> Int
forall a. Seq a -> Int
Seq.length Seq e
soFar)
String -> String -> String
forall a. [a] -> [a] -> [a]
++ "\n at (packedLength,start,here) == " String -> String -> String
forall a. [a] -> [a] -> [a]
++ (WireSize, WireSize, WireSize) -> String
forall a. Show a => a -> String
show (WireSize
packedLength,WireSize
start,WireSize
here))
{-# INLINE genericPacked #-}
genericPacked :: Wire a => FieldType -> Get (Seq a)
genericPacked :: FieldType -> Get (Seq a)
genericPacked ft :: FieldType
ft = do
WireSize
packedLength <- Get WireSize
forall a. (Show a, Integral a, Bits a) => Get a
getVarInt
WireSize
start <- Get WireSize
bytesRead
let stop :: WireSize
stop = WireSize
packedLengthWireSize -> WireSize -> WireSize
forall a. Num a => a -> a -> a
+WireSize
start
next :: Seq a -> Get (Seq a)
next !Seq a
soFar = do
WireSize
here <- Get WireSize
bytesRead
case WireSize -> WireSize -> Ordering
forall a. Ord a => a -> a -> Ordering
compare WireSize
stop WireSize
here of
EQ -> Seq a -> Get (Seq a)
forall (m :: * -> *) a. Monad m => a -> m a
return Seq a
soFar
LT -> WireSize -> Seq a -> WireSize -> WireSize -> Get (Seq a)
tooMuchData WireSize
packedLength Seq a
soFar WireSize
start WireSize
here
GT -> do
a
value <- FieldType -> Get a
forall b. Wire b => FieldType -> Get b
wireGet FieldType
ft
a -> Get (Seq a) -> Get (Seq a)
forall a b. a -> b -> b
seq a
value (Get (Seq a) -> Get (Seq a)) -> Get (Seq a) -> Get (Seq a)
forall a b. (a -> b) -> a -> b
$! Seq a -> Get (Seq a)
next (Seq a -> Get (Seq a)) -> Seq a -> Get (Seq a)
forall a b. (a -> b) -> a -> b
$! Seq a
soFar Seq a -> a -> Seq a
forall a. Seq a -> a -> Seq a
|> a
value
Seq a -> Get (Seq a)
next Seq a
forall a. Seq a
Seq.empty
where
tooMuchData :: WireSize -> Seq a -> WireSize -> WireSize -> Get (Seq a)
tooMuchData packedLength :: WireSize
packedLength soFar :: Seq a
soFar start :: WireSize
start here :: WireSize
here =
String -> Get (Seq a)
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError ("Text.ProtocolBuffers.WireMessage.genericPacked: overran expected length."
String -> String -> String
forall a. [a] -> [a] -> [a]
++ "\n The FieldType and count of values so far are " String -> String -> String
forall a. [a] -> [a] -> [a]
++ (FieldType, Int) -> String
forall a. Show a => a -> String
show (FieldType
ft,Seq a -> Int
forall a. Seq a -> Int
Seq.length Seq a
soFar)
String -> String -> String
forall a. [a] -> [a] -> [a]
++ "\n at (packedLength,start,here) == " String -> String -> String
forall a. [a] -> [a] -> [a]
++ (WireSize, WireSize, WireSize) -> String
forall a. Show a => a -> String
show (WireSize
packedLength,WireSize
start,WireSize
here))
getMessageWith :: (Default message, ReflectDescriptor message)
=> (WireTag -> message -> Get message)
-> Get message
getMessageWith :: (WireTag -> message -> Get message) -> Get message
getMessageWith updater :: WireTag -> message -> Get message
updater = do
WireSize
messageLength <- Get WireSize
forall a. (Show a, Integral a, Bits a) => Get a
getVarInt
WireSize
start <- Get WireSize
bytesRead
let stop :: WireSize
stop = WireSize
messageLengthWireSize -> WireSize -> WireSize
forall a. Num a => a -> a -> a
+WireSize
start
go :: Set WireTag -> message -> Get message
go reqs :: Set WireTag
reqs !message
message | Set WireTag -> Bool
forall a. Set a -> Bool
Set.null Set WireTag
reqs = message -> Get message
go' message
message
| Bool
otherwise = do
WireSize
here <- Get WireSize
bytesRead
case WireSize -> WireSize -> Ordering
forall a. Ord a => a -> a -> Ordering
compare WireSize
stop WireSize
here of
EQ -> WireSize -> WireSize -> Get message
notEnoughData WireSize
messageLength WireSize
start
LT -> WireSize -> WireSize -> WireSize -> Get message
tooMuchData WireSize
messageLength WireSize
start WireSize
here
GT -> do
WireTag
wireTag <- (Word32 -> WireTag) -> Get Word32 -> Get WireTag
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Word32 -> WireTag
WireTag Get Word32
forall a. (Show a, Integral a, Bits a) => Get a
getVarInt
let
reqs' :: Set WireTag
reqs' = WireTag -> Set WireTag -> Set WireTag
forall a. Ord a => a -> Set a -> Set a
Set.delete WireTag
wireTag Set WireTag
reqs
WireTag -> message -> Get message
updater WireTag
wireTag message
message Get message -> (message -> Get message) -> Get message
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Set WireTag -> message -> Get message
go Set WireTag
reqs'
go' :: message -> Get message
go' !message
message = do
WireSize
here <- Get WireSize
bytesRead
case WireSize -> WireSize -> Ordering
forall a. Ord a => a -> a -> Ordering
compare WireSize
stop WireSize
here of
EQ -> message -> Get message
forall (m :: * -> *) a. Monad m => a -> m a
return message
message
LT -> WireSize -> WireSize -> WireSize -> Get message
tooMuchData WireSize
messageLength WireSize
start WireSize
here
GT -> do
WireTag
wireTag <- (Word32 -> WireTag) -> Get Word32 -> Get WireTag
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Word32 -> WireTag
WireTag Get Word32
forall a. (Show a, Integral a, Bits a) => Get a
getVarInt
WireTag -> message -> Get message
updater WireTag
wireTag message
message Get message -> (message -> Get message) -> Get message
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= message -> Get message
go'
Set WireTag -> message -> Get message
go Set WireTag
required message
initialMessage
where
initialMessage :: message
initialMessage = message
forall a. Default a => a
defaultValue
(GetMessageInfo {requiredTags :: GetMessageInfo -> Set WireTag
requiredTags=Set WireTag
required}) = message -> GetMessageInfo
forall m. ReflectDescriptor m => m -> GetMessageInfo
getMessageInfo message
initialMessage
notEnoughData :: WireSize -> WireSize -> Get message
notEnoughData messageLength :: WireSize
messageLength start :: WireSize
start =
String -> Get message
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError ("Text.ProtocolBuffers.WireMessage.getMessageWith: Required fields missing when processing "
String -> String -> String
forall a. [a] -> [a] -> [a]
++ (ProtoName -> String
forall a. Show a => a -> String
show (ProtoName -> String)
-> (message -> ProtoName) -> message -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DescriptorInfo -> ProtoName
descName (DescriptorInfo -> ProtoName)
-> (message -> DescriptorInfo) -> message -> ProtoName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. message -> DescriptorInfo
forall m. ReflectDescriptor m => m -> DescriptorInfo
reflectDescriptorInfo (message -> String) -> message -> String
forall a b. (a -> b) -> a -> b
$ message
initialMessage)
String -> String -> String
forall a. [a] -> [a] -> [a]
++ "\n at (messageLength,start) == " String -> String -> String
forall a. [a] -> [a] -> [a]
++ (WireSize, WireSize) -> String
forall a. Show a => a -> String
show (WireSize
messageLength,WireSize
start))
tooMuchData :: WireSize -> WireSize -> WireSize -> Get message
tooMuchData messageLength :: WireSize
messageLength start :: WireSize
start here :: WireSize
here =
String -> Get message
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError ("Text.ProtocolBuffers.WireMessage.getMessageWith: overran expected length when processing"
String -> String -> String
forall a. [a] -> [a] -> [a]
++ (ProtoName -> String
forall a. Show a => a -> String
show (ProtoName -> String)
-> (message -> ProtoName) -> message -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DescriptorInfo -> ProtoName
descName (DescriptorInfo -> ProtoName)
-> (message -> DescriptorInfo) -> message -> ProtoName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. message -> DescriptorInfo
forall m. ReflectDescriptor m => m -> DescriptorInfo
reflectDescriptorInfo (message -> String) -> message -> String
forall a b. (a -> b) -> a -> b
$ message
initialMessage)
String -> String -> String
forall a. [a] -> [a] -> [a]
++ "\n at (messageLength,start,here) == " String -> String -> String
forall a. [a] -> [a] -> [a]
++ (WireSize, WireSize, WireSize) -> String
forall a. Show a => a -> String
show (WireSize
messageLength,WireSize
start,WireSize
here))
getBareMessageWith :: (Default message, ReflectDescriptor message)
=> (WireTag -> message -> Get message)
-> Get message
getBareMessageWith :: (WireTag -> message -> Get message) -> Get message
getBareMessageWith updater :: WireTag -> message -> Get message
updater = Set WireTag -> message -> Get message
go Set WireTag
required message
initialMessage
where
go :: Set WireTag -> message -> Get message
go reqs :: Set WireTag
reqs !message
message | Set WireTag -> Bool
forall a. Set a -> Bool
Set.null Set WireTag
reqs = message -> Get message
go' message
message
| Bool
otherwise = do
Bool
done <- Get Bool
isReallyEmpty
if Bool
done then Get message
notEnoughData
else do
WireTag
wireTag <- (Word32 -> WireTag) -> Get Word32 -> Get WireTag
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Word32 -> WireTag
WireTag Get Word32
forall a. (Show a, Integral a, Bits a) => Get a
getVarInt
let (_fieldId :: FieldId
_fieldId,wireType :: WireType
wireType) = WireTag -> (FieldId, WireType)
splitWireTag WireTag
wireTag
if WireType
wireType WireType -> WireType -> Bool
forall a. Eq a => a -> a -> Bool
== 4 then Get message
notEnoughData
else let reqs' :: Set WireTag
reqs' = WireTag -> Set WireTag -> Set WireTag
forall a. Ord a => a -> Set a -> Set a
Set.delete WireTag
wireTag Set WireTag
reqs
in WireTag -> message -> Get message
updater WireTag
wireTag message
message Get message -> (message -> Get message) -> Get message
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Set WireTag -> message -> Get message
go Set WireTag
reqs'
go' :: message -> Get message
go' !message
message = do
Bool
done <- Get Bool
isReallyEmpty
if Bool
done then message -> Get message
forall (m :: * -> *) a. Monad m => a -> m a
return message
message
else do
WireTag
wireTag <- (Word32 -> WireTag) -> Get Word32 -> Get WireTag
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Word32 -> WireTag
WireTag Get Word32
forall a. (Show a, Integral a, Bits a) => Get a
getVarInt
let (_fieldId :: FieldId
_fieldId,wireType :: WireType
wireType) = WireTag -> (FieldId, WireType)
splitWireTag WireTag
wireTag
if WireType
wireType WireType -> WireType -> Bool
forall a. Eq a => a -> a -> Bool
== 4 then message -> Get message
forall (m :: * -> *) a. Monad m => a -> m a
return message
message
else WireTag -> message -> Get message
updater WireTag
wireTag message
message Get message -> (message -> Get message) -> Get message
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= message -> Get message
go'
initialMessage :: message
initialMessage = message
forall a. Default a => a
defaultValue
(GetMessageInfo {requiredTags :: GetMessageInfo -> Set WireTag
requiredTags=Set WireTag
required}) = message -> GetMessageInfo
forall m. ReflectDescriptor m => m -> GetMessageInfo
getMessageInfo message
initialMessage
notEnoughData :: Get message
notEnoughData = String -> Get message
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError ("Text.ProtocolBuffers.WireMessage.getBareMessageWith: Required fields missing when processing "
String -> String -> String
forall a. [a] -> [a] -> [a]
++ (ProtoName -> String
forall a. Show a => a -> String
show (ProtoName -> String)
-> (message -> ProtoName) -> message -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DescriptorInfo -> ProtoName
descName (DescriptorInfo -> ProtoName)
-> (message -> DescriptorInfo) -> message -> ProtoName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. message -> DescriptorInfo
forall m. ReflectDescriptor m => m -> DescriptorInfo
reflectDescriptorInfo (message -> String) -> message -> String
forall a b. (a -> b) -> a -> b
$ message
initialMessage))
unknownField :: Typeable a => a -> FieldId -> Get a
unknownField :: a -> FieldId -> Get a
unknownField msg :: a
msg fieldId :: FieldId
fieldId = do
WireSize
here <- Get WireSize
bytesRead
String -> Get a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError ("Impossible? Text.ProtocolBuffers.WireMessage.unknownField"
String -> String -> String
forall a. [a] -> [a] -> [a]
++"\n Updater for "String -> String -> String
forall a. [a] -> [a] -> [a]
++TypeRep -> String
forall a. Show a => a -> String
show (a -> TypeRep
forall a. Typeable a => a -> TypeRep
typeOf a
msg)String -> String -> String
forall a. [a] -> [a] -> [a]
++" claims there is an unknown field id on wire: "String -> String -> String
forall a. [a] -> [a] -> [a]
++FieldId -> String
forall a. Show a => a -> String
show FieldId
fieldId
String -> String -> String
forall a. [a] -> [a] -> [a]
++"\n at a position just before byte location "String -> String -> String
forall a. [a] -> [a] -> [a]
++WireSize -> String
forall a. Show a => a -> String
show WireSize
here)
unknown :: (Typeable a,ReflectDescriptor a) => FieldId -> WireType -> a -> Get a
unknown :: FieldId -> WireType -> a -> Get a
unknown fieldId :: FieldId
fieldId wireType :: WireType
wireType initialMessage :: a
initialMessage = do
WireSize
here <- Get WireSize
bytesRead
String -> Get a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError ("Text.ProtocolBuffers.WireMessage.unknown: Unknown field found or failure parsing field (e.g. unexpected Enum value):"
String -> String -> String
forall a. [a] -> [a] -> [a]
++ "\n (message type name,field id number,wire type code,bytes read) == "
String -> String -> String
forall a. [a] -> [a] -> [a]
++ (TypeRep, FieldId, WireType, WireSize) -> String
forall a. Show a => a -> String
show (a -> TypeRep
forall a. Typeable a => a -> TypeRep
typeOf a
initialMessage,FieldId
fieldId,WireType
wireType,WireSize
here)
String -> String -> String
forall a. [a] -> [a] -> [a]
++ "\n when processing "
String -> String -> String
forall a. [a] -> [a] -> [a]
++ (ProtoName -> String
forall a. Show a => a -> String
show (ProtoName -> String) -> (a -> ProtoName) -> a -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DescriptorInfo -> ProtoName
descName (DescriptorInfo -> ProtoName)
-> (a -> DescriptorInfo) -> a -> ProtoName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> DescriptorInfo
forall m. ReflectDescriptor m => m -> DescriptorInfo
reflectDescriptorInfo (a -> String) -> a -> String
forall a b. (a -> b) -> a -> b
$ a
initialMessage))
{-# INLINE castWord32ToFloat #-}
castWord32ToFloat :: Word32 -> Float
castWord32ToFloat :: Word32 -> Float
castWord32ToFloat x :: Word32
x = (forall s. ST s Float) -> Float
forall a. (forall s. ST s a) -> a
runST ((Int, Int) -> Word32 -> ST s (STUArray s Int Word32)
forall (a :: * -> * -> *) e (m :: * -> *) i.
(MArray a e m, Ix i) =>
(i, i) -> e -> m (a i e)
newArray (0::Int,0) Word32
x ST s (STUArray s Int Word32)
-> (STUArray s Int Word32 -> ST s (STUArray s Int Float))
-> ST s (STUArray s Int Float)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= STUArray s Int Word32 -> ST s (STUArray s Int Float)
forall s ix a b. STUArray s ix a -> ST s (STUArray s ix b)
castSTUArray ST s (STUArray s Int Float)
-> (STUArray s Int Float -> ST s Float) -> ST s Float
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (STUArray s Int Float -> Int -> ST s Float)
-> Int -> STUArray s Int Float -> ST s Float
forall a b c. (a -> b -> c) -> b -> a -> c
flip STUArray s Int Float -> Int -> ST s Float
forall (a :: * -> * -> *) e (m :: * -> *) i.
(MArray a e m, Ix i) =>
a i e -> i -> m e
readArray 0)
{-# INLINE castFloatToWord32 #-}
castFloatToWord32 :: Float -> Word32
castFloatToWord32 :: Float -> Word32
castFloatToWord32 x :: Float
x = (forall s. ST s Word32) -> Word32
forall a. (forall s. ST s a) -> a
runST ((Int, Int) -> Float -> ST s (STUArray s Int Float)
forall (a :: * -> * -> *) e (m :: * -> *) i.
(MArray a e m, Ix i) =>
(i, i) -> e -> m (a i e)
newArray (0::Int,0) Float
x ST s (STUArray s Int Float)
-> (STUArray s Int Float -> ST s (STUArray s Int Word32))
-> ST s (STUArray s Int Word32)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= STUArray s Int Float -> ST s (STUArray s Int Word32)
forall s ix a b. STUArray s ix a -> ST s (STUArray s ix b)
castSTUArray ST s (STUArray s Int Word32)
-> (STUArray s Int Word32 -> ST s Word32) -> ST s Word32
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (STUArray s Int Word32 -> Int -> ST s Word32)
-> Int -> STUArray s Int Word32 -> ST s Word32
forall a b c. (a -> b -> c) -> b -> a -> c
flip STUArray s Int Word32 -> Int -> ST s Word32
forall (a :: * -> * -> *) e (m :: * -> *) i.
(MArray a e m, Ix i) =>
a i e -> i -> m e
readArray 0)
{-# INLINE castWord64ToDouble #-}
castWord64ToDouble :: Word64 -> Double
castWord64ToDouble :: Word64 -> Double
castWord64ToDouble x :: Word64
x = (forall s. ST s Double) -> Double
forall a. (forall s. ST s a) -> a
runST ((Int, Int) -> Word64 -> ST s (STUArray s Int Word64)
forall (a :: * -> * -> *) e (m :: * -> *) i.
(MArray a e m, Ix i) =>
(i, i) -> e -> m (a i e)
newArray (0::Int,0) Word64
x ST s (STUArray s Int Word64)
-> (STUArray s Int Word64 -> ST s (STUArray s Int Double))
-> ST s (STUArray s Int Double)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= STUArray s Int Word64 -> ST s (STUArray s Int Double)
forall s ix a b. STUArray s ix a -> ST s (STUArray s ix b)
castSTUArray ST s (STUArray s Int Double)
-> (STUArray s Int Double -> ST s Double) -> ST s Double
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (STUArray s Int Double -> Int -> ST s Double)
-> Int -> STUArray s Int Double -> ST s Double
forall a b c. (a -> b -> c) -> b -> a -> c
flip STUArray s Int Double -> Int -> ST s Double
forall (a :: * -> * -> *) e (m :: * -> *) i.
(MArray a e m, Ix i) =>
a i e -> i -> m e
readArray 0)
{-# INLINE castDoubleToWord64 #-}
castDoubleToWord64 :: Double -> Word64
castDoubleToWord64 :: Double -> Word64
castDoubleToWord64 x :: Double
x = (forall s. ST s Word64) -> Word64
forall a. (forall s. ST s a) -> a
runST ((Int, Int) -> Double -> ST s (STUArray s Int Double)
forall (a :: * -> * -> *) e (m :: * -> *) i.
(MArray a e m, Ix i) =>
(i, i) -> e -> m (a i e)
newArray (0::Int,0) Double
x ST s (STUArray s Int Double)
-> (STUArray s Int Double -> ST s (STUArray s Int Word64))
-> ST s (STUArray s Int Word64)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= STUArray s Int Double -> ST s (STUArray s Int Word64)
forall s ix a b. STUArray s ix a -> ST s (STUArray s ix b)
castSTUArray ST s (STUArray s Int Word64)
-> (STUArray s Int Word64 -> ST s Word64) -> ST s Word64
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (STUArray s Int Word64 -> Int -> ST s Word64)
-> Int -> STUArray s Int Word64 -> ST s Word64
forall a b c. (a -> b -> c) -> b -> a -> c
flip STUArray s Int Word64 -> Int -> ST s Word64
forall (a :: * -> * -> *) e (m :: * -> *) i.
(MArray a e m, Ix i) =>
a i e -> i -> m e
readArray 0)
wireSizeErr :: Typeable a => FieldType -> a -> WireSize
wireSizeErr :: FieldType -> a -> WireSize
wireSizeErr ft :: FieldType
ft x :: a
x = String -> WireSize
forall a. HasCallStack => String -> a
error (String -> WireSize) -> String -> WireSize
forall a b. (a -> b) -> a -> b
$ [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [ "Impossible? wireSize field type mismatch error: Field type number ", FieldType -> String
forall a. Show a => a -> String
show FieldType
ft
, " does not match internal type ", TypeRep -> String
forall a. Show a => a -> String
show (a -> TypeRep
forall a. Typeable a => a -> TypeRep
typeOf a
x) ]
wirePutErr :: Typeable a => FieldType -> a -> PutM b
wirePutErr :: FieldType -> a -> PutM b
wirePutErr ft :: FieldType
ft x :: a
x = String -> PutM b
forall a. HasCallStack => String -> a
error (String -> PutM b) -> String -> PutM b
forall a b. (a -> b) -> a -> b
$ [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [ "Impossible? wirePut field type mismatch error: Field type number ", FieldType -> String
forall a. Show a => a -> String
show FieldType
ft
, " does not match internal type ", TypeRep -> String
forall a. Show a => a -> String
show (a -> TypeRep
forall a. Typeable a => a -> TypeRep
typeOf a
x) ]
wireGetErr :: Typeable a => FieldType -> Get a
wireGetErr :: FieldType -> Get a
wireGetErr ft :: FieldType
ft = Get a
answer where
answer :: Get a
answer = String -> Get a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (String -> Get a) -> String -> Get a
forall a b. (a -> b) -> a -> b
$ [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [ "Impossible? wireGet field type mismatch error: Field type number ", FieldType -> String
forall a. Show a => a -> String
show FieldType
ft
, " does not match internal type ", TypeRep -> String
forall a. Show a => a -> String
show (a -> TypeRep
forall a. Typeable a => a -> TypeRep
typeOf (a
forall a. HasCallStack => a
undefined a -> a -> a
forall a. a -> a -> a
`asTypeOf` Get a -> a
forall a. Get a -> a
typeHack Get a
answer)) ]
typeHack :: Get a -> a
typeHack :: Get a -> a
typeHack = Get a -> a
forall a. HasCallStack => a
undefined
class Wire b where
{-# MINIMAL wireGet, wireSize, (wirePut | wirePutWithSize) #-}
wireSize :: FieldType -> b -> WireSize
{-# INLINE wirePut #-}
wirePut :: FieldType -> b -> Put
wirePut ft :: FieldType
ft x :: b
x = FieldType -> b -> PutM WireSize
forall b. Wire b => FieldType -> b -> PutM WireSize
wirePutWithSize FieldType
ft b
x PutM WireSize -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> () -> Put
forall (m :: * -> *) a. Monad m => a -> m a
return ()
{-# INLINE wirePutWithSize #-}
wirePutWithSize :: FieldType -> b -> PutM WireSize
wirePutWithSize ft :: FieldType
ft x :: b
x = FieldType -> b -> Put
forall b. Wire b => FieldType -> b -> Put
wirePut FieldType
ft b
x Put -> PutM WireSize -> PutM WireSize
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> WireSize -> PutM WireSize
forall (m :: * -> *) a. Monad m => a -> m a
return (FieldType -> b -> WireSize
forall b. Wire b => FieldType -> b -> WireSize
wireSize FieldType
ft b
x)
wireGet :: FieldType -> Get b
{-# INLINE wireGetPacked #-}
wireGetPacked :: FieldType -> Get (Seq b)
wireGetPacked ft :: FieldType
ft = String -> Get (Seq b)
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError ("Text.ProtocolBuffers.ProtoCompile.Basic: wireGetPacked default:"
String -> String -> String
forall a. [a] -> [a] -> [a]
++ "\n There is no way to get a packed FieldType of "String -> String -> String
forall a. [a] -> [a] -> [a]
++FieldType -> String
forall a. Show a => a -> String
show FieldType
ft
String -> String -> String
forall a. [a] -> [a] -> [a]
++ ".\n Either there is a bug in this library or the wire format is has been updated.")
instance Wire Double where
{-# INLINE wireSize #-}
wireSize :: FieldType -> Double -> WireSize
wireSize 1 _ = 8
wireSize ft :: FieldType
ft x :: Double
x = FieldType -> Double -> WireSize
forall a. Typeable a => FieldType -> a -> WireSize
wireSizeErr FieldType
ft Double
x
{-# INLINE wirePut #-}
wirePut :: FieldType -> Double -> Put
wirePut 1 x :: Double
x = Word64 -> Put
putWord64le (Double -> Word64
castDoubleToWord64 Double
x)
wirePut ft :: FieldType
ft x :: Double
x = FieldType -> Double -> Put
forall a b. Typeable a => FieldType -> a -> PutM b
wirePutErr FieldType
ft Double
x
{-# INLINE wireGet #-}
wireGet :: FieldType -> Get Double
wireGet 1 = (Word64 -> Double) -> Get Word64 -> Get Double
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Word64 -> Double
castWord64ToDouble Get Word64
getWord64le
wireGet ft :: FieldType
ft = FieldType -> Get Double
forall a. Typeable a => FieldType -> Get a
wireGetErr FieldType
ft
{-# INLINE wireGetPacked #-}
wireGetPacked :: FieldType -> Get (Seq Double)
wireGetPacked 1 = FieldType -> Get (Seq Double)
forall a. Wire a => FieldType -> Get (Seq a)
genericPacked 1
wireGetPacked ft :: FieldType
ft = FieldType -> Get (Seq Double)
forall a. Typeable a => FieldType -> Get a
wireGetErr FieldType
ft
instance Wire Float where
{-# INLINE wireSize #-}
wireSize :: FieldType -> Float -> WireSize
wireSize 2 _ = 4
wireSize ft :: FieldType
ft x :: Float
x = FieldType -> Float -> WireSize
forall a. Typeable a => FieldType -> a -> WireSize
wireSizeErr FieldType
ft Float
x
{-# INLINE wirePut #-}
wirePut :: FieldType -> Float -> Put
wirePut 2 x :: Float
x = Word32 -> Put
putWord32le (Float -> Word32
castFloatToWord32 Float
x)
wirePut ft :: FieldType
ft x :: Float
x = FieldType -> Float -> Put
forall a b. Typeable a => FieldType -> a -> PutM b
wirePutErr FieldType
ft Float
x
{-# INLINE wireGet #-}
wireGet :: FieldType -> Get Float
wireGet 2 = (Word32 -> Float) -> Get Word32 -> Get Float
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Word32 -> Float
castWord32ToFloat Get Word32
getWord32le
wireGet ft :: FieldType
ft = FieldType -> Get Float
forall a. Typeable a => FieldType -> Get a
wireGetErr FieldType
ft
{-# INLINE wireGetPacked #-}
wireGetPacked :: FieldType -> Get (Seq Float)
wireGetPacked 2 = FieldType -> Get (Seq Float)
forall a. Wire a => FieldType -> Get (Seq a)
genericPacked 2
wireGetPacked ft :: FieldType
ft = FieldType -> Get (Seq Float)
forall a. Typeable a => FieldType -> Get a
wireGetErr FieldType
ft
instance Wire Int64 where
{-# INLINE wireSize #-}
wireSize :: FieldType -> WireSize -> WireSize
wireSize 3 x :: WireSize
x = WireSize -> WireSize
size'Int64 WireSize
x
wireSize 18 x :: WireSize
x = Word64 -> WireSize
size'Word64 (WireSize -> Word64
zzEncode64 WireSize
x)
wireSize 16 _ = 8
wireSize ft :: FieldType
ft x :: WireSize
x = FieldType -> WireSize -> WireSize
forall a. Typeable a => FieldType -> a -> WireSize
wireSizeErr FieldType
ft WireSize
x
{-# INLINE wirePut #-}
wirePut :: FieldType -> WireSize -> Put
wirePut 3 x :: WireSize
x = WireSize -> Put
forall a. (Integral a, Bits a) => a -> Put
putVarSInt WireSize
x
wirePut 18 x :: WireSize
x = Word64 -> Put
forall a. (Integral a, Bits a) => a -> Put
putVarUInt (WireSize -> Word64
zzEncode64 WireSize
x)
wirePut 16 x :: WireSize
x = Word64 -> Put
putWord64le (WireSize -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral WireSize
x)
wirePut ft :: FieldType
ft x :: WireSize
x = FieldType -> WireSize -> Put
forall a b. Typeable a => FieldType -> a -> PutM b
wirePutErr FieldType
ft WireSize
x
{-# INLINE wireGet #-}
wireGet :: FieldType -> Get WireSize
wireGet 3 = Get WireSize
forall a. (Show a, Integral a, Bits a) => Get a
getVarInt
wireGet 18 = (Word64 -> WireSize) -> Get Word64 -> Get WireSize
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Word64 -> WireSize
zzDecode64 Get Word64
forall a. (Show a, Integral a, Bits a) => Get a
getVarInt
wireGet 16 = (Word64 -> WireSize) -> Get Word64 -> Get WireSize
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Word64 -> WireSize
forall a b. (Integral a, Num b) => a -> b
fromIntegral Get Word64
getWord64le
wireGet ft :: FieldType
ft = FieldType -> Get WireSize
forall a. Typeable a => FieldType -> Get a
wireGetErr FieldType
ft
{-# INLINE wireGetPacked #-}
wireGetPacked :: FieldType -> Get (Seq WireSize)
wireGetPacked 3 = FieldType -> Get (Seq WireSize)
forall a. Wire a => FieldType -> Get (Seq a)
genericPacked 3
wireGetPacked 18 = FieldType -> Get (Seq WireSize)
forall a. Wire a => FieldType -> Get (Seq a)
genericPacked 18
wireGetPacked 16 = FieldType -> Get (Seq WireSize)
forall a. Wire a => FieldType -> Get (Seq a)
genericPacked 16
wireGetPacked ft :: FieldType
ft = FieldType -> Get (Seq WireSize)
forall a. Typeable a => FieldType -> Get a
wireGetErr FieldType
ft
instance Wire Int32 where
{-# INLINE wireSize #-}
wireSize :: FieldType -> Int32 -> WireSize
wireSize 5 x :: Int32
x = Int32 -> WireSize
size'Int32 Int32
x
wireSize 17 x :: Int32
x = Word32 -> WireSize
size'Word32 (Int32 -> Word32
zzEncode32 Int32
x)
wireSize 15 _ = 4
wireSize ft :: FieldType
ft x :: Int32
x = FieldType -> Int32 -> WireSize
forall a. Typeable a => FieldType -> a -> WireSize
wireSizeErr FieldType
ft Int32
x
{-# INLINE wirePut #-}
wirePut :: FieldType -> Int32 -> Put
wirePut 5 x :: Int32
x = Int32 -> Put
forall a. (Integral a, Bits a) => a -> Put
putVarSInt Int32
x
wirePut 17 x :: Int32
x = Word32 -> Put
forall a. (Integral a, Bits a) => a -> Put
putVarUInt (Int32 -> Word32
zzEncode32 Int32
x)
wirePut 15 x :: Int32
x = Word32 -> Put
putWord32le (Int32 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int32
x)
wirePut ft :: FieldType
ft x :: Int32
x = FieldType -> Int32 -> Put
forall a b. Typeable a => FieldType -> a -> PutM b
wirePutErr FieldType
ft Int32
x
{-# INLINE wireGet #-}
wireGet :: FieldType -> Get Int32
wireGet 5 = Get Int32
forall a. (Show a, Integral a, Bits a) => Get a
getVarInt
wireGet 17 = (Word32 -> Int32) -> Get Word32 -> Get Int32
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Word32 -> Int32
zzDecode32 Get Word32
forall a. (Show a, Integral a, Bits a) => Get a
getVarInt
wireGet 15 = (Word32 -> Int32) -> Get Word32 -> Get Int32
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Word32 -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Get Word32
getWord32le
wireGet ft :: FieldType
ft = FieldType -> Get Int32
forall a. Typeable a => FieldType -> Get a
wireGetErr FieldType
ft
{-# INLINE wireGetPacked #-}
wireGetPacked :: FieldType -> Get (Seq Int32)
wireGetPacked 5 = FieldType -> Get (Seq Int32)
forall a. Wire a => FieldType -> Get (Seq a)
genericPacked 5
wireGetPacked 17 = FieldType -> Get (Seq Int32)
forall a. Wire a => FieldType -> Get (Seq a)
genericPacked 17
wireGetPacked 15 = FieldType -> Get (Seq Int32)
forall a. Wire a => FieldType -> Get (Seq a)
genericPacked 15
wireGetPacked ft :: FieldType
ft = FieldType -> Get (Seq Int32)
forall a. Typeable a => FieldType -> Get a
wireGetErr FieldType
ft
instance Wire Word64 where
{-# INLINE wireSize #-}
wireSize :: FieldType -> Word64 -> WireSize
wireSize 4 x :: Word64
x = Word64 -> WireSize
size'Word64 Word64
x
wireSize 6 _ = 8
wireSize ft :: FieldType
ft x :: Word64
x = FieldType -> Word64 -> WireSize
forall a. Typeable a => FieldType -> a -> WireSize
wireSizeErr FieldType
ft Word64
x
{-# INLINE wirePut #-}
wirePut :: FieldType -> Word64 -> Put
wirePut 4 x :: Word64
x = Word64 -> Put
forall a. (Integral a, Bits a) => a -> Put
putVarUInt Word64
x
wirePut 6 x :: Word64
x = Word64 -> Put
putWord64le Word64
x
wirePut ft :: FieldType
ft x :: Word64
x = FieldType -> Word64 -> Put
forall a b. Typeable a => FieldType -> a -> PutM b
wirePutErr FieldType
ft Word64
x
{-# INLINE wireGet #-}
wireGet :: FieldType -> Get Word64
wireGet 6 = Get Word64
getWord64le
wireGet 4 = Get Word64
forall a. (Show a, Integral a, Bits a) => Get a
getVarInt
wireGet ft :: FieldType
ft = FieldType -> Get Word64
forall a. Typeable a => FieldType -> Get a
wireGetErr FieldType
ft
{-# INLINE wireGetPacked #-}
wireGetPacked :: FieldType -> Get (Seq Word64)
wireGetPacked 6 = FieldType -> Get (Seq Word64)
forall a. Wire a => FieldType -> Get (Seq a)
genericPacked 6
wireGetPacked 4 = FieldType -> Get (Seq Word64)
forall a. Wire a => FieldType -> Get (Seq a)
genericPacked 4
wireGetPacked ft :: FieldType
ft = FieldType -> Get (Seq Word64)
forall a. Typeable a => FieldType -> Get a
wireGetErr FieldType
ft
instance Wire Word32 where
{-# INLINE wireSize #-}
wireSize :: FieldType -> Word32 -> WireSize
wireSize 13 x :: Word32
x = Word32 -> WireSize
size'Word32 Word32
x
wireSize 7 _ = 4
wireSize ft :: FieldType
ft x :: Word32
x = FieldType -> Word32 -> WireSize
forall a. Typeable a => FieldType -> a -> WireSize
wireSizeErr FieldType
ft Word32
x
{-# INLINE wirePut #-}
wirePut :: FieldType -> Word32 -> Put
wirePut 13 x :: Word32
x = Word32 -> Put
forall a. (Integral a, Bits a) => a -> Put
putVarUInt Word32
x
wirePut 7 x :: Word32
x = Word32 -> Put
putWord32le Word32
x
wirePut ft :: FieldType
ft x :: Word32
x = FieldType -> Word32 -> Put
forall a b. Typeable a => FieldType -> a -> PutM b
wirePutErr FieldType
ft Word32
x
{-# INLINE wireGet #-}
wireGet :: FieldType -> Get Word32
wireGet 13 = Get Word32
forall a. (Show a, Integral a, Bits a) => Get a
getVarInt
wireGet 7 = Get Word32
getWord32le
wireGet ft :: FieldType
ft = FieldType -> Get Word32
forall a. Typeable a => FieldType -> Get a
wireGetErr FieldType
ft
{-# INLINE wireGetPacked #-}
wireGetPacked :: FieldType -> Get (Seq Word32)
wireGetPacked 13 = FieldType -> Get (Seq Word32)
forall a. Wire a => FieldType -> Get (Seq a)
genericPacked 13
wireGetPacked 7 = FieldType -> Get (Seq Word32)
forall a. Wire a => FieldType -> Get (Seq a)
genericPacked 7
wireGetPacked ft :: FieldType
ft = FieldType -> Get (Seq Word32)
forall a. Typeable a => FieldType -> Get a
wireGetErr FieldType
ft
instance Wire Bool where
{-# INLINE wireSize #-}
wireSize :: FieldType -> Bool -> WireSize
wireSize 8 _ = 1
wireSize ft :: FieldType
ft x :: Bool
x = FieldType -> Bool -> WireSize
forall a. Typeable a => FieldType -> a -> WireSize
wireSizeErr FieldType
ft Bool
x
{-# INLINE wirePut #-}
wirePut :: FieldType -> Bool -> Put
wirePut 8 False = Word8 -> Put
putWord8 0
wirePut 8 True = Word8 -> Put
putWord8 1
wirePut ft :: FieldType
ft x :: Bool
x = FieldType -> Bool -> Put
forall a b. Typeable a => FieldType -> a -> PutM b
wirePutErr FieldType
ft Bool
x
{-# INLINE wireGet #-}
wireGet :: FieldType -> Get Bool
wireGet 8 = do
Int32
x <- Get Int32
forall a. (Show a, Integral a, Bits a) => Get a
getVarInt :: Get Int32
case Int32
x of
0 -> Bool -> Get Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
_ -> Bool -> Get Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
wireGet ft :: FieldType
ft = FieldType -> Get Bool
forall a. Typeable a => FieldType -> Get a
wireGetErr FieldType
ft
{-# INLINE wireGetPacked #-}
wireGetPacked :: FieldType -> Get (Seq Bool)
wireGetPacked 8 = FieldType -> Get (Seq Bool)
forall a. Wire a => FieldType -> Get (Seq a)
genericPacked 8
wireGetPacked ft :: FieldType
ft = FieldType -> Get (Seq Bool)
forall a. Typeable a => FieldType -> Get a
wireGetErr FieldType
ft
instance Wire Utf8 where
{-# INLINE wireSize #-}
wireSize :: FieldType -> Utf8 -> WireSize
wireSize 9 x :: Utf8
x = WireSize -> WireSize
prependMessageSize (WireSize -> WireSize) -> WireSize -> WireSize
forall a b. (a -> b) -> a -> b
$ ByteString -> WireSize
BS.length (Utf8 -> ByteString
utf8 Utf8
x)
wireSize ft :: FieldType
ft x :: Utf8
x = FieldType -> Utf8 -> WireSize
forall a. Typeable a => FieldType -> a -> WireSize
wireSizeErr FieldType
ft Utf8
x
{-# INLINE wirePut #-}
wirePut :: FieldType -> Utf8 -> Put
wirePut 9 x :: Utf8
x = WireSize -> Put
forall a. (Integral a, Bits a) => a -> Put
putVarUInt (ByteString -> WireSize
BS.length (Utf8 -> ByteString
utf8 Utf8
x)) Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ByteString -> Put
putLazyByteString (Utf8 -> ByteString
utf8 Utf8
x)
wirePut ft :: FieldType
ft x :: Utf8
x = FieldType -> Utf8 -> Put
forall a b. Typeable a => FieldType -> a -> PutM b
wirePutErr FieldType
ft Utf8
x
{-# INLINE wireGet #-}
wireGet :: FieldType -> Get Utf8
wireGet 9 = Get WireSize
forall a. (Show a, Integral a, Bits a) => Get a
getVarInt Get WireSize -> (WireSize -> Get ByteString) -> Get ByteString
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= WireSize -> Get ByteString
getLazyByteString Get ByteString -> (ByteString -> Get Utf8) -> Get Utf8
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ByteString -> Get Utf8
verifyUtf8
wireGet ft :: FieldType
ft = FieldType -> Get Utf8
forall a. Typeable a => FieldType -> Get a
wireGetErr FieldType
ft
instance Wire ByteString where
{-# INLINE wireSize #-}
wireSize :: FieldType -> ByteString -> WireSize
wireSize 12 x :: ByteString
x = WireSize -> WireSize
prependMessageSize (WireSize -> WireSize) -> WireSize -> WireSize
forall a b. (a -> b) -> a -> b
$ ByteString -> WireSize
BS.length ByteString
x
wireSize ft :: FieldType
ft x :: ByteString
x = FieldType -> ByteString -> WireSize
forall a. Typeable a => FieldType -> a -> WireSize
wireSizeErr FieldType
ft ByteString
x
{-# INLINE wirePut #-}
wirePut :: FieldType -> ByteString -> Put
wirePut 12 x :: ByteString
x = WireSize -> Put
forall a. (Integral a, Bits a) => a -> Put
putVarUInt (ByteString -> WireSize
BS.length ByteString
x) Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ByteString -> Put
putLazyByteString ByteString
x
wirePut ft :: FieldType
ft x :: ByteString
x = FieldType -> ByteString -> Put
forall a b. Typeable a => FieldType -> a -> PutM b
wirePutErr FieldType
ft ByteString
x
{-# INLINE wireGet #-}
wireGet :: FieldType -> Get ByteString
wireGet 12 = Get WireSize
forall a. (Show a, Integral a, Bits a) => Get a
getVarInt Get WireSize -> (WireSize -> Get ByteString) -> Get ByteString
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= WireSize -> Get ByteString
getLazyByteString
wireGet ft :: FieldType
ft = FieldType -> Get ByteString
forall a. Typeable a => FieldType -> Get a
wireGetErr FieldType
ft
instance Wire Int where
{-# INLINE wireSize #-}
wireSize :: FieldType -> Int -> WireSize
wireSize 14 x :: Int
x = Int -> WireSize
size'Int Int
x
wireSize ft :: FieldType
ft x :: Int
x = FieldType -> Int -> WireSize
forall a. Typeable a => FieldType -> a -> WireSize
wireSizeErr FieldType
ft Int
x
{-# INLINE wirePut #-}
wirePut :: FieldType -> Int -> Put
wirePut 14 x :: Int
x = Int -> Put
forall a. (Integral a, Bits a) => a -> Put
putVarSInt Int
x
wirePut ft :: FieldType
ft x :: Int
x = FieldType -> Int -> Put
forall a b. Typeable a => FieldType -> a -> PutM b
wirePutErr FieldType
ft Int
x
{-# INLINE wireGet #-}
wireGet :: FieldType -> Get Int
wireGet 14 = Get Int
forall a. (Show a, Integral a, Bits a) => Get a
getVarInt
wireGet ft :: FieldType
ft = FieldType -> Get Int
forall a. Typeable a => FieldType -> Get a
wireGetErr FieldType
ft
{-# INLINE wireGetPacked #-}
wireGetPacked :: FieldType -> Get (Seq Int)
wireGetPacked 14 = FieldType -> Get (Seq Int)
forall a. Wire a => FieldType -> Get (Seq a)
genericPacked 14
wireGetPacked ft :: FieldType
ft = FieldType -> Get (Seq Int)
forall a. Typeable a => FieldType -> Get a
wireGetErr FieldType
ft
{-# INLINE verifyUtf8 #-}
verifyUtf8 :: ByteString -> Get Utf8
verifyUtf8 :: ByteString -> Get Utf8
verifyUtf8 bs :: ByteString
bs = case ByteString -> Maybe Int
isValidUTF8 ByteString
bs of
Nothing -> Utf8 -> Get Utf8
forall (m :: * -> *) a. Monad m => a -> m a
return (ByteString -> Utf8
Utf8 ByteString
bs)
Just i :: Int
i -> String -> Get Utf8
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (String -> Get Utf8) -> String -> Get Utf8
forall a b. (a -> b) -> a -> b
$ "Text.ProtocolBuffers.WireMessage.verifyUtf8: ByteString is not valid utf8 at position "String -> String -> String
forall a. [a] -> [a] -> [a]
++Int -> String
forall a. Show a => a -> String
show Int
i
{-# INLINE wireGetEnum #-}
wireGetEnum :: (Typeable e, Enum e) => (Int -> Maybe e) -> Get e
wireGetEnum :: (Int -> Maybe e) -> Get e
wireGetEnum toMaybe'Enum :: Int -> Maybe e
toMaybe'Enum = do
Int
int <- FieldType -> Get Int
forall b. Wire b => FieldType -> Get b
wireGet 14
case Int -> Maybe e
toMaybe'Enum Int
int of
Just !e
v -> e -> Get e
forall (m :: * -> *) a. Monad m => a -> m a
return e
v
Nothing -> String -> Get e
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (String
msg String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
int)
where msg :: String
msg = "Bad wireGet of Enum "String -> String -> String
forall a. [a] -> [a] -> [a]
++TypeRep -> String
forall a. Show a => a -> String
show (e -> TypeRep
forall a. Typeable a => a -> TypeRep
typeOf (e
forall a. HasCallStack => a
undefined e -> e -> e
forall a. a -> a -> a
`asTypeOf` (Int -> Maybe e) -> e
forall e. (Int -> Maybe e) -> e
typeHack Int -> Maybe e
toMaybe'Enum))String -> String -> String
forall a. [a] -> [a] -> [a]
++", unrecognized Int value is "
typeHack :: (Int -> Maybe e) -> e
typeHack :: (Int -> Maybe e) -> e
typeHack f :: Int -> Maybe e
f = e -> Maybe e -> e
forall a. a -> Maybe a -> a
fromMaybe e
forall a. HasCallStack => a
undefined (Int -> Maybe e
f Int
forall a. HasCallStack => a
undefined)
size'WireTag :: WireTag -> Int64
size'WireTag :: WireTag -> WireSize
size'WireTag = Word32 -> WireSize
size'Word32 (Word32 -> WireSize) -> (WireTag -> Word32) -> WireTag -> WireSize
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WireTag -> Word32
getWireTag
size'Word32 :: Word32 -> Int64
size'Word32 :: Word32 -> WireSize
size'Word32 b :: Word32
b | Word32
b Word32 -> Word32 -> Bool
forall a. Ord a => a -> a -> Bool
<= 0x7F = 1
| Word32
b Word32 -> Word32 -> Bool
forall a. Ord a => a -> a -> Bool
<= 0x3FFF = 2
| Word32
b Word32 -> Word32 -> Bool
forall a. Ord a => a -> a -> Bool
<= 0x1FFFFF = 3
| Word32
b Word32 -> Word32 -> Bool
forall a. Ord a => a -> a -> Bool
<= 0xFFFFFFF = 4
| Bool
otherwise = 5
size'Int32 :: Int32 -> Int64
size'Int32 :: Int32 -> WireSize
size'Int32 b :: Int32
b | Int32
b Int32 -> Int32 -> Bool
forall a. Ord a => a -> a -> Bool
< 0 = 10
| Int32
b Int32 -> Int32 -> Bool
forall a. Ord a => a -> a -> Bool
<= 0x7F = 1
| Int32
b Int32 -> Int32 -> Bool
forall a. Ord a => a -> a -> Bool
<= 0x3FFF = 2
| Int32
b Int32 -> Int32 -> Bool
forall a. Ord a => a -> a -> Bool
<= 0x1FFFFF = 3
| Int32
b Int32 -> Int32 -> Bool
forall a. Ord a => a -> a -> Bool
<= 0xFFFFFFF = 4
| Bool
otherwise = 5
size'Word64 :: Word64 -> Int64
size'Word64 :: Word64 -> WireSize
size'Word64 b :: Word64
b | Word64
b Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
<= 0x7F = 1
| Word64
b Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
<= 0x3FFF = 2
| Word64
b Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
<= 0x1FFFFF = 3
| Word64
b Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
<= 0xFFFFFFF = 4
| Word64
b Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
<= 0X7FFFFFFFF = 5
| Word64
b Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
<= 0x3FFFFFFFFFF = 6
| Word64
b Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
<= 0x1FFFFFFFFFFFF = 7
| Word64
b Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
<= 0xFFFFFFFFFFFFFF = 8
| Word64
b Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
<= 0x7FFFFFFFFFFFFFFF = 9
| Bool
otherwise = 10
size'Int :: Int -> Int64
size'Int :: Int -> WireSize
size'Int b :: Int
b | Int
b Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< 0 = 10
| Int
b Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= 0x7F = 1
| Int
b Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= 0x3FFF = 2
| Int
b Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= 0x1FFFFF = 3
| Int
b Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= 0xFFFFFFF = 4
| Int
b Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= 0x7FFFFFFF = 5
| Int
b Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= 0x7FFFFFFFF = 5
| Int
b Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= 0x3FFFFFFFFFF = 6
| Int
b Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= 0x1FFFFFFFFFFFF = 7
| Int
b Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= 0xFFFFFFFFFFFFFF = 8
| Bool
otherwise = 9
size'Int64,size'WireSize :: Int64 -> Int64
size'WireSize :: WireSize -> WireSize
size'WireSize = WireSize -> WireSize
size'Int64
size'Int64 :: WireSize -> WireSize
size'Int64 b :: WireSize
b | WireSize
b WireSize -> WireSize -> Bool
forall a. Ord a => a -> a -> Bool
< 0 = 10
| WireSize
b WireSize -> WireSize -> Bool
forall a. Ord a => a -> a -> Bool
<= 0x7F = 1
| WireSize
b WireSize -> WireSize -> Bool
forall a. Ord a => a -> a -> Bool
<= 0x3FFF = 2
| WireSize
b WireSize -> WireSize -> Bool
forall a. Ord a => a -> a -> Bool
<= 0x1FFFFF = 3
| WireSize
b WireSize -> WireSize -> Bool
forall a. Ord a => a -> a -> Bool
<= 0xFFFFFFF = 4
| WireSize
b WireSize -> WireSize -> Bool
forall a. Ord a => a -> a -> Bool
<= 0x7FFFFFFFF = 5
| WireSize
b WireSize -> WireSize -> Bool
forall a. Ord a => a -> a -> Bool
<= 0x3FFFFFFFFFF = 6
| WireSize
b WireSize -> WireSize -> Bool
forall a. Ord a => a -> a -> Bool
<= 0x1FFFFFFFFFFFF = 7
| WireSize
b WireSize -> WireSize -> Bool
forall a. Ord a => a -> a -> Bool
<= 0xFFFFFFFFFFFFFF = 8
| Bool
otherwise = 9
zzEncode32 :: Int32 -> Word32
zzEncode32 :: Int32 -> Word32
zzEncode32 x :: Int32
x = Int32 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Int32
x Int32 -> Int -> Int32
forall a. Bits a => a -> Int -> a
`shiftL` 1) Int32 -> Int32 -> Int32
forall a. Bits a => a -> a -> a
`xor` (Int32
x Int32 -> Int -> Int32
forall a. Bits a => a -> Int -> a
`shiftR` 31))
zzEncode64 :: Int64 -> Word64
zzEncode64 :: WireSize -> Word64
zzEncode64 x :: WireSize
x = WireSize -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((WireSize
x WireSize -> Int -> WireSize
forall a. Bits a => a -> Int -> a
`shiftL` 1) WireSize -> WireSize -> WireSize
forall a. Bits a => a -> a -> a
`xor` (WireSize
x WireSize -> Int -> WireSize
forall a. Bits a => a -> Int -> a
`shiftR` 63))
zzDecode32 :: Word32 -> Int32
zzDecode32 :: Word32 -> Int32
zzDecode32 w :: Word32
w = (Word32 -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32
w Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
`shiftR` 1)) Int32 -> Int32 -> Int32
forall a. Bits a => a -> a -> a
`xor` (Int32 -> Int32
forall a. Num a => a -> a
negate (Word32 -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32
w Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
.&. 1)))
zzDecode64 :: Word64 -> Int64
zzDecode64 :: Word64 -> WireSize
zzDecode64 w :: Word64
w = (Word64 -> WireSize
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64
w Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftR` 1)) WireSize -> WireSize -> WireSize
forall a. Bits a => a -> a -> a
`xor` (WireSize -> WireSize
forall a. Num a => a -> a
negate (Word64 -> WireSize
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64
w Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.&. 1)))
getVarInt :: (Show a, Integral a, Bits a) => Get a
{-# INLINE getVarInt #-}
getVarInt :: Get a
getVarInt = do
a
a <- Get a
forall s. (Num s, Integral s, Bits s) => Get s
decode7unrolled
String -> Get a -> Get a
forall a b. a -> b -> b
trace ("getVarInt: "String -> String -> String
forall a. [a] -> [a] -> [a]
++a -> String
forall a. Show a => a -> String
show a
a) (Get a -> Get a) -> Get a -> Get a
forall a b. (a -> b) -> a -> b
$ a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a
{-# INLINE putVarSInt #-}
putVarSInt :: (Integral a, Bits a) => a -> Put
putVarSInt :: a -> Put
putVarSInt bIn :: a
bIn =
case a -> a -> Ordering
forall a. Ord a => a -> a -> Ordering
compare a
bIn 0 of
LT -> let b :: Int64
b :: WireSize
b = a -> WireSize
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
bIn
len :: Int
len :: Int
len = 10
last'Mask :: WireSize
last'Mask = 1
go :: WireSize -> Int -> Put
go !WireSize
i 1 = Word8 -> Put
putWord8 (WireSize -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (WireSize
i WireSize -> WireSize -> WireSize
forall a. Bits a => a -> a -> a
.&. WireSize
last'Mask))
go !WireSize
i n :: Int
n = Word8 -> Put
putWord8 (WireSize -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (WireSize
i WireSize -> WireSize -> WireSize
forall a. Bits a => a -> a -> a
.&. 0x7F) Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.|. 0x80) Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> WireSize -> Int -> Put
go (WireSize
i WireSize -> Int -> WireSize
forall a. Bits a => a -> Int -> a
`shiftR` 7) (Int -> Int
forall a. Enum a => a -> a
pred Int
n)
in WireSize -> Int -> Put
go WireSize
b Int
len
EQ -> Word8 -> Put
putWord8 0
GT -> a -> Put
forall a. (Integral a, Bits a) => a -> Put
putVarUInt a
bIn
{-# INLINE putVarUInt #-}
putVarUInt :: (Integral a, Bits a) => a -> Put
putVarUInt :: a -> Put
putVarUInt i :: a
i | a
i a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< 0x80 = Word8 -> Put
putWord8 (a -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
i)
| Bool
otherwise = Word8 -> Put
putWord8 (a -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (a
i a -> a -> a
forall a. Bits a => a -> a -> a
.&. 0x7F) Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.|. 0x80) Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> a -> Put
forall a. (Integral a, Bits a) => a -> Put
putVarUInt (a
i a -> Int -> a
forall a. Bits a => a -> Int -> a
`shiftR` 7)
wireGetFromWire :: FieldId -> WireType -> Get ByteString
wireGetFromWire :: FieldId -> WireType -> Get ByteString
wireGetFromWire fi :: FieldId
fi wt :: WireType
wt = WireSize -> Get ByteString
getLazyByteString (WireSize -> Get ByteString) -> Get WireSize -> Get ByteString
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Get WireSize
calcLen where
calcLen :: Get WireSize
calcLen = case WireType
wt of
0 -> Get WireSize
highBitRun
1 -> WireSize -> Get WireSize
forall (m :: * -> *) a. Monad m => a -> m a
return 8
2 -> Get WireSize -> Get WireSize
forall a. Get a -> Get a
lookAhead (Get WireSize -> Get WireSize) -> Get WireSize -> Get WireSize
forall a b. (a -> b) -> a -> b
$ do
WireSize
here <- Get WireSize
bytesRead
WireSize
len <- Get WireSize
forall a. (Show a, Integral a, Bits a) => Get a
getVarInt
WireSize
there <- Get WireSize
bytesRead
WireSize -> Get WireSize
forall (m :: * -> *) a. Monad m => a -> m a
return ((WireSize
thereWireSize -> WireSize -> WireSize
forall a. Num a => a -> a -> a
-WireSize
here)WireSize -> WireSize -> WireSize
forall a. Num a => a -> a -> a
+WireSize
len)
3 -> Get () -> Get WireSize
lenOf (FieldId -> Get ()
skipGroup FieldId
fi)
4 -> String -> Get WireSize
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (String -> Get WireSize) -> String -> Get WireSize
forall a b. (a -> b) -> a -> b
$ "Cannot wireGetFromWire with wireType of STOP_GROUP: "String -> String -> String
forall a. [a] -> [a] -> [a]
++(FieldId, WireType) -> String
forall a. Show a => a -> String
show (FieldId
fi,WireType
wt)
5 -> WireSize -> Get WireSize
forall (m :: * -> *) a. Monad m => a -> m a
return 4
wtf :: WireType
wtf -> String -> Get WireSize
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (String -> Get WireSize) -> String -> Get WireSize
forall a b. (a -> b) -> a -> b
$ "Invalid wire type (expected 0,1,2,3,or 5) found: "String -> String -> String
forall a. [a] -> [a] -> [a]
++(FieldId, WireType) -> String
forall a. Show a => a -> String
show (FieldId
fi,WireType
wtf)
lenOf :: Get () -> Get WireSize
lenOf g :: Get ()
g = do WireSize
here <- Get WireSize
bytesRead
WireSize
there <- Get WireSize -> Get WireSize
forall a. Get a -> Get a
lookAhead (Get ()
g Get () -> Get WireSize -> Get WireSize
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Get WireSize
bytesRead)
String -> Get WireSize -> Get WireSize
forall a b. a -> b -> b
trace (":wireGetFromWire.lenOf: "String -> String -> String
forall a. [a] -> [a] -> [a]
++((FieldId, WireType), (WireSize, WireSize, WireSize)) -> String
forall a. Show a => a -> String
show ((FieldId
fi,WireType
wt),(WireSize
here,WireSize
there,WireSize
thereWireSize -> WireSize -> WireSize
forall a. Num a => a -> a -> a
-WireSize
here))) (Get WireSize -> Get WireSize) -> Get WireSize -> Get WireSize
forall a b. (a -> b) -> a -> b
$ WireSize -> Get WireSize
forall (m :: * -> *) a. Monad m => a -> m a
return (WireSize
thereWireSize -> WireSize -> WireSize
forall a. Num a => a -> a -> a
-WireSize
here)
skipGroup :: FieldId -> Get ()
skipGroup :: FieldId -> Get ()
skipGroup start_fi :: FieldId
start_fi = Get ()
go where
go :: Get ()
go = do
(fieldId :: FieldId
fieldId,wireType :: WireType
wireType) <- (Word32 -> (FieldId, WireType))
-> Get Word32 -> Get (FieldId, WireType)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (WireTag -> (FieldId, WireType)
splitWireTag (WireTag -> (FieldId, WireType))
-> (Word32 -> WireTag) -> Word32 -> (FieldId, WireType)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word32 -> WireTag
WireTag) Get Word32
forall a. (Show a, Integral a, Bits a) => Get a
getVarInt
case WireType
wireType of
0 -> (Word8 -> Bool) -> Get ByteString
spanOf (Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
>=128) Get ByteString -> Get () -> Get ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> WireSize -> Get ()
skip 1 Get () -> Get () -> Get ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Get ()
go
1 -> WireSize -> Get ()
skip 8 Get () -> Get () -> Get ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Get ()
go
2 -> Get WireSize
forall a. (Show a, Integral a, Bits a) => Get a
getVarInt Get WireSize -> (WireSize -> Get ()) -> Get ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= WireSize -> Get ()
skip Get () -> Get () -> Get ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Get ()
go
3 -> FieldId -> Get ()
skipGroup FieldId
fieldId Get () -> Get () -> Get ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Get ()
go
4 | FieldId
start_fi FieldId -> FieldId -> Bool
forall a. Eq a => a -> a -> Bool
/= FieldId
fieldId -> String -> Get ()
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (String -> Get ()) -> String -> Get ()
forall a b. (a -> b) -> a -> b
$ "skipGroup failed, fieldId mismatch bewteen START_GROUP and STOP_GROUP: "String -> String -> String
forall a. [a] -> [a] -> [a]
++(FieldId, (FieldId, WireType)) -> String
forall a. Show a => a -> String
show (FieldId
start_fi,(FieldId
fieldId,WireType
wireType))
| Bool
otherwise -> () -> Get ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
5 -> WireSize -> Get ()
skip 4 Get () -> Get () -> Get ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Get ()
go
wtf :: WireType
wtf -> String -> Get ()
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (String -> Get ()) -> String -> Get ()
forall a b. (a -> b) -> a -> b
$ "Invalid wire type (expected 0,1,2,3,4,or 5) found: "String -> String -> String
forall a. [a] -> [a] -> [a]
++(FieldId, WireType) -> String
forall a. Show a => a -> String
show (FieldId
fieldId,WireType
wtf)
toWireType :: FieldType -> WireType
toWireType :: FieldType -> WireType
toWireType 1 = 1
toWireType 2 = 5
toWireType 3 = 0
toWireType 4 = 0
toWireType 5 = 0
toWireType 6 = 1
toWireType 7 = 5
toWireType 8 = 0
toWireType 9 = 2
toWireType 10 = 3
toWireType 11 = 2
toWireType 12 = 2
toWireType 13 = 0
toWireType 14 = 0
toWireType 15 = 5
toWireType 16 = 1
toWireType 17 = 0
toWireType 18 = 0
toWireType x :: FieldType
x = String -> WireType
forall a. HasCallStack => String -> a
error (String -> WireType) -> String -> WireType
forall a b. (a -> b) -> a -> b
$ "Text.ProcolBuffers.Basic.toWireType: Bad FieldType: "String -> String -> String
forall a. [a] -> [a] -> [a]
++FieldType -> String
forall a. Show a => a -> String
show FieldType
x