Make all ints size_t
We should be consistent when we declare index types. Nlohmann uses an
underlying uint64_t as the integer type, so use that for all index
types.
Size_t is directly creatable from it in both 32 and 64 bit modes.
Tested: On last patch in series.
Change-Id: Id1da0e7be2e2046bdbd732247d208b6e9e8c008c
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/redfish-core/include/error_messages.hpp b/redfish-core/include/error_messages.hpp
index 7dfe62d..e38a6f4 100644
--- a/redfish-core/include/error_messages.hpp
+++ b/redfish-core/include/error_messages.hpp
@@ -899,9 +899,9 @@
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message InvalidIndex formatted to JSON */
-nlohmann::json invalidIndex(int64_t arg1);
+nlohmann::json invalidIndex(uint64_t arg1);
-void invalidIndex(crow::Response& res, int64_t arg1);
+void invalidIndex(crow::Response& res, uint64_t arg1);
/**
* @brief Formats PropertyValueModified message into JSON
@@ -949,9 +949,10 @@
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message StringValueTooLong formatted to JSON */
-nlohmann::json stringValueTooLong(std::string_view arg1, int arg2);
+nlohmann::json stringValueTooLong(std::string_view arg1, uint64_t arg2);
-void stringValueTooLong(crow::Response& res, std::string_view arg1, int arg2);
+void stringValueTooLong(crow::Response& res, std::string_view arg1,
+ uint64_t arg2);
/**
* @brief Formats StringValueTooShort message into JSON
diff --git a/redfish-core/src/error_messages.cpp b/redfish-core/src/error_messages.cpp
index 328cae7..4e2ede8 100644
--- a/redfish-core/src/error_messages.cpp
+++ b/redfish-core/src/error_messages.cpp
@@ -1533,14 +1533,14 @@
* See header file for more information
* @endinternal
*/
-nlohmann::json invalidIndex(int64_t arg1)
+nlohmann::json invalidIndex(uint64_t arg1)
{
std::string arg1Str = std::to_string(arg1);
return getLog(redfish::registries::base::Index::invalidIndex,
std::to_array<std::string_view>({arg1Str}));
}
-void invalidIndex(crow::Response& res, int64_t arg1)
+void invalidIndex(crow::Response& res, uint64_t arg1)
{
res.result(boost::beast::http::status::bad_request);
addMessageToErrorJson(res.jsonValue, invalidIndex(arg1));
@@ -1613,14 +1613,15 @@
* See header file for more information
* @endinternal
*/
-nlohmann::json stringValueTooLong(std::string_view arg1, int arg2)
+nlohmann::json stringValueTooLong(std::string_view arg1, uint64_t arg2)
{
std::string arg2Str = std::to_string(arg2);
return getLog(redfish::registries::base::Index::stringValueTooLong,
std::to_array<std::string_view>({arg1, arg2Str}));
}
-void stringValueTooLong(crow::Response& res, std::string_view arg1, int arg2)
+void stringValueTooLong(crow::Response& res, std::string_view arg1,
+ uint64_t arg2)
{
res.result(boost::beast::http::status::bad_request);
addMessageToErrorJson(res.jsonValue, stringValueTooLong(arg1, arg2));
diff --git a/scripts/parse_registries.py b/scripts/parse_registries.py
index a7eb5bf..ceb781f 100755
--- a/scripts/parse_registries.py
+++ b/scripts/parse_registries.py
@@ -237,47 +237,41 @@
def make_error_function(entry_id, entry, is_header):
-
- arg_as_url = {
- "AccessDenied": [1],
- "CouldNotEstablishConnection": [1],
- "GenerateSecretKeyRequired": [1],
- "InvalidObject": [1],
- "PasswordChangeRequired": [1],
- "PropertyValueResourceConflict": [3],
- "ResetRequired": [1],
- "ResourceAtUriInUnknownFormat": [1],
- "ResourceAtUriUnauthorized": [1],
- "ResourceCreationConflict": [1],
- "ResourceMissingAtURI": [1],
- "SourceDoesNotSupportProtocol": [1],
- }
-
- arg_as_json = {
- "ActionParameterValueError": [1],
- "ActionParameterValueFormatError": [1],
- "ActionParameterValueTypeError": [1],
- "PropertyValueExternalConflict": [2],
- "PropertyValueFormatError": [1],
- "PropertyValueIncorrect": [2],
- "PropertyValueModified": [2],
- "PropertyValueNotInList": [1],
- "PropertyValueOutOfRange": [1],
- "PropertyValueResourceConflict": [2],
- "PropertyValueTypeError": [1],
- "QueryParameterValueFormatError": [1],
- "QueryParameterValueTypeError": [1],
- }
-
- arg_as_int = {
- "StringValueTooLong": [2],
- }
-
- arg_as_uint64 = {
- "ArraySizeTooLong": [2],
- }
- arg_as_int64 = {
- "InvalidIndex": [1],
+ arg_nonstring_types = {
+ "const boost::urls::url_view_base&": {
+ "AccessDenied": [1],
+ "CouldNotEstablishConnection": [1],
+ "GenerateSecretKeyRequired": [1],
+ "InvalidObject": [1],
+ "PasswordChangeRequired": [1],
+ "PropertyValueResourceConflict": [3],
+ "ResetRequired": [1],
+ "ResourceAtUriInUnknownFormat": [1],
+ "ResourceAtUriUnauthorized": [1],
+ "ResourceCreationConflict": [1],
+ "ResourceMissingAtURI": [1],
+ "SourceDoesNotSupportProtocol": [1],
+ },
+ "const nlohmann::json&": {
+ "ActionParameterValueError": [1],
+ "ActionParameterValueFormatError": [1],
+ "ActionParameterValueTypeError": [1],
+ "PropertyValueExternalConflict": [2],
+ "PropertyValueFormatError": [1],
+ "PropertyValueIncorrect": [2],
+ "PropertyValueModified": [2],
+ "PropertyValueNotInList": [1],
+ "PropertyValueOutOfRange": [1],
+ "PropertyValueResourceConflict": [2],
+ "PropertyValueTypeError": [1],
+ "QueryParameterValueFormatError": [1],
+ "QueryParameterValueTypeError": [1],
+ },
+ "uint64_t": {
+ "ArraySizeTooLong": [2],
+ "InvalidIndex": [1],
+ "StringValueTooLong": [2],
+ },
}
out = ""
@@ -285,18 +279,11 @@
argtypes = []
for arg_index, arg in enumerate(entry.get("ParamTypes", [])):
arg_index += 1
- if arg_index in arg_as_url.get(entry_id, []):
- typename = "const boost::urls::url_view_base&"
- elif arg_index in arg_as_json.get(entry_id, []):
- typename = "const nlohmann::json&"
- elif arg_index in arg_as_int.get(entry_id, []):
- typename = "int"
- elif arg_index in arg_as_uint64.get(entry_id, []):
- typename = "uint64_t"
- elif arg_index in arg_as_int64.get(entry_id, []):
- typename = "int64_t"
- else:
- typename = "std::string_view"
+ typename = "std::string_view"
+ for typestring, entries in arg_nonstring_types.items():
+ if arg_index in entries.get(entry_id, []):
+ typename = typestring
+
argtypes.append(typename)
args.append(f"{typename} arg{arg_index}")
function_name = entry_id[0].lower() + entry_id[1:]
@@ -314,7 +301,7 @@
index += 1
if typename == "const nlohmann::json&":
out += f"std::string arg{index}Str = arg{index}.dump(-1, ' ', true, nlohmann::json::error_handler_t::replace);\n"
- elif typename in ("int64_t", "int", "uint64_t"):
+ elif typename == "uint64_t":
out += f"std::string arg{index}Str = std::to_string(arg{index});\n"
for index, typename in enumerate(argtypes):
@@ -325,13 +312,12 @@
elif typename == "const nlohmann::json&":
outargs.append(f"arg{index}Str")
to_array_type = "<std::string_view>"
- elif typename in ("int64_t", "int", "uint64_t"):
+ elif typename == "uint64_t":
outargs.append(f"arg{index}Str")
to_array_type = "<std::string_view>"
else:
outargs.append(f"arg{index}")
argstring = ", ".join(outargs)
- # out += f" std::array<std::string_view, {len(argtypes)}> args{{{argstring}}};\n"
if argtypes:
arg_param = f"std::to_array{to_array_type}({{{argstring}}})"