summaryrefslogtreecommitdiff
path: root/http/utility.hpp
diff options
context:
space:
mode:
authorEd Tanous <ed@tanous.net>2024-03-28 00:08:59 +0300
committerEd Tanous <ed@tanous.net>2024-04-11 19:38:16 +0300
commitd9e89dfd49538c54d280dce3750f4af264cfd5fc (patch)
treea6884a3df21336eb24c7fbeaedf225361ca46cb2 /http/utility.hpp
parent76b038f20fed54ff61450a175160dc0af21b3cf9 (diff)
downloadbmcweb-d9e89dfd49538c54d280dce3750f4af264cfd5fc.tar.xz
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>
Diffstat (limited to 'http/utility.hpp')
-rw-r--r--http/utility.hpp44
1 files changed, 2 insertions, 42 deletions
diff --git a/http/utility.hpp b/http/utility.hpp
index 0476d73c74..7633c395af 100644
--- a/http/utility.hpp
+++ b/http/utility.hpp
@@ -31,28 +31,11 @@ namespace crow
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 @@ constexpr uint64_t getParameterTag(std::string_view url)
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 @@ constexpr uint64_t getParameterTag(std::string_view url)
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';