mirror of
https://github.com/logos-messaging/nim-sds.git
synced 2026-01-05 23:53:08 +00:00
chore: rearrange helper funcs
This commit is contained in:
parent
b69164da17
commit
7105874c07
@ -33,24 +33,3 @@ const
|
|||||||
DefaultSyncMessageInterval* = initDuration(seconds = 30)
|
DefaultSyncMessageInterval* = initDuration(seconds = 30)
|
||||||
DefaultBufferSweepInterval* = initDuration(seconds = 60)
|
DefaultBufferSweepInterval* = initDuration(seconds = 60)
|
||||||
MaxMessageSize* = 1024 * 1024 # 1 MB
|
MaxMessageSize* = 1024 * 1024 # 1 MB
|
||||||
|
|
||||||
# Helper functions for HistoryEntry
|
|
||||||
proc newHistoryEntry*(messageId: SdsMessageID, retrievalHint: seq[byte] = @[]): HistoryEntry =
|
|
||||||
## Creates a new HistoryEntry with optional retrieval hint
|
|
||||||
HistoryEntry(messageId: messageId, retrievalHint: retrievalHint)
|
|
||||||
|
|
||||||
proc newHistoryEntry*(messageId: SdsMessageID, retrievalHint: string): HistoryEntry =
|
|
||||||
## Creates a new HistoryEntry with string retrieval hint
|
|
||||||
HistoryEntry(messageId: messageId, retrievalHint: cast[seq[byte]](retrievalHint))
|
|
||||||
|
|
||||||
proc toCausalHistory*(messageIds: seq[SdsMessageID]): seq[HistoryEntry] =
|
|
||||||
## Converts a sequence of message IDs to HistoryEntry sequence (for backward compatibility)
|
|
||||||
result = newSeq[HistoryEntry](messageIds.len)
|
|
||||||
for i, msgId in messageIds:
|
|
||||||
result[i] = newHistoryEntry(msgId)
|
|
||||||
|
|
||||||
proc getMessageIds*(causalHistory: seq[HistoryEntry]): seq[SdsMessageID] =
|
|
||||||
## Extracts message IDs from HistoryEntry sequence
|
|
||||||
result = newSeq[SdsMessageID](causalHistory.len)
|
|
||||||
for i, entry in causalHistory:
|
|
||||||
result[i] = entry.messageId
|
|
||||||
|
|||||||
@ -124,6 +124,27 @@ proc updateLamportTimestamp*(
|
|||||||
error "Failed to update lamport timestamp",
|
error "Failed to update lamport timestamp",
|
||||||
channelId = channelId, msgTs = msgTs, error = getCurrentExceptionMsg()
|
channelId = channelId, msgTs = msgTs, error = getCurrentExceptionMsg()
|
||||||
|
|
||||||
|
# Helper functions for HistoryEntry
|
||||||
|
proc newHistoryEntry*(messageId: SdsMessageID, retrievalHint: seq[byte] = @[]): HistoryEntry =
|
||||||
|
## Creates a new HistoryEntry with optional retrieval hint
|
||||||
|
HistoryEntry(messageId: messageId, retrievalHint: retrievalHint)
|
||||||
|
|
||||||
|
proc newHistoryEntry*(messageId: SdsMessageID, retrievalHint: string): HistoryEntry =
|
||||||
|
## Creates a new HistoryEntry with string retrieval hint
|
||||||
|
HistoryEntry(messageId: messageId, retrievalHint: cast[seq[byte]](retrievalHint))
|
||||||
|
|
||||||
|
proc toCausalHistory*(messageIds: seq[SdsMessageID]): seq[HistoryEntry] =
|
||||||
|
## Converts a sequence of message IDs to HistoryEntry sequence
|
||||||
|
result = newSeq[HistoryEntry](messageIds.len)
|
||||||
|
for i, msgId in messageIds:
|
||||||
|
result[i] = newHistoryEntry(msgId)
|
||||||
|
|
||||||
|
proc getMessageIds*(causalHistory: seq[HistoryEntry]): seq[SdsMessageID] =
|
||||||
|
## Extracts message IDs from HistoryEntry sequence
|
||||||
|
result = newSeq[SdsMessageID](causalHistory.len)
|
||||||
|
for i, entry in causalHistory:
|
||||||
|
result[i] = entry.messageId
|
||||||
|
|
||||||
proc getRecentHistoryEntries*(
|
proc getRecentHistoryEntries*(
|
||||||
rm: ReliabilityManager, n: int, channelId: SdsChannelID
|
rm: ReliabilityManager, n: int, channelId: SdsChannelID
|
||||||
): seq[HistoryEntry] =
|
): seq[HistoryEntry] =
|
||||||
@ -265,4 +286,4 @@ proc removeChannel*(
|
|||||||
except Exception:
|
except Exception:
|
||||||
error "Failed to remove channel",
|
error "Failed to remove channel",
|
||||||
channelId = channelId, msg = getCurrentExceptionMsg()
|
channelId = channelId, msg = getCurrentExceptionMsg()
|
||||||
return err(ReliabilityError.reInternalError)
|
return err(ReliabilityError.reInternalError)
|
||||||
Loading…
x
Reference in New Issue
Block a user