problem in adding required field to repeated message

27 views
Skip to first unread message

GopiKrishna Parisa

unread,
Nov 13, 2019, 7:40:52 AM11/13/19
to Protocol Buffers
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.
Reply all
Reply to author
Forward
0 new messages