I posted this on stackoverflow as well...will update each if I find an answer.
As someone pointed out... status_cd should not be a float but that is not the root of my issues. *** <http://stackoverflow.com/questions/18391290/how-to-encode-nested-python-protobuf#> Been stumped on this for a while and pulling what is left of my hair out. Sending non-nested Protobufs from Python to Java and Java to Python without an issue with WebSockets. My problem is sending a nested version over a WebSocket. I believe my issue is on the Python encoding side. Your guidance is appreciated. .proto file message Response { // Reflect back to caller required string service_name = 1; // Reflect back to caller required string method_name = 2; // Who is responding required string client_id = 3; // Status Code required StatusCd status_cd = 4; // RPC response proto optional bytes response_proto = 5; // Was callback invoked optional bool callback = 6 [default = false]; // Error, if any optional string error = 7; //optional string response_desc = 6;} message HeartbeatResult { required string service = 1; required string timestamp = 2; required float status_cd = 3; required string status_summary = 4;} enum StatusCd { // Server-side errors OK = 1; BAD_REQUEST_DATA = 2; // Server received bad request data BAD_REQUEST_PROTO = 3; // Server received bad request proto SERVICE_NOT_FOUND = 4; // Service not found on server METHOD_NOT_FOUND = 5; // Method not found on server RPC_ERROR = 6; // Rpc threw exception on server RPC_FAILED = 7; // Rpc failed on server // Client-side errors (these are returned by the client-side code) INVALID_REQUEST_PROTO = 8; // Rpc was called with invalid request proto BAD_RESPONSE_PROTO = 9; // Server returned a bad response proto UNKNOWN_HOST = 10; // Could not find supplied host IO_ERROR = 11; // I/O error while communicating with server } A Heartbeat result is supposed to get sent in the reponse_proto field of the Response Protobuf. I am able to do this in Java to Java but Python to Java is not working. I've included two variations of the python code. Neither of which works. def GetHeartbeat(self): print "GetHeartbeat called" import time ts = time.time() import datetime st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') heartbeatResult = rpc_pb2.HeartbeatResult() heartbeatResult.service = "ALERT_SERVICE" heartbeatResult.timestamp = st heartbeatResult.status_cd = rpc_pb2.OK heartbeatResult.status_summary = "OK" response = rpc_pb2.Response() response.service_name = "" response.method_name = "SendHeartbeatResult" response.client_id = "ALERT_SERVICE" response.status_cd = rpc_pb2.OK response.response_proto = str(heartbeatResult).encode('utf-8') self.sendMessage(response.SerializeToString()) print "GetHeartbeat finished" def GetHeartbeat2(self): print "GetHeartbeat called" import time ts = time.time() import datetime st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') heartbeatResult = rpc_pb2.HeartbeatResult() heartbeatResult.service = "ALERT_SERVICE" heartbeatResult.timestamp = st heartbeatResult.status_cd = rpc_pb2.OK heartbeatResult.status_summary = "OK" response = rpc_pb2.Response() response.service_name = "" response.method_name = "SendHeartbeatResult" response.client_id = "ALERT_SERVICE" response.status_cd = rpc_pb2.OK response.response_proto = heartbeatResult.SerializeToString() self.sendMessage(response.SerializeToString()) print "GetHeartbeat finished" Errors on the Java server side are: (GetHeartbeat) Protocol message end-group tag did not match expected tagand(GetHeartbeat2)Message: [org.java_websocket.exceptions.InvalidDataException: java.nio.charset.MalformedInputException: Input length = 1 at org.java_websocket.util.Charsetfunctions.stringUtf8(Charsetfunctions.java:80) at org.java_websocket.WebSocketImpl.deliverMessage(WebSocketImpl.java:561) at org.java_websocket.WebSocketImpl.decodeFrames(WebSocketImpl.java:328) at org.java_websocket.WebSocketImpl.decode(WebSocketImpl.java:149) at org.java_websocket.server.WebSocketServer$WebSocketWorker.run(WebSocketServer.java:593)Caused by: java.nio.charset.MalformedInputException: Input length = 1 at java.nio.charset.CoderResult.throwException(CoderResult.java:277) at java.nio.charset.CharsetDecoder.decode(CharsetDecoder.java:798) at org.java_websocket.util.Charsetfunctions.stringUtf8(Charsetfunctions.java:7 -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/protobuf. For more options, visit https://groups.google.com/groups/opt_out.
