Simplify router
Now that we only support string types in the router we no longer need to
build a "Tag" to be used for constructing argument types. Now, we can
just track the number of arguments, which simplifies the code
significantly, and removes the need to convert to and from the tag to
parameter counts.
This in turn deletes a lot of code in the router, removing the need for
tracking tag types.
Tested: Redfish service validator passes. Unit tests pass.
Change-Id: Ide1d665dc1984552681e8c05952b38073d5e32dd
Signed-off-by: Ed Tanous <ed@tanous.net>
diff --git a/http/utility.hpp b/http/utility.hpp
index 0476d73..7633c39 100644
--- a/http/utility.hpp
+++ b/http/utility.hpp
@@ -31,28 +31,11 @@
namespace utility
{
-enum class TypeCode : uint8_t
-{
- Unspecified = 0,
- String = 1,
- Path = 2,
- Max = 3,
-};
-
-// Remove when we have c++23
-template <typename E>
-constexpr typename std::underlying_type<E>::type toUnderlying(E e) noexcept
-{
- return static_cast<typename std::underlying_type<E>::type>(e);
-}
-
constexpr uint64_t getParameterTag(std::string_view url)
{
uint64_t tagValue = 0;
size_t urlSegmentIndex = std::string_view::npos;
- size_t paramIndex = 0;
-
for (size_t urlIndex = 0; urlIndex < url.size(); urlIndex++)
{
char character = url[urlIndex];
@@ -73,25 +56,14 @@
std::string_view tag = url.substr(urlSegmentIndex,
urlIndex + 1 - urlSegmentIndex);
- // Note, this is a really lame way to do std::pow(6, paramIndex)
- // std::pow doesn't work in constexpr in clang.
- // Ideally in the future we'd move this to use a power of 2 packing
- // (probably 8 instead of 6) so that these just become bit shifts
- uint64_t insertIndex = 1;
- for (size_t unused = 0; unused < paramIndex; unused++)
- {
- insertIndex *= 3;
- }
-
if (tag == "<str>" || tag == "<string>")
{
- tagValue += insertIndex * toUnderlying(TypeCode::String);
+ tagValue++;
}
if (tag == "<path>")
{
- tagValue += insertIndex * toUnderlying(TypeCode::Path);
+ tagValue++;
}
- paramIndex++;
urlSegmentIndex = std::string_view::npos;
}
}
@@ -102,18 +74,6 @@
return tagValue;
}
-constexpr size_t numArgsFromTag(int tag)
-{
- size_t ret = 0;
- while (tag > 0)
- {
- // Move to the next tag by removing the bottom bits from the number
- tag /= toUnderlying(TypeCode::Max);
- ret++;
- }
- return ret;
-};
-
class Base64Encoder
{
char overflow1 = '\0';