Skip to content

Commit f8e254c

Browse files
committed
encodings
1 parent 626f7a1 commit f8e254c

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/Simplex/Messaging/Agent/Protocol.hs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,35 @@ instance Eq ACreatedConnLink where
14281428

14291429
deriving instance Show ACreatedConnLink
14301430

1431+
instance ConnectionModeI m => StrEncoding (CreatedConnLink m) where
1432+
strEncode CCLink {connFullLink, connShortLink} = case connFullLink of
1433+
CRInvitationUri {} -> strEncode (CMInvitation, connFullLink, connShortLink)
1434+
CRContactUri _ -> strEncode (CMContact, connFullLink, connShortLink)
1435+
strP = (\(ACCL _ l) -> checkConnMode l) <$?> strP
1436+
{-# INLINE strP #-}
1437+
1438+
instance ConnectionModeI m => ToField (CreatedConnLink m) where toField = toField . Binary . strEncode
1439+
1440+
instance (Typeable m, ConnectionModeI m) => FromField (CreatedConnLink m) where fromField = blobFieldDecoder strDecode
1441+
1442+
instance StrEncoding ACreatedConnLink where
1443+
strEncode (ACCL _ ccl) = strEncode ccl
1444+
{-# INLINE strEncode #-}
1445+
strP =
1446+
strP >>= \case
1447+
CMInvitation -> do
1448+
connFullLink <- strP_
1449+
connShortLink <- strP
1450+
pure $ ACCL SCMInvitation $ CCLink connFullLink connShortLink
1451+
CMContact -> do
1452+
connFullLink <- strP_
1453+
connShortLink <- strP
1454+
pure $ ACCL SCMContact $ CCLink connFullLink connShortLink
1455+
1456+
instance ToField ACreatedConnLink where toField = toField . Binary . strEncode
1457+
1458+
instance FromField ACreatedConnLink where fromField = blobFieldDecoder strDecode
1459+
14311460
data AConnectionLink = forall m. ConnectionModeI m => ACL (SConnectionMode m) (ConnectionLink m)
14321461

14331462
instance Eq AConnectionLink where

0 commit comments

Comments
 (0)