{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}

module Simplex.Messaging.Server.MsgStore
  ( MsgLogRecord (..),
  ) where

import Simplex.Messaging.Encoding.String
import Simplex.Messaging.Protocol (Message (..), RecipientId)

data MsgLogRecord = MLRv3 RecipientId Message

instance StrEncoding MsgLogRecord where
  strEncode :: MsgLogRecord -> ByteString
strEncode (MLRv3 RecipientId
rId Message
msg) = (Str, RecipientId, Message) -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode (ByteString -> Str
Str ByteString
"v3", RecipientId
rId, Message
msg)
  strP :: Parser MsgLogRecord
strP = Parser ByteString ByteString
"v3 " Parser ByteString ByteString
-> Parser MsgLogRecord -> Parser MsgLogRecord
forall a b.
Parser ByteString a -> Parser ByteString b -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (RecipientId -> Message -> MsgLogRecord
MLRv3 (RecipientId -> Message -> MsgLogRecord)
-> Parser ByteString RecipientId
-> Parser ByteString (Message -> MsgLogRecord)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString RecipientId
forall a. StrEncoding a => Parser a
strP_ Parser ByteString (Message -> MsgLogRecord)
-> Parser ByteString Message -> Parser MsgLogRecord
forall a b.
Parser ByteString (a -> b)
-> Parser ByteString a -> Parser ByteString b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ByteString Message
forall a. StrEncoding a => Parser a
strP)