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?

edmonds's user avatar
edmonds
372 bronze badges
askedJan 23, 2024 at 15:15
macchina001's user avatar
3
  • 1
    Protobuf usesUTF-8 encoding to pass strings. So if your string contains0xff 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.CommentedJan 23, 2024 at 15:34
  • Just to clarifystd::string data = results.SerializeAsString(); is not related to your problem.CommentedJan 23, 2024 at 15:42
  • You need to show the python code. More specifically, why are you trying to decode binary data as utf8?CommentedJan 24, 2024 at 9:21

0

Know someone who can answer? Share a link to thisquestion viaemail,Twitter, orFacebook.

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy 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.