34encodeCTID(uint32_t ledgerSeq, uint32_t txnIndex, uint32_t networkID)
noexcept
36 constexpr uint32_t maxLedgerSeq = 0x0FFF'FFFF;
37 constexpr uint32_t maxTxnIndex = 0xFFFF;
38 constexpr uint32_t maxNetworkID = 0xFFFF;
40 if (ledgerSeq > maxLedgerSeq || txnIndex > maxTxnIndex ||
41 networkID > maxNetworkID)
45 ((0xC000'0000ULL +
static_cast<uint64_t
>(ledgerSeq)) << 32) |
46 ((
static_cast<uint64_t
>(txnIndex) << 16) | networkID);
66 uint64_t ctidValue = 0;
74 if (ctidString.
size() != 16)
77 static boost::regex
const hexRegex(
"^[0-9A-Fa-f]{16}$");
78 if (!boost::regex_match(ctidString, hexRegex))
95 ctidValue =
static_cast<uint64_t
>(ctid);
103 constexpr uint64_t ctidPrefixMask = 0xF000'0000'0000'0000ULL;
104 constexpr uint64_t ctidPrefix = 0xC000'0000'0000'0000ULL;
105 if ((ctidValue & ctidPrefixMask) != ctidPrefix)
108 uint32_t ledgerSeq =
static_cast<uint32_t
>((ctidValue >> 32) & 0x0FFF'FFFF);
109 uint16_t txnIndex =
static_cast<uint16_t
>((ctidValue >> 16) & 0xFFFF);
110 uint16_t networkID =
static_cast<uint16_t
>(ctidValue & 0xFFFF);
std::optional< std::string > encodeCTID(uint32_t ledgerSeq, uint32_t txnIndex, uint32_t networkID) noexcept
Encodes ledger sequence, transaction index, and network ID into a CTID string.
std::optional< std::tuple< uint32_t, uint16_t, uint16_t > > decodeCTID(T const ctid) noexcept
Decodes a CTID string or integer into its component parts.