From 115a8838d324ddc73814681dd0e04bc07bb9077c Mon Sep 17 00:00:00 2001 From: Lorenz Hruby Date: Sun, 29 Sep 2024 16:02:07 +0000 Subject: [PATCH] Add prefix. --- .../include/hephaestus/serdes/protobuf/enums.h | 12 ++++++------ .../proto/hephaestus/types/proto/dummy_type.proto | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/modules/serdes/include/hephaestus/serdes/protobuf/enums.h b/modules/serdes/include/hephaestus/serdes/protobuf/enums.h index 588d3039..dc61a623 100644 --- a/modules/serdes/include/hephaestus/serdes/protobuf/enums.h +++ b/modules/serdes/include/hephaestus/serdes/protobuf/enums.h @@ -34,16 +34,16 @@ template [[nodiscard]] auto getProtoPrefix() -> std::string { const auto enum_type_name = magic_enum::enum_type_name(); - // Underscores indicate nested proto enums, no underscore means it's a top-level proto enum. Top level enums - // do not have a prefix. + // Underscores indicate nested proto enums, no underscore indicates a top-level proto enum. if (const auto underscore_pos = std::find(enum_type_name.begin(), enum_type_name.end(), '_'); underscore_pos == enum_type_name.end()) { - return ""; + // Top-level enums use the enum name as a prefix: ENUM_NAME_ENUM_VALUE. + return utils::string::toScreamingSnakeCase(enum_type_name); } // Nested enums have a prefix, and enum values are separated by an underscore: // ClassName_EnumName_ENUM_VALUE. - return fmt::format("{}_", enum_type_name); + return fmt::format("{}", enum_type_name); } /// Convert between enums and their protobuf counterparts. The following convention is used: @@ -52,13 +52,13 @@ template /// enum class InternalEnum : { BAR1, BAR2 }; /// }; /// will have a protobuf counterpart -/// enum FooExternalEnum : { BAR1, BAR2 }; +/// enum FooExternalEnum : { FOO_EXTERNAL_ENUM_BAR1, FOO_EXTERNAL_ENUM_BAR2 }; /// enum Foo_InternalEnum : { Foo_InternalEnum_BAR1, Foo_InternalEnum_BAR2 }; template [[nodiscard]] auto getAsProtoEnum(T e) -> ProtoT { const auto proto_prefix = getProtoPrefix(); auto proto_enum_name = - fmt::format("{}{}", proto_prefix, magic_enum::enum_name(e)); // ClassName_EnumName_ENUM_VALUE + fmt::format("{}_{}", proto_prefix, magic_enum::enum_name(e)); // ClassName_EnumName_ENUM_VALUE auto proto_enum = magic_enum::enum_cast(proto_enum_name); heph::throwExceptionIf( diff --git a/modules/types_proto/proto/hephaestus/types/proto/dummy_type.proto b/modules/types_proto/proto/hephaestus/types/proto/dummy_type.proto index 02595fbc..dfae36d9 100644 --- a/modules/types_proto/proto/hephaestus/types/proto/dummy_type.proto +++ b/modules/types_proto/proto/hephaestus/types/proto/dummy_type.proto @@ -7,13 +7,13 @@ syntax = "proto3"; package heph.types.proto; enum DummyTypeExternalDummyEnum { - A = 0; - B = 1; - C = 2; - D = 3; - E = 4; - F = 5; - G = 6; + DUMMY_TYPE_EXTERNAL_DUMMY_ENUM_A = 0; + DUMMY_TYPE_EXTERNAL_DUMMY_ENUM_B = 1; + DUMMY_TYPE_EXTERNAL_DUMMY_ENUM_C = 2; + DUMMY_TYPE_EXTERNAL_DUMMY_ENUM_D = 3; + DUMMY_TYPE_EXTERNAL_DUMMY_ENUM_E = 4; + DUMMY_TYPE_EXTERNAL_DUMMY_ENUM_F = 5; + DUMMY_TYPE_EXTERNAL_DUMMY_ENUM_G = 6; } message DummyPrimitivesType {