protocol buffers - protobuf-c: How to pack nested messages -
i have protobuf protocol file looks this:
message foo { message bar { required string name = 1; required string value = 2; } message baz { required bar = 1; } }
given protocol file, need write encoder using protobuf-c, c extension protobuf. wrote following code:
foo myfoo = foo__init; foo__bar mybar = foo__bar__init; foo__baz mybaz = foo__baz__init; mybaz.a = &mybar;
however, stuck @ point on how serialize mybaz
. generated struct foo, not contain entry can assign mybaz
to. , no method generated directly pack baz.
in python, lot more simpler, since mybaz.serializetostring()
function had been generated. how should go in c?
declaring nested types in protocol buffers declaring nested classes in c++ or static
inner classes in java. declares new type; not add field outer type. so, in proto schema, foo
empty message -- has no fields. true regardless of programming language you're working in.
probably meant this:
message foo { message bar { required string name = 1; required string value = 2; } message baz { required bar = 1; } optional baz baz = 1; }
now foo
has field called baz
can assign baz
object.
Comments
Post a Comment