Hi,
i am using C++11.
my problem is, i am not able to add required field to repeated message.

.Proto
message HDPMsg
{
   required MsgHeaderSig messageHeader = 1;
   optional int64 tag = 18999;
}
message InfusionEventContainer
{
   repeated InfusionEventSig infusionOngoingEvents = 5;
   optional int64 tag = 18999;
}

message InfusionEventSig
{
   required MsgHeaderSig messageHeader = 1;
   optional int64 tag = 18999;
}

.cpp
void buildMessage(HdpMain &rHdpMain)
{
   HDPMsg hdp5;
   MsgHeaderSig header;
   InfusionEventContainer container;
   InfusionEventSig infusionOngoingEvents;


   header.set_timestamp(time(NULL));
   header.set_sourceid(MSG_SOURCE_UIC);


   hdp5.set_allocated_messageheader(&header);
   hdp5.set_eventtype(INFUSION_UPDATE);

   container.set_allocated_messageheader(&header);

   infusionOngoingEvents.set_allocated_messageheader(&header);

   container.add_infusionongoingevents();  // here i am getting error when 
running code.Error: header not set.

   hdp5.set_allocated_infusionevents(&container);

printf("is infusionongoingevents IsInitialized after= %d\n", 
hdp5.infusionevents().infusionongoingevents(0).IsInitialized()); // giveng 
me value 0(not set).
// if i use printf("is infusionongoingevents IsInitialized after= 
%d\n",infusionOngoingEvents.IsInitialized()); // giving me value 1(set).

   hdp5.release_messageheader();
   hdp5.release_infusionevents();

   container.release_messageheader();
   container.clear_infusionongoingevents();
   container.release_shifttotals();

   infusionOngoingEvents.release_messageheader();
 
}

Error: [libprotobuf FATAL google/protobuf/message_lite.cc:231] CHECK 
failed: IsInitialized(): Can't serialize message of type 
"com.silver.hdp5signals.mdcodegen.signals.HDPMsg" because it is missing 
required fields: infusionEvents.infusionOngoingEvents[0].messageHeader


your help will be appreciated.

Thank you.
Krishna.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/7cd8c092-5b00-4267-8a0c-ee82a33efcbe%40googlegroups.com.

Reply via email to