{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module Proto3.Wire.Encode
(
MessageBuilder
, reverseMessageBuilder
, vectorMessageBuilder
, messageLength
, toLazyByteString
, unsafeFromLazyByteString
, int32
, int64
, uint32
, uint64
, sint32
, sint64
, fixed32
, fixed64
, sfixed32
, sfixed64
, float
, double
, enum
, bool
, bytes
, string
, text
, shortText
, byteString
, lazyByteString
, shortByteString
, embedded
, packedVarints
, packedVarintsV
, packedBoolsV
, packedFixed32
, packedFixed32V
, packedFixed64
, packedFixed64V
, packedFloats
, packedFloatsV
, packedDoubles
, packedDoublesV
, zigZagEncode
) where
import Data.Bits ( (.|.), shiftL, shiftR, xor,
FiniteBits, finiteBitSize )
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as BL
import qualified Data.ByteString.Short as BS
import Data.Coerce ( coerce )
import Data.Int ( Int32, Int64 )
import qualified Data.Text.Lazy as Text.Lazy
import qualified Data.Text.Short as Text.Short
import Data.Vector.Generic ( Vector )
import Data.Word ( Word8, Word32, Word64 )
import GHC.TypeLits ( KnownNat, Nat, type (+) )
import Parameterized.Data.Semigroup ( PNullary, PSemigroup(..),
(&<>) )
import Parameterized.Data.Monoid ( PMEmpty(..) )
import qualified Proto3.Wire.Reverse as RB
import qualified Proto3.Wire.Reverse.Prim as Prim
import Proto3.Wire.Class
import Proto3.Wire.Types
zigZagEncode :: (Num a, FiniteBits a) => a -> a
zigZagEncode :: forall a. (Num a, FiniteBits a) => a -> a
zigZagEncode a
i = (a
i a -> Int -> a
forall a. Bits a => a -> Int -> a
`shiftL` Int
1) a -> a -> a
forall a. Bits a => a -> a -> a
`xor` (a
i a -> Int -> a
forall a. Bits a => a -> Int -> a
`shiftR` Int
n)
where n :: Int
n = a -> Int
forall b. FiniteBits b => b -> Int
finiteBitSize a
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
{-# INLINE zigZagEncode #-}
newtype MessageBuilder = MessageBuilder { MessageBuilder -> BuildR
unMessageBuilder :: RB.BuildR }
deriving (Semigroup MessageBuilder
MessageBuilder
Semigroup MessageBuilder =>
MessageBuilder
-> (MessageBuilder -> MessageBuilder -> MessageBuilder)
-> ([MessageBuilder] -> MessageBuilder)
-> Monoid MessageBuilder
[MessageBuilder] -> MessageBuilder
MessageBuilder -> MessageBuilder -> MessageBuilder
forall a.
Semigroup a =>
a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
$cmempty :: MessageBuilder
mempty :: MessageBuilder
$cmappend :: MessageBuilder -> MessageBuilder -> MessageBuilder
mappend :: MessageBuilder -> MessageBuilder -> MessageBuilder
$cmconcat :: [MessageBuilder] -> MessageBuilder
mconcat :: [MessageBuilder] -> MessageBuilder
Monoid, NonEmpty MessageBuilder -> MessageBuilder
MessageBuilder -> MessageBuilder -> MessageBuilder
(MessageBuilder -> MessageBuilder -> MessageBuilder)
-> (NonEmpty MessageBuilder -> MessageBuilder)
-> (forall b. Integral b => b -> MessageBuilder -> MessageBuilder)
-> Semigroup MessageBuilder
forall b. Integral b => b -> MessageBuilder -> MessageBuilder
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
$c<> :: MessageBuilder -> MessageBuilder -> MessageBuilder
<> :: MessageBuilder -> MessageBuilder -> MessageBuilder
$csconcat :: NonEmpty MessageBuilder -> MessageBuilder
sconcat :: NonEmpty MessageBuilder -> MessageBuilder
$cstimes :: forall b. Integral b => b -> MessageBuilder -> MessageBuilder
stimes :: forall b. Integral b => b -> MessageBuilder -> MessageBuilder
Semigroup)
instance Show MessageBuilder where
showsPrec :: Int -> MessageBuilder -> ShowS
showsPrec Int
prec MessageBuilder
builder =
Bool -> ShowS -> ShowS
showParen (Int
prec Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10)
(String -> ShowS
showString String
"Proto3.Wire.Encode.unsafeFromLazyByteString " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ShowS
forall a. Show a => a -> ShowS
shows ByteString
bytes')
where
bytes' :: ByteString
bytes' = MessageBuilder -> ByteString
toLazyByteString MessageBuilder
builder
reverseMessageBuilder :: MessageBuilder -> RB.BuildR
reverseMessageBuilder :: MessageBuilder -> BuildR
reverseMessageBuilder = MessageBuilder -> BuildR
unMessageBuilder
etaMessageBuilder :: forall a . (a -> MessageBuilder) -> a -> MessageBuilder
etaMessageBuilder :: forall a. (a -> MessageBuilder) -> a -> MessageBuilder
etaMessageBuilder = ((a -> BuildR) -> a -> BuildR)
-> (a -> MessageBuilder) -> a -> MessageBuilder
forall a b. Coercible a b => a -> b
coerce (forall a. (a -> BuildR) -> a -> BuildR
RB.etaBuildR @a)
vectorMessageBuilder ::
forall v a . Vector v a => (a -> MessageBuilder) -> v a -> MessageBuilder
vectorMessageBuilder :: forall (v :: * -> *) a.
Vector v a =>
(a -> MessageBuilder) -> v a -> MessageBuilder
vectorMessageBuilder = ((a -> BuildR) -> v a -> BuildR)
-> (a -> MessageBuilder) -> v a -> MessageBuilder
forall a b. Coercible a b => a -> b
coerce (forall (v :: * -> *) a.
Vector v a =>
(a -> BuildR) -> v a -> BuildR
RB.vectorBuildR @v @a)
messageLength :: MessageBuilder -> Word
messageLength :: MessageBuilder -> Word
messageLength = Int -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Word) -> (MessageBuilder -> Int) -> MessageBuilder -> Word
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int, ByteString) -> Int
forall a b. (a, b) -> a
fst ((Int, ByteString) -> Int)
-> (MessageBuilder -> (Int, ByteString)) -> MessageBuilder -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BuildR -> (Int, ByteString)
RB.runBuildR (BuildR -> (Int, ByteString))
-> (MessageBuilder -> BuildR)
-> MessageBuilder
-> (Int, ByteString)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MessageBuilder -> BuildR
unMessageBuilder
toLazyByteString :: MessageBuilder -> BL.ByteString
toLazyByteString :: MessageBuilder -> ByteString
toLazyByteString = BuildR -> ByteString
RB.toLazyByteString (BuildR -> ByteString)
-> (MessageBuilder -> BuildR) -> MessageBuilder -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MessageBuilder -> BuildR
unMessageBuilder
unsafeFromLazyByteString :: BL.ByteString -> MessageBuilder
unsafeFromLazyByteString :: ByteString -> MessageBuilder
unsafeFromLazyByteString ByteString
bytes' =
MessageBuilder { unMessageBuilder :: BuildR
unMessageBuilder = ByteString -> BuildR
RB.lazyByteString ByteString
bytes' }
newtype MessageBoundedPrim w
= MessageBoundedPrim { forall (w :: Nat). MessageBoundedPrim w -> BoundedPrim w
unMessageBoundedPrim :: Prim.BoundedPrim w }
type instance PNullary MessageBoundedPrim width = MessageBoundedPrim width
instance (w1 + w2) ~ w3 =>
PSemigroup MessageBoundedPrim w1 w2 w3
where
pmappend :: PNullary MessageBoundedPrim w1
-> PNullary MessageBoundedPrim w2 -> PNullary MessageBoundedPrim w3
pmappend = (BoundedPrim Any -> BoundedPrim Any -> BoundedPrim (Any + Any))
-> MessageBoundedPrim w1
-> MessageBoundedPrim w2
-> MessageBoundedPrim w3
forall a b. Coercible a b => a -> b
coerce (forall k (n :: k -> *) (t :: k) (u :: k) (v :: k).
PSemigroup n t u v =>
PNullary n t -> PNullary n u -> PNullary n v
pmappend @Nat @Prim.BoundedPrim)
{-# INLINE CONLIKE pmappend #-}
instance Prim.AssocPlusNat MessageBoundedPrim u v w
where
assocLPlusNat :: Proxy# '(u, v, w)
-> PNullary MessageBoundedPrim (u + (v + w))
-> PNullary MessageBoundedPrim ((u + v) + w)
assocLPlusNat = \Proxy# '(u, v, w)
p -> (BoundedPrim (u + (v + w)) -> BoundedPrim ((u + v) + w))
-> MessageBoundedPrim (u + (v + w))
-> MessageBoundedPrim ((u + v) + w)
forall a b. Coercible a b => a -> b
coerce (forall (n :: Nat -> *) (u :: Nat) (v :: Nat) (w :: Nat).
AssocPlusNat n u v w =>
Proxy# '(u, v, w)
-> PNullary n (u + (v + w)) -> PNullary n ((u + v) + w)
Prim.assocLPlusNat @Prim.BoundedPrim Proxy# '(u, v, w)
p)
{-# INLINE CONLIKE assocLPlusNat #-}
assocRPlusNat :: Proxy# '(u, v, w)
-> PNullary MessageBoundedPrim ((u + v) + w)
-> PNullary MessageBoundedPrim (u + (v + w))
assocRPlusNat = \Proxy# '(u, v, w)
p -> (BoundedPrim ((u + v) + w) -> BoundedPrim (u + (v + w)))
-> MessageBoundedPrim ((u + v) + w)
-> MessageBoundedPrim (u + (v + w))
forall a b. Coercible a b => a -> b
coerce (forall (n :: Nat -> *) (u :: Nat) (v :: Nat) (w :: Nat).
AssocPlusNat n u v w =>
Proxy# '(u, v, w)
-> PNullary n ((u + v) + w) -> PNullary n (u + (v + w))
Prim.assocRPlusNat @Prim.BoundedPrim Proxy# '(u, v, w)
p)
{-# INLINE CONLIKE assocRPlusNat #-}
instance Prim.CommPlusNat MessageBoundedPrim u v
where
commPlusNat :: Proxy# '(u, v)
-> PNullary MessageBoundedPrim (u + v)
-> PNullary MessageBoundedPrim (v + u)
commPlusNat = \Proxy# '(u, v)
p -> (BoundedPrim (u + v) -> BoundedPrim (v + u))
-> MessageBoundedPrim (u + v) -> MessageBoundedPrim (v + u)
forall a b. Coercible a b => a -> b
coerce (forall (n :: Nat -> *) (u :: Nat) (v :: Nat).
CommPlusNat n u v =>
Proxy# '(u, v) -> PNullary n (u + v) -> PNullary n (v + u)
Prim.commPlusNat @Prim.BoundedPrim Proxy# '(u, v)
p)
{-# INLINE CONLIKE commPlusNat #-}
instance PMEmpty MessageBoundedPrim 0
where
pmempty :: PNullary MessageBoundedPrim 0
pmempty = BoundedPrim 0 -> MessageBoundedPrim 0
forall a b. Coercible a b => a -> b
coerce (forall k (n :: k -> *) (id :: k). PMEmpty n id => PNullary n id
pmempty @Nat @Prim.BoundedPrim)
{-# INLINE CONLIKE pmempty #-}
instance Prim.Max u v ~ w =>
Prim.PChoose MessageBoundedPrim u v w
where
pbool :: PNullary MessageBoundedPrim u
-> PNullary MessageBoundedPrim v
-> Bool
-> PNullary MessageBoundedPrim w
pbool = (BoundedPrim Any
-> BoundedPrim Any
-> Bool
-> BoundedPrim
(If (OrdCond (CmpNat Any Any) 'True 'True 'False) Any Any))
-> MessageBoundedPrim u
-> MessageBoundedPrim v
-> Bool
-> MessageBoundedPrim w
forall a b. Coercible a b => a -> b
coerce (forall {k} (n :: k -> *) (f :: k) (t :: k) (w :: k).
PChoose n f t w =>
PNullary n f -> PNullary n t -> Bool -> PNullary n w
forall (n :: Nat -> *) (f :: Nat) (t :: Nat) (w :: Nat).
PChoose n f t w =>
PNullary n f -> PNullary n t -> Bool -> PNullary n w
Prim.pbool @Prim.BoundedPrim)
{-# INLINE CONLIKE pbool #-}
instance Prim.AssocMaxNat MessageBoundedPrim u v w
where
assocLMaxNat :: Proxy# '(u, v, w)
-> PNullary MessageBoundedPrim (Max u (Max v w))
-> PNullary MessageBoundedPrim (Max (Max u v) w)
assocLMaxNat = \Proxy# '(u, v, w)
p -> (BoundedPrim
(If
(OrdCond
(CmpNat (If (OrdCond (CmpNat w v) 'True 'True 'False) v w) u)
'True
'True
'False)
u
(If (OrdCond (CmpNat w v) 'True 'True 'False) v w))
-> BoundedPrim
(If
(OrdCond
(CmpNat w (If (OrdCond (CmpNat v u) 'True 'True 'False) u v))
'True
'True
'False)
(If (OrdCond (CmpNat v u) 'True 'True 'False) u v)
w))
-> MessageBoundedPrim
(If
(OrdCond
(CmpNat (If (OrdCond (CmpNat w v) 'True 'True 'False) v w) u)
'True
'True
'False)
u
(If (OrdCond (CmpNat w v) 'True 'True 'False) v w))
-> MessageBoundedPrim
(If
(OrdCond
(CmpNat w (If (OrdCond (CmpNat v u) 'True 'True 'False) u v))
'True
'True
'False)
(If (OrdCond (CmpNat v u) 'True 'True 'False) u v)
w)
forall a b. Coercible a b => a -> b
coerce (forall {k} (n :: k -> *) (u :: k) (v :: k) (w :: k).
AssocMaxNat n u v w =>
Proxy# '(u, v, w)
-> PNullary n (Max u (Max v w)) -> PNullary n (Max (Max u v) w)
forall (n :: Nat -> *) (u :: Nat) (v :: Nat) (w :: Nat).
AssocMaxNat n u v w =>
Proxy# '(u, v, w)
-> PNullary n (Max u (Max v w)) -> PNullary n (Max (Max u v) w)
Prim.assocLMaxNat @Prim.BoundedPrim Proxy# '(u, v, w)
p)
{-# INLINE CONLIKE assocLMaxNat #-}
assocRMaxNat :: Proxy# '(u, v, w)
-> PNullary MessageBoundedPrim (Max (Max u v) w)
-> PNullary MessageBoundedPrim (Max u (Max v w))
assocRMaxNat = \Proxy# '(u, v, w)
p -> (BoundedPrim
(If
(OrdCond
(CmpNat w (If (OrdCond (CmpNat v u) 'True 'True 'False) u v))
'True
'True
'False)
(If (OrdCond (CmpNat v u) 'True 'True 'False) u v)
w)
-> BoundedPrim
(If
(OrdCond
(CmpNat (If (OrdCond (CmpNat w v) 'True 'True 'False) v w) u)
'True
'True
'False)
u
(If (OrdCond (CmpNat w v) 'True 'True 'False) v w)))
-> MessageBoundedPrim
(If
(OrdCond
(CmpNat w (If (OrdCond (CmpNat v u) 'True 'True 'False) u v))
'True
'True
'False)
(If (OrdCond (CmpNat v u) 'True 'True 'False) u v)
w)
-> MessageBoundedPrim
(If
(OrdCond
(CmpNat (If (OrdCond (CmpNat w v) 'True 'True 'False) v w) u)
'True
'True
'False)
u
(If (OrdCond (CmpNat w v) 'True 'True 'False) v w))
forall a b. Coercible a b => a -> b
coerce (forall {k} (n :: k -> *) (u :: k) (v :: k) (w :: k).
AssocMaxNat n u v w =>
Proxy# '(u, v, w)
-> PNullary n (Max (Max u v) w) -> PNullary n (Max u (Max v w))
forall (n :: Nat -> *) (u :: Nat) (v :: Nat) (w :: Nat).
AssocMaxNat n u v w =>
Proxy# '(u, v, w)
-> PNullary n (Max (Max u v) w) -> PNullary n (Max u (Max v w))
Prim.assocRMaxNat @Prim.BoundedPrim Proxy# '(u, v, w)
p)
{-# INLINE CONLIKE assocRMaxNat #-}
instance Prim.CommMaxNat MessageBoundedPrim u v
where
commMaxNat :: Proxy# '(u, v)
-> PNullary MessageBoundedPrim (Max u v)
-> PNullary MessageBoundedPrim (Max v u)
commMaxNat = \Proxy# '(u, v)
p -> (BoundedPrim (If (OrdCond (CmpNat v u) 'True 'True 'False) u v)
-> BoundedPrim (If (OrdCond (CmpNat u v) 'True 'True 'False) v u))
-> MessageBoundedPrim
(If (OrdCond (CmpNat v u) 'True 'True 'False) u v)
-> MessageBoundedPrim
(If (OrdCond (CmpNat u v) 'True 'True 'False) v u)
forall a b. Coercible a b => a -> b
coerce (forall {k} (n :: k -> *) (u :: k) (v :: k).
CommMaxNat n u v =>
Proxy# '(u, v) -> PNullary n (Max u v) -> PNullary n (Max v u)
forall (n :: Nat -> *) (u :: Nat) (v :: Nat).
CommMaxNat n u v =>
Proxy# '(u, v) -> PNullary n (Max u v) -> PNullary n (Max v u)
Prim.commMaxNat @Prim.BoundedPrim Proxy# '(u, v)
p)
{-# INLINE CONLIKE commMaxNat #-}
liftBoundedPrim :: KnownNat w => MessageBoundedPrim w -> MessageBuilder
liftBoundedPrim :: forall (w :: Nat).
KnownNat w =>
MessageBoundedPrim w -> MessageBuilder
liftBoundedPrim (MessageBoundedPrim BoundedPrim w
p) = BuildR -> MessageBuilder
MessageBuilder (BoundedPrim w -> BuildR
forall (w :: Nat). KnownNat w => BoundedPrim w -> BuildR
Prim.liftBoundedPrim BoundedPrim w
p)
{-# INLINE liftBoundedPrim #-}
base128Varint32 :: Word32 -> MessageBoundedPrim 5
base128Varint32 :: Word32 -> MessageBoundedPrim 5
base128Varint32 = BoundedPrim 5 -> MessageBoundedPrim 5
forall (w :: Nat). BoundedPrim w -> MessageBoundedPrim w
MessageBoundedPrim (BoundedPrim 5 -> MessageBoundedPrim 5)
-> (Word32 -> BoundedPrim 5) -> Word32 -> MessageBoundedPrim 5
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word32 -> BoundedPrim 5
Prim.word32Base128LEVar
{-# INLINE base128Varint32 #-}
base128Varint64 :: Word64 -> MessageBoundedPrim 10
base128Varint64 :: Word64 -> MessageBoundedPrim 10
base128Varint64 = BoundedPrim 10 -> MessageBoundedPrim 10
forall (w :: Nat). BoundedPrim w -> MessageBoundedPrim w
MessageBoundedPrim (BoundedPrim 10 -> MessageBoundedPrim 10)
-> (Word64 -> BoundedPrim 10) -> Word64 -> MessageBoundedPrim 10
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> BoundedPrim 10
Prim.word64Base128LEVar
{-# INLINE base128Varint64 #-}
base128Varint64_inline :: Word64 -> MessageBoundedPrim 10
base128Varint64_inline :: Word64 -> MessageBoundedPrim 10
base128Varint64_inline = BoundedPrim 10 -> MessageBoundedPrim 10
forall (w :: Nat). BoundedPrim w -> MessageBoundedPrim w
MessageBoundedPrim (BoundedPrim 10 -> MessageBoundedPrim 10)
-> (Word64 -> BoundedPrim 10) -> Word64 -> MessageBoundedPrim 10
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> BoundedPrim 10
Prim.word64Base128LEVar_inline
{-# INLINE base128Varint64_inline #-}
wireType :: WireType -> Word8
wireType :: WireType -> Word8
wireType WireType
Varint = Word8
0
wireType WireType
Fixed32 = Word8
5
wireType WireType
Fixed64 = Word8
1
wireType WireType
LengthDelimited = Word8
2
fieldHeader :: FieldNumber -> WireType -> MessageBoundedPrim 10
= \FieldNumber
num WireType
wt -> Word64 -> MessageBoundedPrim 10
base128Varint64_inline
((FieldNumber -> Word64
getFieldNumber FieldNumber
num Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftL` Int
3) Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.|. Word8 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (WireType -> Word8
wireType WireType
wt))
{-# INLINE fieldHeader #-}
int32 :: FieldNumber -> Int32 -> MessageBuilder
int32 :: FieldNumber -> Int32 -> MessageBuilder
int32 = \FieldNumber
num Int32
i -> MessageBoundedPrim 20 -> MessageBuilder
forall (w :: Nat).
KnownNat w =>
MessageBoundedPrim w -> MessageBuilder
liftBoundedPrim (MessageBoundedPrim 20 -> MessageBuilder)
-> MessageBoundedPrim 20 -> MessageBuilder
forall a b. (a -> b) -> a -> b
$
FieldNumber -> WireType -> MessageBoundedPrim 10
fieldHeader FieldNumber
num WireType
Varint PNullary MessageBoundedPrim 10
-> PNullary MessageBoundedPrim 10 -> PNullary MessageBoundedPrim 20
forall k (n :: k -> *) (t :: k) (u :: k) (v :: k).
PSemigroup n t u v =>
PNullary n t -> PNullary n u -> PNullary n v
&<> Word64 -> MessageBoundedPrim 10
base128Varint64 (Int32 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int32
i)
{-# INLINE int32 #-}
int64 :: FieldNumber -> Int64 -> MessageBuilder
int64 :: FieldNumber -> Int64 -> MessageBuilder
int64 = \FieldNumber
num Int64
i -> MessageBoundedPrim 20 -> MessageBuilder
forall (w :: Nat).
KnownNat w =>
MessageBoundedPrim w -> MessageBuilder
liftBoundedPrim (MessageBoundedPrim 20 -> MessageBuilder)
-> MessageBoundedPrim 20 -> MessageBuilder
forall a b. (a -> b) -> a -> b
$
FieldNumber -> WireType -> MessageBoundedPrim 10
fieldHeader FieldNumber
num WireType
Varint PNullary MessageBoundedPrim 10
-> PNullary MessageBoundedPrim 10 -> PNullary MessageBoundedPrim 20
forall k (n :: k -> *) (t :: k) (u :: k) (v :: k).
PSemigroup n t u v =>
PNullary n t -> PNullary n u -> PNullary n v
&<> Word64 -> MessageBoundedPrim 10
base128Varint64 (Int64 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int64
i)
{-# INLINE int64 #-}
uint32 :: FieldNumber -> Word32 -> MessageBuilder
uint32 :: FieldNumber -> Word32 -> MessageBuilder
uint32 = \FieldNumber
num Word32
i -> MessageBoundedPrim 15 -> MessageBuilder
forall (w :: Nat).
KnownNat w =>
MessageBoundedPrim w -> MessageBuilder
liftBoundedPrim (MessageBoundedPrim 15 -> MessageBuilder)
-> MessageBoundedPrim 15 -> MessageBuilder
forall a b. (a -> b) -> a -> b
$
FieldNumber -> WireType -> MessageBoundedPrim 10
fieldHeader FieldNumber
num WireType
Varint PNullary MessageBoundedPrim 10
-> PNullary MessageBoundedPrim 5 -> PNullary MessageBoundedPrim 15
forall k (n :: k -> *) (t :: k) (u :: k) (v :: k).
PSemigroup n t u v =>
PNullary n t -> PNullary n u -> PNullary n v
&<> Word32 -> MessageBoundedPrim 5
base128Varint32 Word32
i
{-# INLINE uint32 #-}
uint64 :: FieldNumber -> Word64 -> MessageBuilder
uint64 :: FieldNumber -> Word64 -> MessageBuilder
uint64 = \FieldNumber
num Word64
i -> MessageBoundedPrim 20 -> MessageBuilder
forall (w :: Nat).
KnownNat w =>
MessageBoundedPrim w -> MessageBuilder
liftBoundedPrim (MessageBoundedPrim 20 -> MessageBuilder)
-> MessageBoundedPrim 20 -> MessageBuilder
forall a b. (a -> b) -> a -> b
$
FieldNumber -> WireType -> MessageBoundedPrim 10
fieldHeader FieldNumber
num WireType
Varint PNullary MessageBoundedPrim 10
-> PNullary MessageBoundedPrim 10 -> PNullary MessageBoundedPrim 20
forall k (n :: k -> *) (t :: k) (u :: k) (v :: k).
PSemigroup n t u v =>
PNullary n t -> PNullary n u -> PNullary n v
&<> Word64 -> MessageBoundedPrim 10
base128Varint64 Word64
i
{-# INLINE uint64 #-}
sint32 :: FieldNumber -> Int32 -> MessageBuilder
sint32 :: FieldNumber -> Int32 -> MessageBuilder
sint32 = \FieldNumber
num Int32
i ->
FieldNumber -> Word32 -> MessageBuilder
uint32 FieldNumber
num (Int32 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32 -> Int32
forall a. (Num a, FiniteBits a) => a -> a
zigZagEncode Int32
i))
{-# INLINE sint32 #-}
sint64 :: FieldNumber -> Int64 -> MessageBuilder
sint64 :: FieldNumber -> Int64 -> MessageBuilder
sint64 = \FieldNumber
num Int64
i ->
FieldNumber -> Word64 -> MessageBuilder
uint64 FieldNumber
num (Int64 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64 -> Int64
forall a. (Num a, FiniteBits a) => a -> a
zigZagEncode Int64
i))
{-# INLINE sint64 #-}
fixed32 :: FieldNumber -> Word32 -> MessageBuilder
fixed32 :: FieldNumber -> Word32 -> MessageBuilder
fixed32 = \FieldNumber
num Word32
i -> MessageBoundedPrim 14 -> MessageBuilder
forall (w :: Nat).
KnownNat w =>
MessageBoundedPrim w -> MessageBuilder
liftBoundedPrim (MessageBoundedPrim 14 -> MessageBuilder)
-> MessageBoundedPrim 14 -> MessageBuilder
forall a b. (a -> b) -> a -> b
$
FieldNumber -> WireType -> MessageBoundedPrim 10
fieldHeader FieldNumber
num WireType
Fixed32 PNullary MessageBoundedPrim 10
-> PNullary MessageBoundedPrim 4 -> PNullary MessageBoundedPrim 14
forall k (n :: k -> *) (t :: k) (u :: k) (v :: k).
PSemigroup n t u v =>
PNullary n t -> PNullary n u -> PNullary n v
&<>
BoundedPrim 4 -> MessageBoundedPrim 4
forall (w :: Nat). BoundedPrim w -> MessageBoundedPrim w
MessageBoundedPrim (FixedPrim 4 -> BoundedPrim 4
forall (w :: Nat). KnownNat w => FixedPrim w -> BoundedPrim w
Prim.liftFixedPrim (Word32 -> FixedPrim 4
Prim.word32LE Word32
i))
{-# INLINE fixed32 #-}
fixed64 :: FieldNumber -> Word64 -> MessageBuilder
fixed64 :: FieldNumber -> Word64 -> MessageBuilder
fixed64 = \FieldNumber
num Word64
i -> MessageBoundedPrim 18 -> MessageBuilder
forall (w :: Nat).
KnownNat w =>
MessageBoundedPrim w -> MessageBuilder
liftBoundedPrim (MessageBoundedPrim 18 -> MessageBuilder)
-> MessageBoundedPrim 18 -> MessageBuilder
forall a b. (a -> b) -> a -> b
$
FieldNumber -> WireType -> MessageBoundedPrim 10
fieldHeader FieldNumber
num WireType
Fixed64 PNullary MessageBoundedPrim 10
-> PNullary MessageBoundedPrim 8 -> PNullary MessageBoundedPrim 18
forall k (n :: k -> *) (t :: k) (u :: k) (v :: k).
PSemigroup n t u v =>
PNullary n t -> PNullary n u -> PNullary n v
&<>
BoundedPrim 8 -> MessageBoundedPrim 8
forall (w :: Nat). BoundedPrim w -> MessageBoundedPrim w
MessageBoundedPrim (FixedPrim 8 -> BoundedPrim 8
forall (w :: Nat). KnownNat w => FixedPrim w -> BoundedPrim w
Prim.liftFixedPrim (Word64 -> FixedPrim 8
Prim.word64LE Word64
i))
{-# INLINE fixed64 #-}
sfixed32 :: FieldNumber -> Int32 -> MessageBuilder
sfixed32 :: FieldNumber -> Int32 -> MessageBuilder
sfixed32 = \FieldNumber
num Int32
i -> MessageBoundedPrim 14 -> MessageBuilder
forall (w :: Nat).
KnownNat w =>
MessageBoundedPrim w -> MessageBuilder
liftBoundedPrim (MessageBoundedPrim 14 -> MessageBuilder)
-> MessageBoundedPrim 14 -> MessageBuilder
forall a b. (a -> b) -> a -> b
$
FieldNumber -> WireType -> MessageBoundedPrim 10
fieldHeader FieldNumber
num WireType
Fixed32 PNullary MessageBoundedPrim 10
-> PNullary MessageBoundedPrim 4 -> PNullary MessageBoundedPrim 14
forall k (n :: k -> *) (t :: k) (u :: k) (v :: k).
PSemigroup n t u v =>
PNullary n t -> PNullary n u -> PNullary n v
&<>
BoundedPrim 4 -> MessageBoundedPrim 4
forall (w :: Nat). BoundedPrim w -> MessageBoundedPrim w
MessageBoundedPrim (FixedPrim 4 -> BoundedPrim 4
forall (w :: Nat). KnownNat w => FixedPrim w -> BoundedPrim w
Prim.liftFixedPrim (Int32 -> FixedPrim 4
Prim.int32LE Int32
i))
{-# INLINE sfixed32 #-}
sfixed64 :: FieldNumber -> Int64 -> MessageBuilder
sfixed64 :: FieldNumber -> Int64 -> MessageBuilder
sfixed64 = \FieldNumber
num Int64
i -> MessageBoundedPrim 18 -> MessageBuilder
forall (w :: Nat).
KnownNat w =>
MessageBoundedPrim w -> MessageBuilder
liftBoundedPrim (MessageBoundedPrim 18 -> MessageBuilder)
-> MessageBoundedPrim 18 -> MessageBuilder
forall a b. (a -> b) -> a -> b
$
FieldNumber -> WireType -> MessageBoundedPrim 10
fieldHeader FieldNumber
num WireType
Fixed64 PNullary MessageBoundedPrim 10
-> PNullary MessageBoundedPrim 8 -> PNullary MessageBoundedPrim 18
forall k (n :: k -> *) (t :: k) (u :: k) (v :: k).
PSemigroup n t u v =>
PNullary n t -> PNullary n u -> PNullary n v
&<>
BoundedPrim 8 -> MessageBoundedPrim 8
forall (w :: Nat). BoundedPrim w -> MessageBoundedPrim w
MessageBoundedPrim (FixedPrim 8 -> BoundedPrim 8
forall (w :: Nat). KnownNat w => FixedPrim w -> BoundedPrim w
Prim.liftFixedPrim (Int64 -> FixedPrim 8
Prim.int64LE Int64
i))
{-# INLINE sfixed64 #-}
float :: FieldNumber -> Float -> MessageBuilder
float :: FieldNumber -> Float -> MessageBuilder
float = \FieldNumber
num Float
f -> MessageBoundedPrim 14 -> MessageBuilder
forall (w :: Nat).
KnownNat w =>
MessageBoundedPrim w -> MessageBuilder
liftBoundedPrim (MessageBoundedPrim 14 -> MessageBuilder)
-> MessageBoundedPrim 14 -> MessageBuilder
forall a b. (a -> b) -> a -> b
$
FieldNumber -> WireType -> MessageBoundedPrim 10
fieldHeader FieldNumber
num WireType
Fixed32 PNullary MessageBoundedPrim 10
-> PNullary MessageBoundedPrim 4 -> PNullary MessageBoundedPrim 14
forall k (n :: k -> *) (t :: k) (u :: k) (v :: k).
PSemigroup n t u v =>
PNullary n t -> PNullary n u -> PNullary n v
&<>
BoundedPrim 4 -> MessageBoundedPrim 4
forall (w :: Nat). BoundedPrim w -> MessageBoundedPrim w
MessageBoundedPrim (FixedPrim 4 -> BoundedPrim 4
forall (w :: Nat). KnownNat w => FixedPrim w -> BoundedPrim w
Prim.liftFixedPrim (Float -> FixedPrim 4
Prim.floatLE Float
f))
{-# INLINE float #-}
double :: FieldNumber -> Double -> MessageBuilder
double :: FieldNumber -> Double -> MessageBuilder
double = \FieldNumber
num Double
d -> MessageBoundedPrim 18 -> MessageBuilder
forall (w :: Nat).
KnownNat w =>
MessageBoundedPrim w -> MessageBuilder
liftBoundedPrim (MessageBoundedPrim 18 -> MessageBuilder)
-> MessageBoundedPrim 18 -> MessageBuilder
forall a b. (a -> b) -> a -> b
$
FieldNumber -> WireType -> MessageBoundedPrim 10
fieldHeader FieldNumber
num WireType
Fixed64 PNullary MessageBoundedPrim 10
-> PNullary MessageBoundedPrim 8 -> PNullary MessageBoundedPrim 18
forall k (n :: k -> *) (t :: k) (u :: k) (v :: k).
PSemigroup n t u v =>
PNullary n t -> PNullary n u -> PNullary n v
&<>
BoundedPrim 8 -> MessageBoundedPrim 8
forall (w :: Nat). BoundedPrim w -> MessageBoundedPrim w
MessageBoundedPrim (FixedPrim 8 -> BoundedPrim 8
forall (w :: Nat). KnownNat w => FixedPrim w -> BoundedPrim w
Prim.liftFixedPrim (Double -> FixedPrim 8
Prim.doubleLE Double
d))
{-# INLINE double #-}
enum :: ProtoEnum e => FieldNumber -> e -> MessageBuilder
enum :: forall e. ProtoEnum e => FieldNumber -> e -> MessageBuilder
enum = \FieldNumber
num e
e -> MessageBoundedPrim 15 -> MessageBuilder
forall (w :: Nat).
KnownNat w =>
MessageBoundedPrim w -> MessageBuilder
liftBoundedPrim (MessageBoundedPrim 15 -> MessageBuilder)
-> MessageBoundedPrim 15 -> MessageBuilder
forall a b. (a -> b) -> a -> b
$
FieldNumber -> WireType -> MessageBoundedPrim 10
fieldHeader FieldNumber
num WireType
Varint PNullary MessageBoundedPrim 10
-> PNullary MessageBoundedPrim 5 -> PNullary MessageBoundedPrim 15
forall k (n :: k -> *) (t :: k) (u :: k) (v :: k).
PSemigroup n t u v =>
PNullary n t -> PNullary n u -> PNullary n v
&<>
Word32 -> MessageBoundedPrim 5
base128Varint32 (forall a b. (Integral a, Num b) => a -> b
fromIntegral @Int32 @Word32 (e -> Int32
forall a. ProtoEnum a => a -> Int32
fromProtoEnum e
e))
{-# INLINE enum #-}
bool :: FieldNumber -> Bool -> MessageBuilder
bool :: FieldNumber -> Bool -> MessageBuilder
bool = \FieldNumber
num Bool
b -> MessageBoundedPrim 11 -> MessageBuilder
forall (w :: Nat).
KnownNat w =>
MessageBoundedPrim w -> MessageBuilder
liftBoundedPrim (MessageBoundedPrim 11 -> MessageBuilder)
-> MessageBoundedPrim 11 -> MessageBuilder
forall a b. (a -> b) -> a -> b
$
FieldNumber -> WireType -> MessageBoundedPrim 10
fieldHeader FieldNumber
num WireType
Varint PNullary MessageBoundedPrim 10
-> PNullary MessageBoundedPrim 1 -> PNullary MessageBoundedPrim 11
forall k (n :: k -> *) (t :: k) (u :: k) (v :: k).
PSemigroup n t u v =>
PNullary n t -> PNullary n u -> PNullary n v
&<>
BoundedPrim 1 -> MessageBoundedPrim 1
forall (w :: Nat). BoundedPrim w -> MessageBoundedPrim w
MessageBoundedPrim
(FixedPrim 1 -> BoundedPrim 1
forall (w :: Nat). KnownNat w => FixedPrim w -> BoundedPrim w
Prim.liftFixedPrim (Word8 -> FixedPrim 1
Prim.word8 (Int -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Bool -> Int
forall a. Enum a => a -> Int
fromEnum Bool
b))))
{-# INLINE bool #-}
bytes :: FieldNumber -> RB.BuildR -> MessageBuilder
bytes :: FieldNumber -> BuildR -> MessageBuilder
bytes FieldNumber
num = FieldNumber -> MessageBuilder -> MessageBuilder
embedded FieldNumber
num (MessageBuilder -> MessageBuilder)
-> (BuildR -> MessageBuilder) -> BuildR -> MessageBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BuildR -> MessageBuilder
MessageBuilder
{-# INLINE bytes #-}
string :: FieldNumber -> String -> MessageBuilder
string :: FieldNumber -> String -> MessageBuilder
string FieldNumber
num = FieldNumber -> MessageBuilder -> MessageBuilder
embedded FieldNumber
num (MessageBuilder -> MessageBuilder)
-> (String -> MessageBuilder) -> String -> MessageBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BuildR -> MessageBuilder
MessageBuilder (BuildR -> MessageBuilder)
-> (String -> BuildR) -> String -> MessageBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> BuildR
RB.stringUtf8
{-# INLINE string #-}
text :: FieldNumber -> Text.Lazy.Text -> MessageBuilder
text :: FieldNumber -> Text -> MessageBuilder
text FieldNumber
num = FieldNumber -> MessageBuilder -> MessageBuilder
embedded FieldNumber
num (MessageBuilder -> MessageBuilder)
-> (Text -> MessageBuilder) -> Text -> MessageBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BuildR -> MessageBuilder
MessageBuilder (BuildR -> MessageBuilder)
-> (Text -> BuildR) -> Text -> MessageBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> BuildR
RB.lazyTextUtf8
{-# INLINE text #-}
shortText :: FieldNumber -> Text.Short.ShortText -> MessageBuilder
shortText :: FieldNumber -> ShortText -> MessageBuilder
shortText FieldNumber
num = FieldNumber -> MessageBuilder -> MessageBuilder
embedded FieldNumber
num (MessageBuilder -> MessageBuilder)
-> (ShortText -> MessageBuilder) -> ShortText -> MessageBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BuildR -> MessageBuilder
MessageBuilder (BuildR -> MessageBuilder)
-> (ShortText -> BuildR) -> ShortText -> MessageBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortText -> BuildR
RB.shortTextUtf8
{-# INLINE shortText #-}
byteString :: FieldNumber -> B.ByteString -> MessageBuilder
byteString :: FieldNumber -> ByteString -> MessageBuilder
byteString FieldNumber
num = FieldNumber -> MessageBuilder -> MessageBuilder
embedded FieldNumber
num (MessageBuilder -> MessageBuilder)
-> (ByteString -> MessageBuilder) -> ByteString -> MessageBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BuildR -> MessageBuilder
MessageBuilder (BuildR -> MessageBuilder)
-> (ByteString -> BuildR) -> ByteString -> MessageBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> BuildR
RB.byteString
{-# INLINE byteString #-}
lazyByteString :: FieldNumber -> BL.ByteString -> MessageBuilder
lazyByteString :: FieldNumber -> ByteString -> MessageBuilder
lazyByteString FieldNumber
num = FieldNumber -> MessageBuilder -> MessageBuilder
embedded FieldNumber
num (MessageBuilder -> MessageBuilder)
-> (ByteString -> MessageBuilder) -> ByteString -> MessageBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BuildR -> MessageBuilder
MessageBuilder (BuildR -> MessageBuilder)
-> (ByteString -> BuildR) -> ByteString -> MessageBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> BuildR
RB.lazyByteString
{-# INLINE lazyByteString #-}
shortByteString :: FieldNumber -> BS.ShortByteString -> MessageBuilder
shortByteString :: FieldNumber -> ShortByteString -> MessageBuilder
shortByteString FieldNumber
num = FieldNumber -> MessageBuilder -> MessageBuilder
embedded FieldNumber
num (MessageBuilder -> MessageBuilder)
-> (ShortByteString -> MessageBuilder)
-> ShortByteString
-> MessageBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BuildR -> MessageBuilder
MessageBuilder (BuildR -> MessageBuilder)
-> (ShortByteString -> BuildR) -> ShortByteString -> MessageBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> BuildR
RB.shortByteString
{-# INLINE shortByteString #-}
packedVarints :: Foldable f => FieldNumber -> f Word64 -> MessageBuilder
packedVarints :: forall (f :: * -> *).
Foldable f =>
FieldNumber -> f Word64 -> MessageBuilder
packedVarints FieldNumber
num = (f Word64 -> MessageBuilder) -> f Word64 -> MessageBuilder
forall a. (a -> MessageBuilder) -> a -> MessageBuilder
etaMessageBuilder (FieldNumber -> MessageBuilder -> MessageBuilder
embedded FieldNumber
num (MessageBuilder -> MessageBuilder)
-> (f Word64 -> MessageBuilder) -> f Word64 -> MessageBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f Word64 -> MessageBuilder
payload)
where
payload :: f Word64 -> MessageBuilder
payload = (Word64 -> MessageBuilder) -> f Word64 -> MessageBuilder
forall m a. Monoid m => (a -> m) -> f a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (MessageBoundedPrim 10 -> MessageBuilder
forall (w :: Nat).
KnownNat w =>
MessageBoundedPrim w -> MessageBuilder
liftBoundedPrim (MessageBoundedPrim 10 -> MessageBuilder)
-> (Word64 -> MessageBoundedPrim 10) -> Word64 -> MessageBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> MessageBoundedPrim 10
base128Varint64)
{-# INLINE packedVarints #-}
packedVarintsV ::
Vector v a => (a -> Word64) -> FieldNumber -> v a -> MessageBuilder
packedVarintsV :: forall (v :: * -> *) a.
Vector v a =>
(a -> Word64) -> FieldNumber -> v a -> MessageBuilder
packedVarintsV a -> Word64
f FieldNumber
num = FieldNumber -> MessageBuilder -> MessageBuilder
embedded FieldNumber
num (MessageBuilder -> MessageBuilder)
-> (v a -> MessageBuilder) -> v a -> MessageBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. v a -> MessageBuilder
payload
where
payload :: v a -> MessageBuilder
payload = (a -> MessageBuilder) -> v a -> MessageBuilder
forall (v :: * -> *) a.
Vector v a =>
(a -> MessageBuilder) -> v a -> MessageBuilder
vectorMessageBuilder (MessageBoundedPrim 10 -> MessageBuilder
forall (w :: Nat).
KnownNat w =>
MessageBoundedPrim w -> MessageBuilder
liftBoundedPrim (MessageBoundedPrim 10 -> MessageBuilder)
-> (a -> MessageBoundedPrim 10) -> a -> MessageBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> MessageBoundedPrim 10
base128Varint64 (Word64 -> MessageBoundedPrim 10)
-> (a -> Word64) -> a -> MessageBoundedPrim 10
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Word64
f)
{-# INLINE packedVarintsV #-}
packedBoolsV ::
Vector v a => (a -> Bool) -> FieldNumber -> v a -> MessageBuilder
packedBoolsV :: forall (v :: * -> *) a.
Vector v a =>
(a -> Bool) -> FieldNumber -> v a -> MessageBuilder
packedBoolsV a -> Bool
f FieldNumber
num = FieldNumber -> MessageBuilder -> MessageBuilder
embedded FieldNumber
num (MessageBuilder -> MessageBuilder)
-> (v a -> MessageBuilder) -> v a -> MessageBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BuildR -> MessageBuilder
MessageBuilder (BuildR -> MessageBuilder)
-> (v a -> BuildR) -> v a -> MessageBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. v a -> BuildR
payload
where
payload :: v a -> BuildR
payload = (a -> FixedPrim 1) -> v a -> BuildR
forall (w :: Nat) (v :: * -> *) a.
(KnownNat w, Vector v a) =>
(a -> FixedPrim w) -> v a -> BuildR
Prim.vectorFixedPrim (Word8 -> FixedPrim 1
Prim.word8 (Word8 -> FixedPrim 1) -> (a -> Word8) -> a -> FixedPrim 1
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Word8) -> (a -> Int) -> a -> Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Int
forall a. Enum a => a -> Int
fromEnum (Bool -> Int) -> (a -> Bool) -> a -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Bool
f)
{-# INLINE packedBoolsV #-}
packedFixed32 :: Foldable f => FieldNumber -> f Word32 -> MessageBuilder
packedFixed32 :: forall (f :: * -> *).
Foldable f =>
FieldNumber -> f Word32 -> MessageBuilder
packedFixed32 FieldNumber
num = (f Word32 -> MessageBuilder) -> f Word32 -> MessageBuilder
forall a. (a -> MessageBuilder) -> a -> MessageBuilder
etaMessageBuilder (FieldNumber -> MessageBuilder -> MessageBuilder
embedded FieldNumber
num (MessageBuilder -> MessageBuilder)
-> (f Word32 -> MessageBuilder) -> f Word32 -> MessageBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f Word32 -> MessageBuilder
payload)
where
payload :: f Word32 -> MessageBuilder
payload = (Word32 -> MessageBuilder) -> f Word32 -> MessageBuilder
forall m a. Monoid m => (a -> m) -> f a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (BuildR -> MessageBuilder
MessageBuilder (BuildR -> MessageBuilder)
-> (Word32 -> BuildR) -> Word32 -> MessageBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word32 -> BuildR
RB.word32LE)
{-# INLINE packedFixed32 #-}
packedFixed32V ::
Vector v a => (a -> Word32) -> FieldNumber -> v a -> MessageBuilder
packedFixed32V :: forall (v :: * -> *) a.
Vector v a =>
(a -> Word32) -> FieldNumber -> v a -> MessageBuilder
packedFixed32V a -> Word32
f FieldNumber
num = (v a -> MessageBuilder) -> v a -> MessageBuilder
forall a. (a -> MessageBuilder) -> a -> MessageBuilder
etaMessageBuilder (FieldNumber -> MessageBuilder -> MessageBuilder
embedded FieldNumber
num (MessageBuilder -> MessageBuilder)
-> (v a -> MessageBuilder) -> v a -> MessageBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. v a -> MessageBuilder
payload)
where
payload :: v a -> MessageBuilder
payload = BuildR -> MessageBuilder
MessageBuilder (BuildR -> MessageBuilder)
-> (v a -> BuildR) -> v a -> MessageBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> FixedPrim 4) -> v a -> BuildR
forall (w :: Nat) (v :: * -> *) a.
(KnownNat w, Vector v a) =>
(a -> FixedPrim w) -> v a -> BuildR
Prim.vectorFixedPrim (Word32 -> FixedPrim 4
Prim.word32LE (Word32 -> FixedPrim 4) -> (a -> Word32) -> a -> FixedPrim 4
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Word32
f)
{-# INLINE packedFixed32V #-}
packedFixed64 :: Foldable f => FieldNumber -> f Word64 -> MessageBuilder
packedFixed64 :: forall (f :: * -> *).
Foldable f =>
FieldNumber -> f Word64 -> MessageBuilder
packedFixed64 FieldNumber
num = (f Word64 -> MessageBuilder) -> f Word64 -> MessageBuilder
forall a. (a -> MessageBuilder) -> a -> MessageBuilder
etaMessageBuilder (FieldNumber -> MessageBuilder -> MessageBuilder
embedded FieldNumber
num (MessageBuilder -> MessageBuilder)
-> (f Word64 -> MessageBuilder) -> f Word64 -> MessageBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f Word64 -> MessageBuilder
payload)
where
payload :: f Word64 -> MessageBuilder
payload = (Word64 -> MessageBuilder) -> f Word64 -> MessageBuilder
forall m a. Monoid m => (a -> m) -> f a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (BuildR -> MessageBuilder
MessageBuilder (BuildR -> MessageBuilder)
-> (Word64 -> BuildR) -> Word64 -> MessageBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> BuildR
RB.word64LE)
{-# INLINE packedFixed64 #-}
packedFixed64V ::
Vector v a => (a -> Word64) -> FieldNumber -> v a -> MessageBuilder
packedFixed64V :: forall (v :: * -> *) a.
Vector v a =>
(a -> Word64) -> FieldNumber -> v a -> MessageBuilder
packedFixed64V a -> Word64
f FieldNumber
num = (v a -> MessageBuilder) -> v a -> MessageBuilder
forall a. (a -> MessageBuilder) -> a -> MessageBuilder
etaMessageBuilder (FieldNumber -> MessageBuilder -> MessageBuilder
embedded FieldNumber
num (MessageBuilder -> MessageBuilder)
-> (v a -> MessageBuilder) -> v a -> MessageBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. v a -> MessageBuilder
payload)
where
payload :: v a -> MessageBuilder
payload = BuildR -> MessageBuilder
MessageBuilder (BuildR -> MessageBuilder)
-> (v a -> BuildR) -> v a -> MessageBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> FixedPrim 8) -> v a -> BuildR
forall (w :: Nat) (v :: * -> *) a.
(KnownNat w, Vector v a) =>
(a -> FixedPrim w) -> v a -> BuildR
Prim.vectorFixedPrim (Word64 -> FixedPrim 8
Prim.word64LE (Word64 -> FixedPrim 8) -> (a -> Word64) -> a -> FixedPrim 8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Word64
f)
{-# INLINE packedFixed64V #-}
packedFloats :: Foldable f => FieldNumber -> f Float -> MessageBuilder
packedFloats :: forall (f :: * -> *).
Foldable f =>
FieldNumber -> f Float -> MessageBuilder
packedFloats FieldNumber
num = (f Float -> MessageBuilder) -> f Float -> MessageBuilder
forall a. (a -> MessageBuilder) -> a -> MessageBuilder
etaMessageBuilder (FieldNumber -> MessageBuilder -> MessageBuilder
embedded FieldNumber
num (MessageBuilder -> MessageBuilder)
-> (f Float -> MessageBuilder) -> f Float -> MessageBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f Float -> MessageBuilder
payload)
where
payload :: f Float -> MessageBuilder
payload = (Float -> MessageBuilder) -> f Float -> MessageBuilder
forall m a. Monoid m => (a -> m) -> f a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (BuildR -> MessageBuilder
MessageBuilder (BuildR -> MessageBuilder)
-> (Float -> BuildR) -> Float -> MessageBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Float -> BuildR
RB.floatLE)
{-# INLINE packedFloats #-}
packedFloatsV ::
Vector v a => (a -> Float) -> FieldNumber -> v a -> MessageBuilder
packedFloatsV :: forall (v :: * -> *) a.
Vector v a =>
(a -> Float) -> FieldNumber -> v a -> MessageBuilder
packedFloatsV a -> Float
f FieldNumber
num = (v a -> MessageBuilder) -> v a -> MessageBuilder
forall a. (a -> MessageBuilder) -> a -> MessageBuilder
etaMessageBuilder (FieldNumber -> MessageBuilder -> MessageBuilder
embedded FieldNumber
num (MessageBuilder -> MessageBuilder)
-> (v a -> MessageBuilder) -> v a -> MessageBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. v a -> MessageBuilder
payload)
where
payload :: v a -> MessageBuilder
payload = BuildR -> MessageBuilder
MessageBuilder (BuildR -> MessageBuilder)
-> (v a -> BuildR) -> v a -> MessageBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> FixedPrim 4) -> v a -> BuildR
forall (w :: Nat) (v :: * -> *) a.
(KnownNat w, Vector v a) =>
(a -> FixedPrim w) -> v a -> BuildR
Prim.vectorFixedPrim (Float -> FixedPrim 4
Prim.floatLE (Float -> FixedPrim 4) -> (a -> Float) -> a -> FixedPrim 4
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Float
f)
{-# INLINE packedFloatsV #-}
packedDoubles :: Foldable f => FieldNumber -> f Double -> MessageBuilder
packedDoubles :: forall (f :: * -> *).
Foldable f =>
FieldNumber -> f Double -> MessageBuilder
packedDoubles FieldNumber
num = (f Double -> MessageBuilder) -> f Double -> MessageBuilder
forall a. (a -> MessageBuilder) -> a -> MessageBuilder
etaMessageBuilder (FieldNumber -> MessageBuilder -> MessageBuilder
embedded FieldNumber
num (MessageBuilder -> MessageBuilder)
-> (f Double -> MessageBuilder) -> f Double -> MessageBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f Double -> MessageBuilder
payload)
where
payload :: f Double -> MessageBuilder
payload = (Double -> MessageBuilder) -> f Double -> MessageBuilder
forall m a. Monoid m => (a -> m) -> f a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (BuildR -> MessageBuilder
MessageBuilder (BuildR -> MessageBuilder)
-> (Double -> BuildR) -> Double -> MessageBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> BuildR
RB.doubleLE)
{-# INLINE packedDoubles #-}
packedDoublesV ::
Vector v a => (a -> Double) -> FieldNumber -> v a -> MessageBuilder
packedDoublesV :: forall (v :: * -> *) a.
Vector v a =>
(a -> Double) -> FieldNumber -> v a -> MessageBuilder
packedDoublesV a -> Double
f FieldNumber
num = (v a -> MessageBuilder) -> v a -> MessageBuilder
forall a. (a -> MessageBuilder) -> a -> MessageBuilder
etaMessageBuilder (FieldNumber -> MessageBuilder -> MessageBuilder
embedded FieldNumber
num (MessageBuilder -> MessageBuilder)
-> (v a -> MessageBuilder) -> v a -> MessageBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. v a -> MessageBuilder
payload)
where
payload :: v a -> MessageBuilder
payload = BuildR -> MessageBuilder
MessageBuilder (BuildR -> MessageBuilder)
-> (v a -> BuildR) -> v a -> MessageBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> FixedPrim 8) -> v a -> BuildR
forall (w :: Nat) (v :: * -> *) a.
(KnownNat w, Vector v a) =>
(a -> FixedPrim w) -> v a -> BuildR
Prim.vectorFixedPrim (Double -> FixedPrim 8
Prim.doubleLE (Double -> FixedPrim 8) -> (a -> Double) -> a -> FixedPrim 8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Double
f)
{-# INLINE packedDoublesV #-}
embedded :: FieldNumber -> MessageBuilder -> MessageBuilder
embedded :: FieldNumber -> MessageBuilder -> MessageBuilder
embedded = \FieldNumber
num (MessageBuilder BuildR
bb) ->
BuildR -> MessageBuilder
MessageBuilder ((Int -> BuildR) -> BuildR -> BuildR
RB.withLengthOf (BoundedPrim 20 -> BuildR
forall (w :: Nat). KnownNat w => BoundedPrim w -> BuildR
Prim.liftBoundedPrim (BoundedPrim 20 -> BuildR)
-> (Int -> BoundedPrim 20) -> Int -> BuildR
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FieldNumber -> Int -> BoundedPrim 20
prefix FieldNumber
num) BuildR
bb)
where
prefix :: FieldNumber -> Int -> PNullary BoundedPrim 20
prefix FieldNumber
num Int
len =
MessageBoundedPrim 10 -> BoundedPrim 10
forall (w :: Nat). MessageBoundedPrim w -> BoundedPrim w
unMessageBoundedPrim (FieldNumber -> WireType -> MessageBoundedPrim 10
fieldHeader FieldNumber
num WireType
LengthDelimited) PNullary BoundedPrim 10
-> PNullary BoundedPrim 10 -> PNullary BoundedPrim 20
forall k (n :: k -> *) (t :: k) (u :: k) (v :: k).
PSemigroup n t u v =>
PNullary n t -> PNullary n u -> PNullary n v
&<>
Word -> BoundedPrim 10
Prim.wordBase128LEVar (forall a b. (Integral a, Num b) => a -> b
fromIntegral @Int @Word Int
len)
{-# INLINE embedded #-}