Generally this way has code duplication (variable name == its value) and bad typing (in string might be everything). Maybe there is also performance/memory issues, but most probably they are insignificant
So far I have 3 ideas for solving it issue (feel free to propose new one). The first two use additional strings as it is, the last one is prefer depend on the protobuf (thus less transport-agnostic, but more stable).
All the ways describe how define enum Permission, and related toString & fromString functions. Imo that should be enough for replacing (am I missing smth?).
p.s code may cause compile-errors, consider as pseudo-code
Macros. Yes, they are considered evilish but the solution is the most compact and has no code duplication at all.
New permission -> 1 LOC
Constexpr maps, a lot of code duplication but compile-time (-> prob less error-prone), need to write function str -> enum (idk how to do it via templates). It is roughly same to the case enum+pair of methods, I don't show this case, because constexpr-maps is a bit better (for toString)
New permission -> 4 LOC (enum + PermMap::s (x2) + fromString's map)
Depend on the protobuf, the most elegant way. The only problem that it highly depend on the transport so imo it is a bad thing to use. Also protobuf uses enum (NOT enum class, so weak typing might be a huge problem in future)
New permission -> 0 LOC
Though protobuf updates may need some fixes
So far permissions are still used from the old model and represented via hard-coded strings: https://github.com/hyperledger/iroha/blob/c3b1a743e977de8a517b754eb727d7b9b997545d/irohad/model/permissions.hpp#L34-L48
And its usage (e.g in itf) is not really good as it might be: https://github.com/hyperledger/iroha/blob/c3b1a743e977de8a517b754eb727d7b9b997545d/test/framework/integration_framework/integration_test_framework.cpp#L80-L83
Generally this way has code duplication (variable name == its value) and bad typing (in string might be everything). Maybe there is also performance/memory issues, but most probably they are insignificant
So far I have 3 ideas for solving it issue (feel free to propose new one). The first two use additional strings as it is, the last one is prefer depend on the protobuf (thus less transport-agnostic, but more stable). All the ways describe how define
enum Permission
, and relatedtoString
&fromString
functions. Imo that should be enough for replacing (am I missing smth?).p.s code may cause compile-errors, consider as pseudo-code
enum
(NOTenum class
, so weak typing might be a huge problem in future) New permission -> 0 LOC Though protobuf updates may need some fixes