Hi Matthew,
When you read the serverInfoResp you need to read the header to find the
length of the response message. The header is 5-bytes - 4-bytes of
length and 1-byte of message code. You should just use the parseFrom
calls - not the parseFromDelimited ones.
Please excuse my java - I haven't done any in a long time (a quick
googling couldn't find what to use for ntohl)
byte[] hdr = in.readRawBytes(5);
int msgLen = (hdr[0] << 24) + (hdr[1] << 16) + (hdr[2] << 8) +
hdr[3]; // ntohl
byte msgCode = hdr[4];
byte[] resp = in.readRawBytes(msgLen);
RpbGetServerInfoResp serverInfoResp =
RpbGetServerInfoResp.parseFrom(resp)
Jon
On 4/19/10 3:33 PM, Matthew Pflueger wrote:
Hi,
I’m having issues using the protobuf stuff. Writing/reading bytes
directly to/from the socket works but using the protoc generated Java
message builders either gives me nothing useful back or throws invalid
protocol exceptions. I’ve never used the protobuf stuff before so
maybe I’m doing something stupid...
First I modified the riakclient.proto file inserting a package
declaration: option java_package = "<your package goes here>";
protoc -I=. --java_out=./src riakclient.proto
//ping
out.writeRawBytes(new byte[] {0, 0, 0, 1, 1});
out.flush();
//pong {0, 0, 0, 1, 2}
byte[] bytes = in.readRawBytes(5);
assert bytes[4] == 2;
//get server info
out.writeRawBytes(new byte[] {0, 0, 0, 1, 7});
out.flush();
RpbGetServerInfoResp serverInfoResp =
RpbGetServerInfoResp.parseDelimitedFrom(socket.getInputStream());
System.out.println("Connected to: " +
serverInfoResp.getNode().toStringUtf8());//toString());
parseDelimitedFrom doesn't throw an error but I get nothing back...
Using parseFrom I get an error... Any help would be appreciated...
--Matthew
_______________________________________________
riak-users mailing list
riak-users@lists.basho.com
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
_______________________________________________
riak-users mailing list
riak-users@lists.basho.com
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com