Reading into Protocol Buffer Basics: C++, found nothing that matches the situation:; with following .proto processed with --cpp_out,
message A {
required int32 foo = 1;
}
message B {
optional A data = 1;
}
no obviously looking accessor/setter is generated to set custom optional field (including ‘nested types’ section which I’m too lazy to put here):
// accessors -------------------------------------------------------
// optional .A = 1;
inline bool has_a() const;
inline void clear_a();
static const int kAFieldNumber = 1;
inline const ::A& a() const;
inline ::A* mutable_a();
inline ::A* release_a();
So, how to set B::A to some A instance in C++?
TEST FILES: .proto, generated results: .h, .cc and some .java
Upd: in Java, nested fields are set via Builder: see link above for example (look for setData).
Solution: use mutable to modify some returned doodad.