Tuesday, 15 April 2014

jquery - Using ajax to send a Proto-buf message to a Java server -



jquery - Using ajax to send a Proto-buf message to a Java server -

using https://github.com/dcodeio/protobuf.js/ encoded message want send java server bytebuffer called batch:

batch: bytebuffer {array: arraybuffer, view: dataview, offset: 0, markedoffset: -1, length: 139…} array: arraybuffer length: 139 littleendian: false markedoffset: -1 offset: 0 view: dataview __proto__: object

now want send jquery's ajax:

$.ajax({ url: myurl, type: 'post', info : batch, contenttype: 'application/protobuf', accept: 'application/json' })

but can't seem this. above code gives me jquery exception:

uncaught typeerror: cannot set property 'littleendian' of undefined myscript.js:1353 bytebuffer.le bunk.js:1353 jquery.param.add jquery.js:7203 buildparams jquery.js:7261 jquery.param jquery.js:7223 jquery.extend.ajax

if array buffer batch (batch.toarraybuffer()) java server gets nil from

bytestreams.tobytearray(req.getinputstream());

how should encode bytebuffer send this? , how should decode java byte array?

from jquery's documentation on ajax (http://api.jquery.com/jquery.ajax/):

note: w3c xmlhttprequest specification dictates charset utf-8; specifying charset not forcefulness browser alter encoding.

you're trying send raw binary bytes protobuffer, not compatible utf-8.

i'm not familiar protobuf.js, little digging online looks there's tobase64() method available encoding protobuf base64 string. seek using method info send, , on server decode base64.

java jquery ajax protocol-buffers arraybuffer

No comments:

Post a Comment