53encodeCTID(uint32_t ledgerSeq, uint32_t txnIndex, uint32_t networkID)
noexcept
55 constexpr uint32_t maxLedgerSeq = 0x0FFF'FFFF;
56 constexpr uint32_t maxTxnIndex = 0xFFFF;
57 constexpr uint32_t maxNetworkID = 0xFFFF;
59 if (ledgerSeq > maxLedgerSeq || txnIndex > maxTxnIndex ||
60 networkID > maxNetworkID)
64 ((0xC000'0000ULL +
static_cast<uint64_t
>(ledgerSeq)) << 32) |
65 ((
static_cast<uint64_t
>(txnIndex) << 16) | networkID);
85 uint64_t ctidValue = 0;
93 if (ctidString.
size() != 16)
96 static boost::regex
const hexRegex(
"^[0-9A-Fa-f]{16}$");
97 if (!boost::regex_match(ctidString, hexRegex))
114 ctidValue =
static_cast<uint64_t
>(ctid);
122 constexpr uint64_t ctidPrefixMask = 0xF000'0000'0000'0000ULL;
123 constexpr uint64_t ctidPrefix = 0xC000'0000'0000'0000ULL;
124 if ((ctidValue & ctidPrefixMask) != ctidPrefix)
127 uint32_t ledgerSeq =
static_cast<uint32_t
>((ctidValue >> 32) & 0x0FFF'FFFF);
128 uint16_t txnIndex =
static_cast<uint16_t
>((ctidValue >> 16) & 0xFFFF);
129 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.