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_pack] add config DISABLE_ALL_META_INFO #488

Merged
merged 6 commits into from
Nov 9, 2023

Conversation

poor-circle
Copy link
Collaborator

Why

now we can disable all meta info include hash code to reduce binary size

What is changing

Example

struct rect {
  var_int a, b, c, d;
  bool operator==(const rect& o) const {
    return a == o.a && b == o.b && c == o.c && d == o.d;
  }
};

//clang-format off
void serialize_config() {
  // serialize with config
  rect r{1, -1, 0, 5};
  auto buffer =
      struct_pack::serialize<struct_pack::DISABLE_ALL_META_INFO>(
          r);
  // only need 4 bytes
  assert(buffer.size() == 4);
  // deserialize with config
  auto result =
      struct_pack::deserialize<struct_pack::DISABLE_ALL_META_INFO, rect>(
          buffer);
  assert(result.value() == r);
}

// or, you can also use ADL helper function to config it. this function should
// in the same namespace of type
inline constexpr struct_pack::sp_config set_sp_config(rect*) {
  return struct_pack::DISABLE_ALL_META_INFO;
}

void serialize_config_by_ADL() {
  // serialize with config
  rect r{1, -1, 0, 5};
  auto buffer = struct_pack::serialize(r);
  // only need 4 bytes
  assert(buffer.size() == 4);
  // deserialize with config
  auto result = struct_pack::deserialize<rect>(buffer);
  assert(result.value() == r);
}

@poor-circle poor-circle merged commit ae6abd1 into alibaba:main Nov 9, 2023
30 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.

2 participants