I believe Chris's suggestion was to base64-encode the full message,
not the subproto, or you'll run into other problems down the line,
since it sounds like your transport can't handle arbitrary byte
IOW, something like
response.response_proto = heartbeatResult.SerializeToString()
Or even better, stick the b64encode into sendMessage itself (and
matching b64decode in the receive logic). But best still would be to
figure out why your transport doesn't seem to be handling arbitrary
On Wed, Sep 25, 2013 at 1:24 PM, <chrisg...@gmail.com> wrote:
> Your suggestion of trying base64 worked on the nested
> protobuf. Thanks to you and Llia again for taking the time to
> share your thoughts.
> Here is the solution that ended up working with the websocket
> server that I'm using.
> def GetHeartbeat(self):
> print "GetHeartbeat called"
> heartbeatResult = rpc_pb2.HeartbeatResult()
> heartbeatResult.service = "ALERT_SERVICE"
> heartbeatResult.timestamp = self.getTimestamp()
> 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 =
> print "GetHeartbeat finished"
> On Tuesday, August 27, 2013 12:12:30 PM UTC-7, Christopher Head wrote:
>> On Mon, 26 Aug 2013 17:32:23 -0700 (PDT)
>> chri...@gmail.com wrote:
>> > Thanks for taking the time to read/reply.
>> > GetHeartbeat2 is my original version which I included as well and the
>> > way I had thought it should probably work. This code is serializing
>> > to string
>> > on the inner buffer and then again on the outer.
>> > response.response_proto = heartbeatResult.SerializeToString()
>> > self.sendMessage(response.SerializeToString())
>> > The GetHeartbeat2 generates this error on the server ( I included
>> > more of the stack trace this time)
>> > 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:77)
>> This stack trace suggests you’re still involving UTF-8 somewhere, this
>> time on the Java side (java.nio.charset, stringUtf8 method name, etc.).
>> Again, an encoded Protobuf message is a BYTE STRING. You should not be
>> doing UTF-8 things, or any other text-related things, to it. I have no
>> idea how Websockets work, but if they are not capable of transporting
>> byte strings directly (if they only carry text, for example), then you
>> will have to do further encoding on your Protobuf message—Base64 might
>> be suitable here.
> 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 protobuf+unsubscr...@googlegroups.com.
> To post to this group, send email to email@example.com.
> Visit this group at http://groups.google.com/group/protobuf.
> For more options, visit https://groups.google.com/groups/opt_out.
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 post to this group, send email to firstname.lastname@example.org.
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/groups/opt_out.