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

feat: implement tool to convert proto to struct pb #323

Merged
merged 6 commits into from
Nov 21, 2024

Conversation

helintongh
Copy link
Contributor

proto file to struct pb.

tool/README.md Outdated
#pragma once
#include <ylt/struct_pb.hpp>

#define PUBLIC(T) : public iguana::base_impl<T>
Copy link
Owner

@qicosmos qicosmos Nov 12, 2024

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派生。
默认情况下,不需要派生。
默认情况下构造函数也是不需要的,只有派生的时候才需要增加构造函数。

@helintongh helintongh requested a review from qicosmos November 14, 2024 11:14
1. del  reflection parameter
2. add inherit parameter.
3. only enable_inherit exist generator strurcture function.
@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 45.71%. Comparing base (631e537) to head (2a2ed33).
Report is 14 commits behind head on master.

❗ 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              
Flag Coverage Δ
?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@qicosmos
Copy link
Owner

把readme里面inherit 的两种情况都给个例子吧,看得清楚一点。

@helintongh
Copy link
Contributor Author

把readme里面inherit 的两种情况都给个例子吧,看得清楚一点。

例子已经提供.

下面的多个文件的例子:

文件路径如下所示:

------------proto_dir
|---------component.proto
|---------computer.proto

其中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);

可以看到生成的文件无误.

Copy link
Owner

@qicosmos qicosmos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@qicosmos qicosmos merged commit 1f99cb2 into qicosmos:master Nov 21, 2024
18 checks passed
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.

3 participants