mirror of
https://github.com/unclechu/gRPC-haskell.git
synced 2024-11-26 21:19:43 +01:00
Add Network.GRPC.Time
module with Timespec
binding.
This commit is contained in:
parent
27e90f47bb
commit
3d4cad3279
2 changed files with 35 additions and 3 deletions
|
@ -19,11 +19,17 @@ cabal-version: >=1.10
|
|||
library
|
||||
exposed-modules:
|
||||
Network.GRPC
|
||||
Network.GRPC.Time
|
||||
-- other-modules:
|
||||
-- other-extensions:
|
||||
extra-libraries: grpc
|
||||
includes: grpc/grpc.h
|
||||
extra-libraries:
|
||||
grpc
|
||||
includes:
|
||||
grpc/grpc.h
|
||||
, grpc/support/time.h
|
||||
build-tools: c2hs
|
||||
build-depends: base >=4.7 && <4.8
|
||||
build-depends:
|
||||
base >=4.7 && <4.8
|
||||
, clock >=0.4 && <0.5
|
||||
hs-source-dirs: src
|
||||
default-language: Haskell2010
|
||||
|
|
26
src/Network/GRPC/Time.chs
Normal file
26
src/Network/GRPC/Time.chs
Normal file
|
@ -0,0 +1,26 @@
|
|||
module Network.GRPC.Time where
|
||||
|
||||
import Control.Applicative
|
||||
import Control.Monad
|
||||
import Foreign.C.Types
|
||||
import Foreign.Ptr
|
||||
import Foreign.Storable
|
||||
import System.Clock
|
||||
|
||||
#include "grpc/support/time.h"
|
||||
|
||||
{#context prefix = "grp" #}
|
||||
|
||||
newtype CTimeSpec = CTimeSpec { timeSpec :: TimeSpec }
|
||||
{#pointer *gpr_timespec as CTimeSpecPtr -> CTimeSpec #}
|
||||
|
||||
instance Storable CTimeSpec where
|
||||
sizeOf _ = {#sizeof gpr_timespec #}
|
||||
alignment _ = {#alignof gpr_timespec #}
|
||||
peek p = fmap CTimeSpec $ TimeSpec
|
||||
<$> liftM fromIntegral ({#get gpr_timespec->tv_sec #} p)
|
||||
<*> liftM fromIntegral ({#get gpr_timespec->tv_nsec #} p)
|
||||
poke p x = do
|
||||
{#set gpr_timespec.tv_sec #} p (fromIntegral $ sec $ timeSpec x)
|
||||
{#set gpr_timespec.tv_nsec #} p (fromIntegral $ nsec $ timeSpec x)
|
||||
|
Loading…
Reference in a new issue