Field number 0 is illegal.

Raise code
self._unknown_field_set = containers.UnknownFieldSet()
# pylint: disable=protected-access
unknown_field_set = self._unknown_field_set
# pylint: disable=protected-access
(tag, _) = decoder._DecodeVarint(tag_bytes, 0)
field_number, wire_type = wire_format.UnpackTag(tag)
if field_number == 0:
raise message_mod.DecodeError('Field number 0 is illegal.')
# TODO(jieluo): remove old_pos.
old_pos = new_pos
(data, new_pos) = decoder._DecodeUnknownField(
buffer, new_pos, wire_type) # pylint: disable=protected-access
if new_pos == -1:
return pos
# pylint: disable=protected-access
Links to the raise (1)
https://github.com/protocolbuffers/protobuf/blob/96ccf402fe8e62649f2be48a05944d552701aa5f/python/google/protobuf/internal/python_message.py#L1189Ways to fix
Protocol buffers are a language-neutral, platform-neutral extensible mechanism for serializing structured data. Protocol buffers are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data – think XML, but smaller, faster, and simpler. Here is the official website.
To download Protocol buffers for python, check here
When a message is encoded, the keys and values are concatenated into a byte stream. The "key" for each pair in a wire-format message is actually two values – the field number from your .proto
file, plus a wire type that provides just enough information to find the length of the following value. In most language implementations this key is referred to as a tag. ...
Here is an example of message protocol.
syntax = "proto2";
package tutorial;
message Person {
optional string name = 1;
optional int32 id = 2;
optional string email = 3;
enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
}
message PhoneNumber {
optional string number = 1;
optional PhoneType type = 2 [default = HOME];
}
repeated PhoneNumber phones = 4;
}
message AddressBook {
repeated Person people = 1;
}
Examples are taken here. To create your address book application, you'll need to start with a .proto
file. The definitions in a .proto
file is simple: you add a message for each data structure you want to serialize, then specify a name and a type for each field in the message. Here is the .proto
file that defines your messages, addressbook.proto
.
To compile protocol
protoc -I=$SRC_DIR --python_out=$DST_DIR $SRC_DIR/addressbook.proto
This generates addressbook_pb2.py
in your specified destination directory.
So, an error raises when we define our message protocol. Need to more precise about field numbers. Each field numbers need to be a unique and positive integer between 1-15.