0

I have define my protobuf message that is serialize in CPP and send to Python program thank to a wrapper. On CPP side, the protobuf message is generate as std::string

Here is how I generate in cpp my message:

  ....
  std::string data = results.SerializeAsString();
  return data;

In Python, I just connect my CPP wrapper and I try to get the string message. With a common message, the communication between CPP and Python works properly but with the protobuf serialized message, I get that error:

'utf-8' codec can't decode byte 0xff in position 13: invalid start byte

Is there a way to encore in CPP the string message to be readable in Python?

3
  • 1
    Protobuf uses UTF-8 encoding to pass strings. So if your string contains 0xff and it is not BOM in front of it it is invalid UTF-8 encoding. So sender side had to use string which is not UTF-8 encoded. You should show code which writes some string value into class generated protobuf. Commented Jan 23, 2024 at 15:34
  • Just to clarify std::string data = results.SerializeAsString(); is not related to your problem. Commented Jan 23, 2024 at 15:42
  • You need to show the python code. More specifically, why are you trying to decode binary data as utf8? Commented Jan 24, 2024 at 9:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.