Discussion:
[protobuf] How does HasField works in Python bindings for protobuf
Robert Kuska
2016-04-20 11:13:27 UTC
Permalink
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?
--
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+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.
'Jie Luo' via Protocol Buffers
2016-04-22 22:08:46 UTC
Permalink
If you are using proto3, HasField is not supported for primitive types.
Post by Robert Kuska
message Fly{
uint32 dtime = 1;
}
d.ListFields()[0][0].name
'dtime'
d.ListFields()[0][0].full_name
'Fly.dtime
d.HasField('dtime')
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')
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?
--
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
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.
--
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+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.
Loading...