-
Notifications
You must be signed in to change notification settings - Fork 232
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
feat: implement tool to convert proto to struct pb #323
feat: implement tool to convert proto to struct pb #323
Conversation
tool/README.md
Outdated
#pragma once | ||
#include <ylt/struct_pb.hpp> | ||
|
||
#define PUBLIC(T) : public iguana::base_impl<T> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不要用PUBLIC,使用完整的public iguana::base_impl。
另外可以增加一个参数:enable_reflection,如果设置为true,才从 iguana::base_impl派生。
默认情况下,不需要派生。
默认情况下构造函数也是不需要的,只有派生的时候才需要增加构造函数。
1. del reflection parameter 2. add inherit parameter. 3. only enable_inherit exist generator strurcture function.
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #323 +/- ##
==========================================
+ Coverage 45.64% 45.71% +0.07%
==========================================
Files 64 64
Lines 7582 7592 +10
==========================================
+ Hits 3461 3471 +10
Misses 4121 4121
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
把readme里面inherit 的两种情况都给个例子吧,看得清楚一点。 |
例子已经提供. 下面的多个文件的例子: 文件路径如下所示: ------------proto_dir 其中component.proto如下: syntax = "proto3";
option optimize_for = SPEED;
option cc_enable_arenas = true;
package import;
message CPU {
string Name = 1;
int64 Frequency = 2;
}
message Memory {
string Name = 1;
int64 Cap = 2;
} computer.proto如下: syntax = "proto3";
option optimize_for = SPEED;
option cc_enable_arenas = true;
package import;
import "proto_dir/component.proto";
message Computer {
string name = 1;
import.CPU cpu = 2;
import.Memory memory = 3;
}
此时执行: protoc --plugin=protoc-gen-custom=./build/proto_to_struct proto_dir/* --custom_out=add_optional:./protos 生成文件component.proto.h如下: #pragma once
#include <ylt/struct_pb.hpp>
struct CPU {
std::optional<std::string> Name;
int64_t Frequency;
};
YLT_REFL(CPU, Name, Frequency);
struct Memory {
std::optional<std::string> Name;
int64_t Cap;
};
YLT_REFL(Memory, Name, Cap);
computer.proto.h如下: #pragma once
#include <ylt/struct_pb.hpp>
struct Computer {
std::optional<std::string> name;
std::optional<CPU> cpu;
std::optional<Memory> memory;
};
YLT_REFL(Computer, name, cpu, memory);
可以看到生成的文件无误. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
proto file to struct pb.