From f8e254cca9f9581ff669541c8430a0c6a6d29bb7 Mon Sep 17 00:00:00 2001 From: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Date: Thu, 29 May 2025 11:51:25 +0400 Subject: [PATCH] encodings --- src/Simplex/Messaging/Agent/Protocol.hs | 29 +++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/Simplex/Messaging/Agent/Protocol.hs b/src/Simplex/Messaging/Agent/Protocol.hs index 0d454b421..3d689ac53 100644 --- a/src/Simplex/Messaging/Agent/Protocol.hs +++ b/src/Simplex/Messaging/Agent/Protocol.hs @@ -1428,6 +1428,35 @@ instance Eq ACreatedConnLink where deriving instance Show ACreatedConnLink +instance ConnectionModeI m => StrEncoding (CreatedConnLink m) where + strEncode CCLink {connFullLink, connShortLink} = case connFullLink of + CRInvitationUri {} -> strEncode (CMInvitation, connFullLink, connShortLink) + CRContactUri _ -> strEncode (CMContact, connFullLink, connShortLink) + strP = (\(ACCL _ l) -> checkConnMode l) <$?> strP + {-# INLINE strP #-} + +instance ConnectionModeI m => ToField (CreatedConnLink m) where toField = toField . Binary . strEncode + +instance (Typeable m, ConnectionModeI m) => FromField (CreatedConnLink m) where fromField = blobFieldDecoder strDecode + +instance StrEncoding ACreatedConnLink where + strEncode (ACCL _ ccl) = strEncode ccl + {-# INLINE strEncode #-} + strP = + strP >>= \case + CMInvitation -> do + connFullLink <- strP_ + connShortLink <- strP + pure $ ACCL SCMInvitation $ CCLink connFullLink connShortLink + CMContact -> do + connFullLink <- strP_ + connShortLink <- strP + pure $ ACCL SCMContact $ CCLink connFullLink connShortLink + +instance ToField ACreatedConnLink where toField = toField . Binary . strEncode + +instance FromField ACreatedConnLink where fromField = blobFieldDecoder strDecode + data AConnectionLink = forall m. ConnectionModeI m => ACL (SConnectionMode m) (ConnectionLink m) instance Eq AConnectionLink where