Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[struct_pb][feat]to proto #702

Merged
merged 3 commits into from
Jul 2, 2024
Merged

Conversation

qicosmos
Copy link
Collaborator

@qicosmos qicosmos commented Jul 2, 2024

Why

  • improve dynamic reflection
  • support struct to proto

What is changing

Example

enum Color { Red = 0, Black = 2, Green = 4 };

namespace iguana {
template <>
struct enum_value<Color> {
  constexpr static std::array<int, 3> value = {0, 2, 4};
};

struct vector_t {
  int id;
  Color color;
  std::variant<int, pair_t, std::string> variant;
  std::vector<int> ids;
  std::vector<pair_t> pairs;
  std::vector<std::string> strs;
  std::map<std::string, pair_t> map;
  std::string name;
  std::optional<int> op_val;
};
REFLECTION(vector_t, id, color, variant, ids, pairs, strs, map, name, op_val);

void test() {
    std::string str;
    iguana::to_proto<vector_t>(str, "pb");
    std::cout << str;

    std::ofstream file("test_vector.proto", std::ios::binary);
    iguana::to_proto_file<vector_t>(file, "pb");
}
syntax = "proto3";

package pb;

option optimize_for = SPEED;

option cc_enable_arenas = true;

message vector_t {
  int32 id = 1;
  Color color = 2;
  oneof variant {
    int32  one_of_int32 = 3;
    pair_t  one_of_pair_t = 4;
    string  one_of_string = 5;
  }
  repeated  int32 ids = 6;
  repeated  pair_t pairs = 7;
  repeated  string  strs = 8;
  map<string, pair_t>  map = 9;
  string  name = 10;
  int32 op_val = 11;
}

message pair_t {
  int32 x = 1;
  int32 y = 2;
}

enum Color {
  Red = 0;
  Black = 2;
  Green = 4;
}

Copy link

github-actions bot commented Jul 2, 2024

Code Coverage Report
for detail, goto summary download Artifacts

Filename                                          Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
coro_io/channel.hpp                                      14                 0   100.00%         105                 3    97.14%          30                 2    93.33%
coro_io/client_pool.hpp                                  28                 0   100.00%         352                47    86.65%         106                35    66.98%
coro_io/coro_file.hpp                                    22                 2    90.91%         213                46    78.40%          56                21    62.50%
coro_io/coro_io.hpp                                      50                 1    98.00%         319                11    96.55%           6                 1    83.33%
coro_io/detail/client_queue.hpp                          10                 1    90.00%          47                 1    97.87%          10                 1    90.00%
coro_io/io_context_pool.hpp                              37                 5    86.49%         215                26    87.91%          28                 8    71.43%
coro_io/rate_limiter.hpp                                 13                 1    92.31%          85                 9    89.41%           8                 3    62.50%
coro_rpc/impl/common_service.hpp                          3                 0   100.00%          55                 0   100.00%          26                 7    73.08%
coro_rpc/impl/context.hpp                                 8                 0   100.00%         103                 6    94.17%          16                 6    62.50%
coro_rpc/impl/coro_connection.hpp                        45                10    77.78%         454                74    83.70%         112                38    66.07%
coro_rpc/impl/coro_rpc_client.hpp                        64                11    82.81%         701               117    83.31%         160                56    65.00%
coro_rpc/impl/coro_rpc_server.hpp                        21                 1    95.24%         237                29    87.76%          82                36    56.10%
coro_rpc/impl/errno.h                                    18                 4    77.78%          64                40    37.50%          36                16    55.56%
coro_rpc/impl/protocol/coro_rpc_protocol.hpp              9                 1    88.89%         101                32    68.32%          24                 9    62.50%
coro_rpc/impl/protocol/struct_pack_protocol.hpp           3                 0   100.00%          14                 0   100.00%           0                 0         -
coro_rpc/impl/router.hpp                                 22                 0   100.00%         221                13    94.12%          26                13    50.00%
coro_rpc/impl/rpc_execute.hpp                             3                 0   100.00%         172                 0   100.00%           4                 1    75.00%
easylog.hpp                                              17                 0   100.00%          73                 3    95.89%          14                 5    64.29%
easylog/appender.hpp                                     23                 0   100.00%         275                16    94.18%          90                25    72.22%
easylog/record.hpp                                       17                 0   100.00%         121                14    88.43%          16                 2    87.50%
struct_pack.hpp                                          35                 2    94.29%         320                28    91.25%          34                14    58.82%
struct_pack/alignment.hpp                                 9                 9     0.00%         136               136     0.00%           0                 0         -
struct_pack/calculate_size.hpp                           21                 5    76.19%         405                81    80.00%          32                 7    78.12%
struct_pack/compatible.hpp                                6                 0   100.00%           9                 0   100.00%           6                 2    66.67%
struct_pack/derived_helper.hpp                           14                 7    50.00%         127                61    51.97%           6                 3    50.00%
struct_pack/endian_wrapper.hpp                            9                 3    66.67%         152                28    81.58%           2                 1    50.00%
struct_pack/error_code.hpp                               11                 6    45.45%          38                30    21.05%           0                 0         -
struct_pack/foreach_macro.h                               1                 0   100.00%           1                 0   100.00%           0                 0         -
struct_pack/md5_constexpr.hpp                            27                 3    88.89%         174                18    89.66%          32                 1    96.88%
struct_pack/packer.hpp                                   23                 2    91.30%         495                20    95.96%          48                 9    81.25%
struct_pack/reflection.hpp                               17                10    41.18%        8605              5158    40.06%         514               251    51.17%
struct_pack/size_info.hpp                                 2                 0   100.00%          10                 0   100.00%           0                 0         -
struct_pack/trivial_view.hpp                              4                 0   100.00%          10                 0   100.00%           0                 0         -
struct_pack/tuple.hpp                                    21                 2    90.48%          54                 4    92.59%           6                 3    50.00%
struct_pack/type_calculate.hpp                           37                30    18.92%         753               576    23.51%           0                 0         -
struct_pack/type_id.hpp                                   4                 4     0.00%         277               277     0.00%           0                 0         -
struct_pack/unpacker.hpp                                 50                 5    90.00%        1296               141    89.12%         212                89    58.02%
struct_pack/user_helper.hpp                               6                 0   100.00%          63                 2    96.83%           2                 1    50.00%
struct_pack/util.h                                       12                 7    41.67%         105                61    41.90%           2                 0   100.00%
struct_pack/varint.hpp                                   23                 3    86.96%         147                14    90.48%          12                 3    75.00%
util/concurrentqueue.h                                   79                19    75.95%        1256               564    55.10%         292               148    49.32%
util/dragonbox.h                                         90                50    44.44%         735               388    47.21%          38                34    10.53%
util/dragonbox_to_chars.h                                 6                 1    83.33%         440               365    17.05%          54                43    20.37%
util/expected.hpp                                        93                 8    91.40%         248                38    84.68%          44                17    61.36%
util/function_name.h                                      2                 1    50.00%          22                 7    68.18%           0                 0         -
util/magic_names.hpp                                      1                 1     0.00%          56                56     0.00%           0                 0         -
util/meta_string.hpp                                     10                 3    70.00%          46                23    50.00%           8                 0   100.00%
util/time_util.h                                         21                12    42.86%         184               119    35.33%          26                 5    80.77%
util/type_traits.h                                        1                 0   100.00%           9                 0   100.00%           0                 0         -

Files which contain no functions:
struct_pack/marco.h                                       0                 0         -           0                 0         -           0                 0         -
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                  1062               230    78.34%       20100              8682    56.81%        2220               916    58.74%

Copy link

github-actions bot commented Jul 2, 2024

Code Coverage Report
for detail, goto summary download Artifacts

Filename                                          Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
coro_io/channel.hpp                                      14                 0   100.00%         105                 3    97.14%          30                 2    93.33%
coro_io/client_pool.hpp                                  28                 0   100.00%         352                51    85.51%         106                37    65.09%
coro_io/coro_file.hpp                                    22                 2    90.91%         213                46    78.40%          56                21    62.50%
coro_io/coro_io.hpp                                      50                 1    98.00%         319                11    96.55%           6                 1    83.33%
coro_io/detail/client_queue.hpp                          10                 1    90.00%          47                 1    97.87%          10                 1    90.00%
coro_io/io_context_pool.hpp                              37                 5    86.49%         215                26    87.91%          28                 8    71.43%
coro_io/rate_limiter.hpp                                 13                 1    92.31%          85                 9    89.41%           8                 3    62.50%
coro_rpc/impl/common_service.hpp                          3                 0   100.00%          55                 0   100.00%          26                 7    73.08%
coro_rpc/impl/context.hpp                                 8                 0   100.00%         103                 6    94.17%          16                 6    62.50%
coro_rpc/impl/coro_connection.hpp                        45                10    77.78%         454                74    83.70%         112                39    65.18%
coro_rpc/impl/coro_rpc_client.hpp                        64                11    82.81%         701               117    83.31%         160                56    65.00%
coro_rpc/impl/coro_rpc_server.hpp                        21                 1    95.24%         237                29    87.76%          82                36    56.10%
coro_rpc/impl/errno.h                                    18                 4    77.78%          64                40    37.50%          36                16    55.56%
coro_rpc/impl/protocol/coro_rpc_protocol.hpp              9                 1    88.89%         101                32    68.32%          24                 9    62.50%
coro_rpc/impl/protocol/struct_pack_protocol.hpp           3                 0   100.00%          14                 0   100.00%           0                 0         -
coro_rpc/impl/router.hpp                                 22                 0   100.00%         221                13    94.12%          26                13    50.00%
coro_rpc/impl/rpc_execute.hpp                             3                 0   100.00%         172                 0   100.00%           4                 1    75.00%
easylog.hpp                                              17                 0   100.00%          73                 3    95.89%          14                 5    64.29%
easylog/appender.hpp                                     23                 0   100.00%         275                16    94.18%          90                25    72.22%
easylog/record.hpp                                       17                 0   100.00%         121                14    88.43%          16                 2    87.50%
struct_pack.hpp                                          35                 2    94.29%         320                28    91.25%          34                14    58.82%
struct_pack/alignment.hpp                                 9                 9     0.00%         136               136     0.00%           0                 0         -
struct_pack/calculate_size.hpp                           21                 5    76.19%         405                81    80.00%          32                 7    78.12%
struct_pack/compatible.hpp                                6                 0   100.00%           9                 0   100.00%           6                 2    66.67%
struct_pack/derived_helper.hpp                           14                 7    50.00%         127                61    51.97%           6                 3    50.00%
struct_pack/endian_wrapper.hpp                            9                 3    66.67%         152                28    81.58%           2                 1    50.00%
struct_pack/error_code.hpp                               11                 6    45.45%          38                30    21.05%           0                 0         -
struct_pack/foreach_macro.h                               1                 0   100.00%           1                 0   100.00%           0                 0         -
struct_pack/md5_constexpr.hpp                            27                 3    88.89%         174                18    89.66%          32                 1    96.88%
struct_pack/packer.hpp                                   23                 2    91.30%         495                20    95.96%          48                 9    81.25%
struct_pack/reflection.hpp                               17                10    41.18%        8605              5158    40.06%         514               251    51.17%
struct_pack/size_info.hpp                                 2                 0   100.00%          10                 0   100.00%           0                 0         -
struct_pack/trivial_view.hpp                              4                 0   100.00%          10                 0   100.00%           0                 0         -
struct_pack/tuple.hpp                                    21                 2    90.48%          54                 4    92.59%           6                 3    50.00%
struct_pack/type_calculate.hpp                           37                30    18.92%         753               576    23.51%           0                 0         -
struct_pack/type_id.hpp                                   4                 4     0.00%         277               277     0.00%           0                 0         -
struct_pack/unpacker.hpp                                 50                 5    90.00%        1296               141    89.12%         212                89    58.02%
struct_pack/user_helper.hpp                               6                 0   100.00%          63                 2    96.83%           2                 1    50.00%
struct_pack/util.h                                       12                 7    41.67%         105                61    41.90%           2                 0   100.00%
struct_pack/varint.hpp                                   23                 3    86.96%         147                14    90.48%          12                 3    75.00%
util/concurrentqueue.h                                   79                19    75.95%        1256               569    54.70%         292               152    47.95%
util/dragonbox.h                                         90                50    44.44%         735               388    47.21%          38                34    10.53%
util/dragonbox_to_chars.h                                 6                 1    83.33%         440               365    17.05%          54                43    20.37%
util/expected.hpp                                        93                 8    91.40%         248                38    84.68%          44                17    61.36%
util/function_name.h                                      2                 1    50.00%          22                 7    68.18%           0                 0         -
util/magic_names.hpp                                      1                 1     0.00%          56                56     0.00%           0                 0         -
util/meta_string.hpp                                     10                 3    70.00%          46                23    50.00%           8                 0   100.00%
util/time_util.h                                         21                12    42.86%         184               119    35.33%          26                 5    80.77%
util/type_traits.h                                        1                 0   100.00%           9                 0   100.00%           0                 0         -

Files which contain no functions:
struct_pack/marco.h                                       0                 0         -           0                 0         -           0                 0         -
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                  1062               230    78.34%       20100              8691    56.76%        2220               923    58.42%

Copy link

github-actions bot commented Jul 2, 2024

Code Coverage Report
for detail, goto summary download Artifacts

Filename                                          Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
coro_io/channel.hpp                                      14                 0   100.00%         105                 3    97.14%          30                 2    93.33%
coro_io/client_pool.hpp                                  28                 0   100.00%         352                48    86.36%         106                36    66.04%
coro_io/coro_file.hpp                                    22                 2    90.91%         213                46    78.40%          56                21    62.50%
coro_io/coro_io.hpp                                      50                 1    98.00%         319                11    96.55%           6                 1    83.33%
coro_io/detail/client_queue.hpp                          10                 1    90.00%          47                 1    97.87%          10                 1    90.00%
coro_io/io_context_pool.hpp                              37                 5    86.49%         215                26    87.91%          28                 8    71.43%
coro_io/rate_limiter.hpp                                 13                 1    92.31%          85                 9    89.41%           8                 3    62.50%
coro_rpc/impl/common_service.hpp                          3                 0   100.00%          55                 0   100.00%          26                 7    73.08%
coro_rpc/impl/context.hpp                                 8                 0   100.00%         103                 6    94.17%          16                 6    62.50%
coro_rpc/impl/coro_connection.hpp                        45                10    77.78%         454                74    83.70%         112                39    65.18%
coro_rpc/impl/coro_rpc_client.hpp                        64                11    82.81%         701               117    83.31%         160                56    65.00%
coro_rpc/impl/coro_rpc_server.hpp                        21                 1    95.24%         237                29    87.76%          82                38    53.66%
coro_rpc/impl/errno.h                                    18                 4    77.78%          64                40    37.50%          36                16    55.56%
coro_rpc/impl/protocol/coro_rpc_protocol.hpp              9                 1    88.89%         101                32    68.32%          24                 9    62.50%
coro_rpc/impl/protocol/struct_pack_protocol.hpp           3                 0   100.00%          14                 0   100.00%           0                 0         -
coro_rpc/impl/router.hpp                                 22                 0   100.00%         221                13    94.12%          26                13    50.00%
coro_rpc/impl/rpc_execute.hpp                             3                 0   100.00%         172                 0   100.00%           4                 1    75.00%
easylog.hpp                                              17                 0   100.00%          73                 3    95.89%          14                 5    64.29%
easylog/appender.hpp                                     23                 0   100.00%         275                16    94.18%          90                25    72.22%
easylog/record.hpp                                       17                 0   100.00%         121                14    88.43%          16                 2    87.50%
struct_pack.hpp                                          35                 2    94.29%         320                28    91.25%          34                14    58.82%
struct_pack/alignment.hpp                                 9                 9     0.00%         136               136     0.00%           0                 0         -
struct_pack/calculate_size.hpp                           21                 5    76.19%         405                81    80.00%          32                 7    78.12%
struct_pack/compatible.hpp                                6                 0   100.00%           9                 0   100.00%           6                 2    66.67%
struct_pack/derived_helper.hpp                           14                 7    50.00%         127                61    51.97%           6                 3    50.00%
struct_pack/endian_wrapper.hpp                            9                 3    66.67%         152                28    81.58%           2                 1    50.00%
struct_pack/error_code.hpp                               11                 6    45.45%          38                30    21.05%           0                 0         -
struct_pack/foreach_macro.h                               1                 0   100.00%           1                 0   100.00%           0                 0         -
struct_pack/md5_constexpr.hpp                            27                 3    88.89%         174                18    89.66%          32                 1    96.88%
struct_pack/packer.hpp                                   23                 2    91.30%         495                20    95.96%          48                 9    81.25%
struct_pack/reflection.hpp                               17                10    41.18%        8605              5158    40.06%         514               251    51.17%
struct_pack/size_info.hpp                                 2                 0   100.00%          10                 0   100.00%           0                 0         -
struct_pack/trivial_view.hpp                              4                 0   100.00%          10                 0   100.00%           0                 0         -
struct_pack/tuple.hpp                                    21                 2    90.48%          54                 4    92.59%           6                 3    50.00%
struct_pack/type_calculate.hpp                           37                30    18.92%         753               576    23.51%           0                 0         -
struct_pack/type_id.hpp                                   4                 4     0.00%         277               277     0.00%           0                 0         -
struct_pack/unpacker.hpp                                 50                 5    90.00%        1296               141    89.12%         212                89    58.02%
struct_pack/user_helper.hpp                               6                 0   100.00%          63                 2    96.83%           2                 1    50.00%
struct_pack/util.h                                       12                 7    41.67%         105                61    41.90%           2                 0   100.00%
struct_pack/varint.hpp                                   23                 3    86.96%         147                14    90.48%          12                 3    75.00%
util/concurrentqueue.h                                   79                19    75.95%        1256               576    54.14%         292               160    45.21%
util/dragonbox.h                                         90                50    44.44%         735               388    47.21%          38                34    10.53%
util/dragonbox_to_chars.h                                 6                 1    83.33%         440               365    17.05%          54                43    20.37%
util/expected.hpp                                        93                 8    91.40%         248                38    84.68%          44                17    61.36%
util/function_name.h                                      2                 1    50.00%          22                 7    68.18%           0                 0         -
util/magic_names.hpp                                      1                 1     0.00%          56                56     0.00%           0                 0         -
util/meta_string.hpp                                     10                 3    70.00%          46                23    50.00%           8                 0   100.00%
util/time_util.h                                         21                12    42.86%         184               119    35.33%          26                 5    80.77%
util/type_traits.h                                        1                 0   100.00%           9                 0   100.00%           0                 0         -

Files which contain no functions:
struct_pack/marco.h                                       0                 0         -           0                 0         -           0                 0         -
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                  1062               230    78.34%       20100              8695    56.74%        2220               932    58.02%

@qicosmos qicosmos merged commit 3d46ee8 into alibaba:main Jul 2, 2024
31 checks passed
@qicosmos qicosmos deleted the struct_pb_to_proto branch July 2, 2024 07:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant