<commit_before>module Pos.Binary.Infra.Relay
       (
       ) where

import           Universum

import           Pos.Binary.Class              (Bi (..), getWord8, label, labelS,
                                                putConst, putField)
import           Pos.Communication.Types.Relay (InvMsg (..), MempoolMsg (..), ReqMsg (..))

instance Bi key => Bi (InvMsg key) where
    sizeNPut = labelS "InvMsg" $ putField imKey
    get = label "InvMsg" $ InvMsg <$> get

instance Bi key => Bi (ReqMsg key) where
    sizeNPut = labelS "ReqMsg" $ putField rmKey
    get = label "ReqMsg" $ ReqMsg <$> get

instance Bi (MempoolMsg tag) where
    -- The extra byte is needed because time-warp doesn't work with
    -- possibly-empty messages. 228 was chosen as homage to @pva701
    sizeNPut = labelS "MempoolMsg" $ putConst @Word8 228
    get = label "MempoolMsg" $ do
        x <- getWord8
        when (x /= 228) $ fail "wrong byte"
        pure MempoolMsg<commit_msg>Add Cbor.Bi instance for MempoolMsg<commit_after>module Pos.Binary.Infra.Relay
       (
       ) where

import           Universum

import           Pos.Binary.Class              (Bi (..), getWord8, label, labelS,
                                                putConst, putField)
import qualified Pos.Binary.Cbor               as Cbor
import           Pos.Communication.Types.Relay (InvMsg (..), MempoolMsg (..), ReqMsg (..))

instance Bi key => Bi (InvMsg key) where
    sizeNPut = labelS "InvMsg" $ putField imKey
    get = label "InvMsg" $ InvMsg <$> get

instance Bi key => Bi (ReqMsg key) where
    sizeNPut = labelS "ReqMsg" $ putField rmKey
    get = label "ReqMsg" $ ReqMsg <$> get

instance Bi (MempoolMsg tag) where
    -- The extra byte is needed because time-warp doesn't work with
    -- possibly-empty messages. 228 was chosen as homage to @pva701
    sizeNPut = labelS "MempoolMsg" $ putConst @Word8 228
    get = label "MempoolMsg" $ do
        x <- getWord8
        when (x /= 228) $ fail "wrong byte"
        pure MempoolMsg

instance Cbor.Bi (MempoolMsg tag) where
  encode MempoolMsg = Cbor.encode (228 :: Word8)
  decode = do
    x <- Cbor.decode @Word8
    when (x /= 228) $ fail "wrong byte"
    pure MempoolMsg
{'fraction_non_alphanumeric': 0.10077167498865183, 'fraction_numerical': 0.017249205628688154, 'mean_word_length': 2.1306818181818183, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6864274', 'n_tokens_mistral': 726, 'n_tokens_neox': 672, 'n_words': 223}