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] std::out_of_range: unknown key #710

Open
1 of 2 tasks
PikachuHyA opened this issue Jul 8, 2024 · 0 comments
Open
1 of 2 tasks

[struct_pb] std::out_of_range: unknown key #710

PikachuHyA opened this issue Jul 8, 2024 · 0 comments

Comments

@PikachuHyA
Copy link
Collaborator

Search before asking

  • I searched the issues and found no similar issues.

What happened + What you expected to happen

support unknown

Reproduction way


struct person : struct_pb::base_impl<person> {
  int age;
  std::string name;
};
struct person2 : struct_pb::base_impl<person2> {
  int age;
  std::string name;
  int salary;
};
REFLECTION(person, age, name);
REFLECTION(person2, age, name, salary);
int main() {
  person p1{};
  p1.age = 100;
  p1.name = "abc";
  std::string s;
  struct_pb::to_pb(p1, s);
  person2 p2{};
  struct_pb::from_pb(p2, s);
  std::cout << p2.age << std::endl;
  std::cout << p2.name << std::endl;
  std::cout << p2.salary << std::endl;
  p2.salary = 1000;
  struct_pb::to_pb(p2, s);
  person p3{};
  struct_pb::from_pb(p3, s);
  std::cout << p3.age << std::endl;
  std::cout << p3.name << std::endl;
  return 0;
}

got error

100
abc
0
libc++abi: terminating due to uncaught exception of type std::out_of_range: unknown key

Anything else

Are you willing to submit a PR?

  • Yes I am willing to submit a PR!
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

No branches or pull requests

1 participant