c++ - Protocol buffer extension not recognised on OSX -
c++ - Protocol buffer extension not recognised on OSX -
i have protocol buffers protocol defined follows:
package pkg; message query { optional uint32 basicfield = 1; extensions 100 max; } message point { optional int32 x = 1; optional int32 y = 2; } message specificquery { oneof specific_oneof { point centre = 1000; point corner = 2000; } extend pkg.query { optional specificquery specific_query = 101; } }
i using protocol buffers 2.6.1rc1 (and have tested 2.6.0), since want seek utilize oneof
feature. 64-bit c++. make check
passes on both platforms. if send , receive both on linux (compiling gcc 4.6.3), seems work fine. if receive 1 mac (osx 10.9, compiling clang under xcode), however, not seem recognise extensions.
this receiving code:
if (query.parsefromarray(array, len)) { if (query.has_basicfield()) { printf("basicfield: %d", query.basicfield()); } if (query.hasextension(pkg::specificquery::specific_query)) { // never reached on osx // reached on linux pkg::specificquery* sqy = query.mutableextension(pkg::specificquery::specific_query); if (sqy && sqy->specific_oneof_case() == pkg::specificquery::kcentre) { // reached on linux } } }
if print protocol buffer object printdebugstring()
, this, expected on linux:
basicfield: 1234 [pkg.specificquery.specific_query] { centre { x: 50 y: 150 } }
but on mac, see:
basicfield: 1234 101 { 1000 { 1: 50 2: 150 } }
moreover, query._extensions_
empty, query._unknown_fields_
contains 101
, indicating extension registry seems not working. know why?
somehow, definition of specificquery::specific_query
not beingness linked app. compiler smart has managed optimize away calls made protobufs, , linker smart managed drop whole object file output program. if .pb.o
somehow doesn't linked program, initializers never run, hence extensions defines never registered, , you'll see behavior you're seeing.
one way forcefulness linkage place dummy usage within other code know getting linked in. example, add together line function posted:
specificquery::default_instance();
this function phone call has no side effect, implemented in .pb.cc
file , forcefulness .pb.o
linked.
c++ encoding cross-platform protocol-buffers messages
Comments
Post a Comment