Search code examples
pythonprotocol-buffers

How to access unknown fields in python protobuf version 5.38.3 with upb backend


I'm using Python protobuf package version 5.38.3 for deserializing some packets and I need to check if the messages I deserialize are conformant or not to a specific protobuf message structure. For some checks I want to obtain the list of unknown fields.

This post points to an API UnknownFields() supported by messages, but when I call it in a deserialized message it raises NotImplementedError.

How can I get access to the list of unknown fields from a deserialized message in protobuf 5.28.3?


Solution

  • How can I get access to the list of unknown fields

    Here, let me google that for you.

    https://protobuf.dev/news/2023-08-15

    Python Breaking Change

    In v25 message.UnknownFields() will be deprecated in pure Python and C++ extensions. It will be removed in v26. Use the new UnknownFieldSet(message) support in unknown_fields.py as a replacement.

    You will want to update your code to use the new public API.