-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathParser.hs
More file actions
45 lines (37 loc) · 1.54 KB
/
Parser.hs
File metadata and controls
45 lines (37 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE GHCForeignImportPrim #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE UnliftedFFITypes #-}
module Parser (ITCHv41(..), parseITCHv41) where
import GHC.Int
import GHC.Prim
import GHC.Ptr
import GHC.Word
foreign import prim "ITCHv41_run"
parseITCHv41# :: Addr# -> Word# -> (# Int#, Word#, Word#, Word#, Word#, Word# #)
data ITCHv41
= OrderExecuted
{ nanos :: {-# UNPACK #-} !Word64
, refNum :: {-# UNPACK #-} !Word64
, shares :: {-# UNPACK #-} !Word64
, matchNum :: {-# UNPACK #-} !Word64 }
| OrderExecutedWithPrice
{ nanos :: {-# UNPACK #-} !Word64
, refNum :: {-# UNPACK #-} !Word64
, shares :: {-# UNPACK #-} !Word64
, matchNum :: {-# UNPACK #-} !Word64
, price :: {-# UNPACK #-} !Word64 }
| OtherMessage
{ status :: {-# UNPACK #-} !Int64 }
deriving (Show)
-- | invoke the parser primop and allocate a record with the results
parseITCHv41 :: Ptr Word8 -> Word -> ITCHv41
parseITCHv41 (Ptr buffer) (W# length) = case parseITCHv41# buffer length of
(# 1#, nanos, shares, _, matchNum, refNum #) ->
OrderExecuted (W64# nanos) (W64# refNum) (W64# shares) (W64# matchNum)
(# 2#, nanos, shares, price, matchNum, refNum #) ->
OrderExecutedWithPrice (W64# nanos) (W64# refNum) (W64# shares) (W64# matchNum) (W64# price)
(# status, _, _, _, _, _ #) ->
OtherMessage (I64# status) -- insert error handling here