36encodeCTID(uint32_t ledgerSeq, uint32_t txnIndex, uint32_t networkID)
noexcept
38 static constexpr uint32_t kMaxLedgerSeq = 0x0FFF'FFFF;
39 static constexpr uint32_t kMaxTxnIndex = 0xFFFF;
40 static constexpr uint32_t kMaxNetworkId = 0xFFFF;
42 if (ledgerSeq > kMaxLedgerSeq || txnIndex > kMaxTxnIndex || networkID > kMaxNetworkId)
45 uint64_t
const ctidValue = ((0xC000'0000ULL +
static_cast<uint64_t
>(ledgerSeq)) << 32) |
46 ((
static_cast<uint64_t
>(txnIndex) << 16) | networkID);
65 uint64_t ctidValue = 0;
73 if (ctidString.
size() != 16)
76 static boost::regex
const kHexRegex(
"^[0-9A-Fa-f]{16}$");
77 if (!boost::regex_match(ctidString, kHexRegex))
94 ctidValue =
static_cast<uint64_t
>(ctid);
102 static constexpr uint64_t kCtidPrefixMask = 0xF000'0000'0000'0000ULL;
103 static constexpr uint64_t kCtidPrefix = 0xC000'0000'0000'0000ULL;
104 if ((ctidValue & kCtidPrefixMask) != kCtidPrefix)
107 auto const ledgerSeq =
static_cast<uint32_t
>((ctidValue >> 32) & 0x0FFF'FFFF);
108 auto const txnIndex =
static_cast<uint16_t
>((ctidValue >> 16) & 0xFFFF);
109 auto const 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.