The GitHub Actions job "Fory CI" on fory.git/main has succeeded.
Run started by GitHub user chaokunyang (triggered by chaokunyang).

Head commit for run:
b1725938d8bfc1ef2dd84b53c54018a8e853cdd6 / Shawn Yang <[email protected]>
feat(c++): support private fields of c++ class (#3193)

## Why?

The previous `FORY_FIELD_INFO` macro required defining field metadata
outside the class/struct definition, which prevented it from accessing
private fields. This limitation made it impossible to serialize classes
with private members unless they were made public or friends were added.

## What does this PR do?

This PR introduces a new `FORY_STRUCT` macro that must be used inside
the class/struct definition as a replacement for `FORY_FIELD_INFO`. The
key changes include:

1. **New `FORY_STRUCT` macro**: Replaces `FORY_FIELD_INFO` and must be
placed inside the struct/class body, enabling access to private fields
via hidden friend functions
2. **Hidden friend function approach**: Uses ADL (Argument-Dependent
Lookup) to define `ForyFieldInfo()` as a friend function within the
class, granting access to private members
3. **Backward compatibility**: Keeps `FORY_STRUCT_FIELDS` for internal
use and provides empty struct support via `FORY_STRUCT_EMPTY`
4. **Comprehensive migration**: Updates all usages across:
   - Test files (encoder, serialization, field tests)
   - Documentation (C++ row format guide, xlang spec)
   - Examples (hello_row example)
   - README files

**Migration pattern:**
```cpp
// Before:
class MyClass {
  int private_field;
};
FORY_FIELD_INFO(MyClass, private_field);  // Outside class, no access to private

// After:
class MyClass {
  int private_field;
  FORY_STRUCT(MyClass, private_field);  // Inside class, can access private
};
```

For external struct:

```cpp
namespace thirdparty {
struct Foo {
  int32_t id;
  std::string name;
};

FORY_STRUCT(Foo, id, name);
} // namespace thirdparty

auto fory = Fory::builder().build();
fory->register_struct<thirdparty::Foo>(1);
```

To include base-class fields in a derived type, list `FORY_BASE(Base)`
inside
`FORY_STRUCT`. The base must define its own `FORY_STRUCT` so its fields
can be
referenced.

```cpp
struct Base {
  int32_t id;
  FORY_STRUCT(Base, id);
};

struct Derived : Base {
  std::string name;
  FORY_STRUCT(Derived, FORY_BASE(Base), name);
};
```


## Related issues

#2906 

## Does this PR introduce any user-facing change?

Yes, this introduces a breaking API change requiring users to migrate
from `FORY_FIELD_INFO` to `FORY_STRUCT`.

- [x] Does this PR introduce any public API change?
- [ ] Does this PR introduce any binary protocol compatibility change?

## Benchmark

No performance impact expected - this is a compile-time macro change
that does not affect runtime serialization logic.

Report URL: https://github.com/apache/fory/actions/runs/21331556760

With regards,
GitHub Actions via GitBox


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to