Currently C++ structs with primitive std::optional members (ints, bools, floats) cannot easily by mapped to Cap’n Proto structs because Cap’n Proto does not provide a way to leave primitive fields unset, so there isn’t a natural way to represent std::nullopt values. This PR makes it possible to map C++ structs with fields like:
0 std::optional<int> foo;
to Cap’n Proto structs by using extra Bool fields prefixed with “has” for primitive optional members:
0 foo [@3](/bitcoin-core-multiprocess/contributor/3/) :Int32;
1 hasFoo [@4](/bitcoin-core-multiprocess/contributor/4/) :Bool;
Boolean “has” fields were already supported by the code generator and used to pass primitive std::optional parameters and return values, so this PR just extends it work with all struct fields, not just fields in params and result structs.
Note: Motivation for this change is dealing with the CreatedTransactionResult::change_pos field introduced to the wallet interface in bitcoin-core/gui#807. This also could have been useful in https://github.com/bitcoin/bitcoin/pull/33965#issuecomment-3937522269