protocolbuffers / protobuf

Protocol Buffers - Google's data interchange format
http://protobuf.dev
Other
64.47k stars 15.35k forks source link

Error parsing message with type 'AiServiceMsg' #16284

Open sathishiitd opened 3 months ago

sathishiitd commented 3 months ago

I am facing an issue in parsing Protobuf messages. The error says "Error parsing message with type 'AiServiceMsg'". my proto is as below syntax = "proto3"; message Bbox{ float x1=1; float y1=2; float x2=3; float y2=4; }

message AiServiceMsg{ string cameraId=1; string msgType=2; Bbox box=3; }

In my application, the protobuf message is created and serialized in C++ code. The serialized message is sent to RabbitMQ. A Python application is receiving the serialized protobuf message and trying to parse it.

C++ code is as below: void generate_dsmeta_message_protobuf() { AiServiceMsg ai_service_msg;

ai_service_msg.set_cameraid(camera_id);
ai_service_msg.set_msgtype("ObjectDetection");

Bbox* box = ai_service_msg.mutable_box(); box->set_x1(11); box->set_y1(11); box->set_x2(22); box->set_y2(22);

int size = ai_service_msg.ByteSize(); gchar* data = new gchar[size];

if (!ai_service_msg.SerializeToArray(data, size)) {
    cout << "generate_event_message_protobuf : Failed to serialize protobuf message to string.\n";
    message_len = 0;
    return ;
}

// data is sent to RabbitMQ return; } Python Code:

def pb_convert(self): try: for method, properties, body in self.channel.consume( self._queue_name, inactivity_timeout=1000 ): if body is not None:
msg = AiServiceMsg() print(body) try: msg.ParseFromString(body) print(msg.cameraId) print(msg.msgType) except Exception as err: print( err)

    except Exception as err:
        print(err)

In Python code, I received the below exception.
Error parsing message with type 'AiServiceMsg'

I can decode protobuf messages in C++ using the below code AiServiceMsg ai_msg; if (!ai_msg.ParseFromArray(data, size)) { cout << "Parsing failed\n"; } { std::lock_guard lock(mu); cout << ai_msg.cameraid() << " " << ai_msg.msgtype() << " " << ai_msg.box().x1() << " " << ai_msg.box().y1() << " " << ai_msg.box().x2() << " " << ai_msg.box().y2() << "\n"; }

Why I am not able to decode the protobuf message in Python

github-actions[bot] commented 1 week ago

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.

This issue is labeled inactive because the last activity was over 90 days ago.