From 170e41ccd38c3df81b2240702ee98671af3cc5ae Mon Sep 17 00:00:00 2001 From: mu <59917266+4eUeP@users.noreply.github.com> Date: Wed, 8 May 2024 18:19:50 +0800 Subject: [PATCH] Show instance for RecordBytes --- .../HStream/Kafka/Server/Handler/Produce.hs | 5 +++++ .../protocol/Kafka/Protocol/Encoding/Types.hs | 13 +++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/hstream-kafka/HStream/Kafka/Server/Handler/Produce.hs b/hstream-kafka/HStream/Kafka/Server/Handler/Produce.hs index f12bd4856..247f47a73 100644 --- a/hstream-kafka/HStream/Kafka/Server/Handler/Produce.hs +++ b/hstream-kafka/HStream/Kafka/Server/Handler/Produce.hs @@ -75,6 +75,11 @@ handleProduce ServerContext{..} _reqCtx req = do let recordBytes = fromMaybe (error "TODO: Receive empty recordBytes in ProduceRequest") (K.unRecordBytes partition.recordBytes) + -- Trace raw record bytes of the request + -- + -- Note that the Show instance of RecordBytes type will only show the + -- length of the ByteString. So here we pass the ByteString to the Log + Log.trace $ "Received recordBytes: " <> Log.buildString' (recordBytes :: ByteString) Log.debug1 $ "Try to append to logid " <> Log.build logid <> "(" <> Log.build partition.index <> ")" diff --git a/hstream-kafka/protocol/Kafka/Protocol/Encoding/Types.hs b/hstream-kafka/protocol/Kafka/Protocol/Encoding/Types.hs index 68714a9c8..064b8e874 100644 --- a/hstream-kafka/protocol/Kafka/Protocol/Encoding/Types.hs +++ b/hstream-kafka/protocol/Kafka/Protocol/Encoding/Types.hs @@ -33,6 +33,7 @@ module Kafka.Protocol.Encoding.Types import Control.DeepSeq (NFData) import Control.Monad import Data.ByteString (ByteString) +import qualified Data.ByteString as BS import Data.Int import Data.String (IsString) import Data.Text (Text) @@ -162,11 +163,19 @@ instance Functor CompactKaArray where fmap f (CompactKaArray xs) = CompactKaArray $ fmap f <$> xs newtype RecordBytes = RecordBytes { unRecordBytes :: Maybe ByteString } - deriving newtype (Show, Eq, Ord, NFData) + deriving newtype (Eq, Ord, NFData) + +instance Show RecordBytes where + show (RecordBytes (Just bs)) = " show (BS.length bs) <> ">" + show (RecordBytes Nothing) = "" newtype RecordCompactBytes = RecordCompactBytes { unRecordCompactBytes :: Maybe ByteString } - deriving newtype (Show, Eq, Ord, NFData) + deriving newtype (Eq, Ord, NFData) + +instance Show RecordCompactBytes where + show (RecordCompactBytes (Just bs)) = " show (BS.length bs) <> ">" + show (RecordCompactBytes Nothing) = "" newtype RecordKey = RecordKey { unRecordKey :: Maybe ByteString } deriving newtype (Show, Eq, Ord, NFData)