Protobuf parsing

25 views
Skip to first unread message

Sumit Patil

unread,
Aug 7, 2023, 4:44:29 AM8/7/23
to Protocol Buffers

I am receiving a WatchEvent message and the value stored in this kubernetes proto is -

  1. Type - for ex. event such as modified or added or deleted
  2. Object - raw bytes of actual object. Can be any object.

I want to convert those raw bytes to actual objects such as pod. Note that I know the kind name of that RawExtension runtime object.

Currently I was doing this but result is negative -


if
( eventType == "ADDED" || eventType == "MODIFIED" ) { WatchEvent watch; watch.set_type( eventType ); string object = responseJson["object"].dump(); watch.mutable_object()->set_raw(object); cout << "Message" << endl; cout << watch.DebugString() << endl; Pod pod; JsonStringToMessage( watch.object().raw(), &pod ); cout << "Pod" << endl; cout << pod.DebugString() << endl; }

Sumit Patil

unread,
Aug 7, 2023, 4:45:52 AM8/7/23
to Protocol Buffers
if( eventType == "ADDED" || eventType == "MODIFIED" )
 WatchEvent watch; 
 watch.set_type( eventType ); 
 string object = responseJson["object"].dump(); 
 watch.mutable_object()->set_raw(object); 
 cout << "Message" << endl; 
 cout << watch.DebugString() << endl
 Pod pod; 
 JsonStringToMessage( watch.object().raw(), &pod ); 
 cout << "Pod" << endl;
 cout << pod.DebugString() << endl;
 }

Reply all
Reply to author
Forward
0 new messages