Using https://github.com/dcodeIO/ProtoBuf.js/ I encoded the message that I want to send to the Java server in ByteBuffer, called the package:
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 I want to send this using jquery Ajax:
$.ajax({ url: myUrl, type: 'POST', data : batch, contentType: 'application/protobuf', accept: 'application/json' })
But I canβt do it. The above code gives me a 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 I get an array buffer from a package (batch.toArrayBuffer ()), the Java server does not receive anything from
ByteStreams.toByteArray(req.getInputStream());
How do I encode a ByteBuffer to send as follows? And how do I decode it into a java byte array?
source share