Map operations by ordinal

This commit is contained in:
Uwe Seimet 2021-12-18 13:26:21 +01:00
parent ee101f2c6b
commit 6b14ba6511
3 changed files with 6 additions and 6 deletions

View File

@ -179,10 +179,9 @@ message PbOperationMetaData {
repeated PbOperationParameter parameters = 2; repeated PbOperationParameter parameters = 2;
} }
// Mapping of operation names to their meta data. // Mapping of operations to their ordinals
// The names are the names at the time the server-side protobuf data were generated from the .proto interface file.
message PbOperationInfo { message PbOperationInfo {
map<string, PbOperationMetaData> operations = 1; map<int32, PbOperationMetaData> operations = 1;
} }
// The supported file extensions mapped to their respective device types // The supported file extensions mapped to their respective device types

View File

@ -468,7 +468,8 @@ void RascsiResponse::CreateOperation(PbOperationInfo *operation_info, PbOperatio
const PbOperation& operation, const string& description) const PbOperation& operation, const string& description)
{ {
(*meta_data->mutable_description())["en"] = description; (*meta_data->mutable_description())["en"] = description;
(*operation_info->mutable_operations())[PbOperation_Name(operation)] = *meta_data; int ordinal = PbOperation_descriptor()->FindValueByName(PbOperation_Name(operation))->index();
(*operation_info->mutable_operations())[ordinal] = *meta_data;
} }
PbOperationParameter *RascsiResponse::AddOperationParameter(PbOperationMetaData *meta_data, const string& name, PbOperationParameter *RascsiResponse::AddOperationParameter(PbOperationMetaData *meta_data, const string& name,

View File

@ -277,11 +277,11 @@ void RasctlDisplay::DisplayMappingInfo(const PbMappingInfo& mapping_info)
void RasctlDisplay::DisplayOperationInfo(const PbOperationInfo& operation_info) void RasctlDisplay::DisplayOperationInfo(const PbOperationInfo& operation_info)
{ {
// Creates a sorted map // Creates a sorted map
const map<string, PbOperationMetaData> operations = { operation_info.operations().begin(), operation_info.operations().end() }; const map<int32_t, PbOperationMetaData> operations = { operation_info.operations().begin(), operation_info.operations().end() };
cout << "Remote operations supported by rascsi and their parameters:" << endl; cout << "Remote operations supported by rascsi and their parameters:" << endl;
for (const auto& operation : operations) { for (const auto& operation : operations) {
cout << " " << operation.first; cout << " " << PbOperation_Name(operation.first);
if (!operation.second.description().empty()) { if (!operation.second.description().empty()) {
cout << " (" << operation.second.description().at("en") << ")"; cout << " (" << operation.second.description().at("en") << ")";
} }