module Database.Kafkar.Types
(
Topic(..)
, Segment(..)
, MessageEntry(..)
, Message(..)
, Attributes(..)
, Index
, IndexEntry(..)
, Codec(..)
, Offset(..)
, RelativeOffset(..)
, LogPosition(..)
) where
import Data.AdditiveGroup
import Data.AffineSpace
import Data.ByteString (ByteString)
import Data.Int
import qualified Data.Vector as VB
import qualified Data.Vector.Unboxed as VU
import Data.Vector.Unboxed.Deriving
data Codec = None | GZip | Snappy
deriving (Eq, Show)
newtype Offset = Offset Int64
deriving (Eq, Show, Ord)
newtype RelativeOffset = RelativeOffset Int32
deriving (Eq, Show, Ord)
newtype LogPosition = LogPosition Int32
deriving (Eq, Show, Ord)
instance AdditiveGroup RelativeOffset where
(RelativeOffset x) ^+^ (RelativeOffset y) = RelativeOffset (x + y)
zeroV = RelativeOffset 0
negateV (RelativeOffset x) = RelativeOffset (negate x)
instance AffineSpace Offset where
type Diff Offset = RelativeOffset
(Offset x) .-. (Offset y) = RelativeOffset $ fromIntegral (x y)
(Offset x) .+^ (RelativeOffset y) = Offset (x + fromIntegral y)
data IndexEntry = IndexEntry
{ relativeOffset :: !RelativeOffset
, logPosition :: !LogPosition
} deriving (Eq, Show)
derivingUnbox "IndexEntry"
[t| IndexEntry -> (Int32,Int32) |]
[| \(IndexEntry (RelativeOffset x) (LogPosition y)) -> (x,y) |]
[| \(x, y) -> IndexEntry (RelativeOffset x) (LogPosition y) |]
type Index = VU.Vector IndexEntry
data MessageEntry = MessageEntry
{ offset :: !Offset
, size :: !Int32
, message :: !Message
} deriving (Eq, Show)
data Message = Message
{ attributes :: !Attributes
, key :: !(Maybe ByteString)
, value :: !(Maybe ByteString)
} deriving (Eq, Show)
data Attributes = Attributes
{ compression :: !Codec
} deriving (Eq, Show)
data Topic = Topic
{ topicName :: !String
, partition :: !Int
, segments :: !(VB.Vector Segment)
} deriving (Eq, Show)
data Segment = Segment
{ initialOffset :: !Offset
, index :: !Index
, logPath :: !FilePath
} deriving (Eq, Show)