How does HasField works in Python bindings for protobuf

268 views
Skip to first unread message

Robert Kuska

unread,
Apr 22, 2016, 4:34:44 PM4/22/16
to Protocol Buffers
Consider following code:

message Fly{
 uint32 dtime = 1;
}

>>> d.ListFields()[0][0].name
'dtime'
>>> d.ListFields()[0][0].full_name
'Fly.dtime
>>> 
>>> d.HasField('dtime')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/rkuska/.local/lib/python2.7/site-packages/google/protobuf/internal/python_message.py", line 825, in HasField
    raise ValueError(error_msg % field_name)
ValueError: Protocol message has no non-repeated submessage field "dtime_utc"
>>> d.HasField('Fly.dtime')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/rkuska/.local/lib/python2.7/site-packages/google/protobuf/internal/python_message.py", line 825, in HasField
    raise ValueError(error_msg % field_name)
ValueError: Protocol message has no non-repeated submessage field "Flight.dtime_utc"

What does HasField expect as a parameter?


Jie Luo

unread,
Apr 22, 2016, 6:08:49 PM4/22/16
to Robert Kuska, Protocol Buffers
If you are using proto3, HasField is not supported for primitive types.

--
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 protobuf+u...@googlegroups.com.
To post to this group, send email to prot...@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages