mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Cleanup LedgerEntryType & TxType:
This commit removes the `ltINVALID` pseudo-type identifier from `LedgerEntryType` and the `ttINVALID` pseudo-type identifier from `TxType` and includes several small additional improvements that help to simplify the code base. It also improves the documentation `LedgerEntryType` and `TxType`, which was all over the place, and highlights some important caveats associated with making changes to the ledger and transaction type identifiers. The commit also adds a safety check to the `KnownFormats<>` class, that will catch the the accidental reuse of format identifiers. Ideally, this should be done at compile time but C++ does not (yet?) allow for the sort of introspection that would enable this.
This commit is contained in:
@@ -768,12 +768,13 @@ private:
|
||||
}
|
||||
|
||||
// Compare a protobuf descriptor to a KnownFormat::Item
|
||||
template <typename FmtType>
|
||||
template <typename FmtType, typename FmtName>
|
||||
void
|
||||
validateFields(
|
||||
google::protobuf::Descriptor const* const pbufDescriptor,
|
||||
google::protobuf::Descriptor const* const commonFields,
|
||||
typename KnownFormats<FmtType>::Item const* const knownFormatItem)
|
||||
typename KnownFormats<FmtType, FmtName>::Item const* const
|
||||
knownFormatItem)
|
||||
{
|
||||
// Create namespace aliases for shorter names.
|
||||
namespace pbuf = google::protobuf;
|
||||
@@ -806,10 +807,10 @@ private:
|
||||
std::move(sFields));
|
||||
}
|
||||
|
||||
template <typename FmtType>
|
||||
template <typename FmtType, typename FmtName>
|
||||
void
|
||||
testKnownFormats(
|
||||
KnownFormats<FmtType> const& knownFormat,
|
||||
KnownFormats<FmtType, FmtName> const& knownFormat,
|
||||
std::string const& knownFormatName,
|
||||
google::protobuf::Descriptor const* const commonFields,
|
||||
google::protobuf::OneofDescriptor const* const oneOfDesc)
|
||||
@@ -822,7 +823,9 @@ private:
|
||||
return;
|
||||
|
||||
// Get corresponding names for all KnownFormat Items.
|
||||
std::map<std::string, typename KnownFormats<FmtType>::Item const*>
|
||||
std::map<
|
||||
std::string,
|
||||
typename KnownFormats<FmtType, FmtName>::Item const*>
|
||||
formatTypes;
|
||||
|
||||
for (auto const& item : knownFormat)
|
||||
@@ -897,7 +900,7 @@ private:
|
||||
}
|
||||
|
||||
// Validate that the gRPC and KnownFormat fields align.
|
||||
validateFields<FmtType>(
|
||||
validateFields<FmtType, FmtName>(
|
||||
fieldDesc->message_type(), commonFields, fmtIter->second);
|
||||
|
||||
// Remove the checked KnownFormat from the map. This way we
|
||||
|
||||
Reference in New Issue
Block a user