Hi,

I heard about this google protobuf stuff for the first time when I was 
assigned a project. Did some reading and when I went to add some variable 
in the google message structure, no setters were generated for this new 
variable. After doing extensive research, I thought I need to use mutable() 
instead. But when I try to call this function within my class, compiler 
complains. I am enclosing my code snapshot if it helps.  Thank you very 
much for your time.


###################################################################
File:  *Base.proto   *

message Data1 {               

                optional string A1 = 1;

                optional string A2 = 2;

                optional string A3 = 3;

                //here x,y, z are different namespaces.  

                optional x::y::z::*RegionData  regiondata1* = 4;  //new 
variable added...  //RegionData is enum defined in some other class.

}

 

In my class  Foo

--------------------------------

File:  Foo.hpp

-------------------------------


Class Foo {

   Data1 instance1;  

 

}


--------------------------------------

File:   Foo.cpp

---------------------------------------

Void Foo :: initialize() {

       int regiondata = 0;


       //trying to set the value of  region;

       //get the region value from some other source.


       //call protobuf method to set the value..

      
 instance1.mutable_regiondata1()->set_allocated_regiondata(&regionData);    
           //compile error ...not able to recognize this function 

}

 

*Note:*

//compile fails saying class Data1 has no member named mutable_regiondata1()

///There are no regular setter functions generated for this  variable. 

//So after doing extensive research, I came to the conclusion that I need 
to use this way. Not sure what I am doing wrong here.

//Any pointers to help me out is highly appreciated since I am running 
closer to deadline.

 

This is the  generated   *Base.pb.cc* file

******************************************************

 

// optional .x.y.z.RegionData  regionData1  = 4;


bool Data1::has_ regionData1 () const {

 return (_has_bits_[0] & 0x00400000u) != 0;

}


void Data1::set_has_ regionData1 () {

   _has_bits_[0] |= 0x00400000u;

}


void Data1::clear_has_ regionData1 () {

   _has_bits_[0] &= ~0x00400000u;

}


void Data1::clear_ regionData1 () {

   if (regionData1_ != NULL) regionData1_->::x::y::z::RegionData::Clear();

   clear_has_regionData1();

}


const ::x::y::z::RegionData& Data1:: regionData1 () const {

   // @@protoc_insertion_point(field_get:x.y.z.core.Data1.regiondata1)

   return regionData1_ != NULL ? *regionData1_

                         : 
*::x::y::z::RegionData::internal_default_instance();

}


::x::y::z::RegionData* Data1::*mutable_ regiondata1* () {

   set_has_regionData1();

   if (regionData1_ == NULL) {

    regionData1_ = new ::x::y::z::RegionData;

   }

   // @@protoc_insertion_point(field_mutable:x.y.z.core.Data1.regiondata1)

   return regionData1_;

}


::x::y::z::RegionData* Data1::release_regionData1() {

   // @@protoc_insertion_point(field_release:x.y.z.core.Data1.regiondata1)

   clear_has_regionData1();

   ::x::y::z::RegionData* temp = regionData1_;

   regiondata1_ = NULL;

   return temp;

}


void Data1::set_allocated_regiondata1(::x::y::z::RegionData* regiondata1) {

  delete regiondata1_;

  regionData1_ = regiondata1;


  if (regiondata1) {

    set_has_regiondata1();

  } else {

    clear_has_regiondata1();

  }

  // 
@@protoc_insertion_point(field_set_allocated:x.y.z.core.Data1.regiondata1)

}

 

#endif  // PROTOBUF_INLINE_NOT_IN_HEADERS

###################################################################


-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to