charley
charley

Reputation: 59

How to fill StringValue in protobuf in python

How to fill StringValue in protobuf (programming in python)

message event {
    string id = 1; 
    google.protobuf.StringValue test = 2;
}

Upvotes: 1

Views: 5683

Answers (3)

Nik Bhagat
Nik Bhagat

Reputation: 1

You can use StringValue constructor

from google.protobuf.wrappers_pb2 import StringValue

event(
  test=StringValue(value="test")
)

Upvotes: 0

previous_developer
previous_developer

Reputation: 11008

event.test.value = 'test'

Also works. It is more straightforward and doesn't require importing StringValue class.

Upvotes: 5

charley
charley

Reputation: 59

After fighting for a while found the answer

event.test.CopyFrom(wrappers.StringValue(value='test'))

Upvotes: 4

Related Questions