java - Protobuf Doubles Serializing as Null Bytes -


i have created simple java class using google protobuf 2.6.1, following structure:

required int64 tid = 1; required int64 tid = 1; required string clordid = 2; required string execid = 3; required string tickettype = 4; optional string lastmkt = 5; required double lastqty = 6; required double cumqty = 7; required double lastpx = 8; required double avgpx = 9; optional string lastcapacity = 10; required int64 transactiontime = 11; required int64 reporttime = 12; 

after building class , populating these fields test data, converting byte array using .tobytearray() method:

double d = 99.0; fillproto fillproto = fillproto.newbuilder()                         .settid(n)                         .setclordid("clordid")                         .setexecid("execid")                         .settickettype("tickettype")                         .setlastmkt("lastmkt")                         .setlastqty(d)                         .setcumqty(d)                         .setlastpx(d)                         .setavgpx(d)                         .setlastcapacity("lastcapacity")                         .settransactiontime(now.gettime())                         .setreporttime(now.gettime())                         .build();  log.info(class_,method_,"sending through:\n" + new string(fillproto.tobytearray())); 

i sending bytearray through solace queue, , after consuming on other side, try build object using fillproto.parsefrom(byte[]) error: "while parsing protocol message, input ended unexpectedly in middle of field.". bytearray seems fine, until fields marked double, outputting null (00 bytes). know what's happening here?

byte array below:

  08 05 12 07 63 6c 4f 72    64 49 44 1a 06 65 78 65    ....clordid..exe   63 49 44 22 0a 74 69 63    6b 65 74 54 79 70 65 2a    cid".tickettype*   07 6c 61 73 74 4d 6b 74    31 00 00 00 00 00 c0 58    .lastmkt1......x   40 39 00 00 00 00 00 c0    58 40 41 00 00 00 00 00    @9......x@a.....   c0 58 40 49 00 00 00 00    00 c0 58 40 52 0c 4c 61    .x@i......x@r.la   73 74 43 61 70 61 63 69    74 79 58 b0 8b a8 ce e6    stcapacityx.....   29 60 b0 8b a8 ce e6 29                               )`.....) 

this normal. doubles represented using standard 8-byte ieee-754 representation. double value 0 represented zeros, , other values contain zeros well.

it sounds messaging infrastructure designed operate on nul-terminated text strings. such infrastructure not work raw protobuf content, because truncate message @ first nul byte. in general, cannot use raw protobuf data in context designed text, various corruption occur. note in particular should never pass protobuf bytes new string(), because string stores unicode text, not bytes.

if need transmit protobufs text expected, need base64-encode data prevent such corruption -- base64 allows raw bytes placed in textual context, increases overall size of data 33%.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -