1

I am attempting to use the J2V8 library on Android to call a javascript function and pass a parameter to it. The below code is what I have, but can't figure out how to pass the bytes ByteArray to the called function.

private fun decodePbfBytes(bytes: ByteArray?){
    val params = arrayOf(bytes)
    val v8 = V8.createV8Runtime()
    var v8Array = V8Array(v8) //how do I add bytes to this?
    val fileContents = MyApp.sharedInstance.assets.open("pbfIndex.js").bufferedReader().use { it.readText() }
    v8.executeScript(fileContents)
    val result = v8.executeStringFunction("", v8Array)
}
pnizzle
  • 6,243
  • 4
  • 52
  • 81

2 Answers2

1

As a temporary solution, though very naive, I converted the byte array to a string of comma separated numbers then separating them in js into a byte array. Of coarse the size of the data passed around increases multi-fold. But for now that works and I can move forward with everything else.

pnizzle
  • 6,243
  • 4
  • 52
  • 81
-1

Try this :

var buffer = V8ArrayBuffer(bytes, bytes.size)
var v8Array = V8TypedArray(v8, bytes, V8Value.BYTE, 0, 2)
V8Array(v8).add("v8Array", v8Array)

or

...
V8Array(v8).push( v8Array)
Eugene
  • 1,487
  • 10
  • 23