{"action":"created","issue":{"url":"https://api.github.com/repos/AssemblyScript/assemblyscript/issues/240","repository_url":"https://api.github.com/repos/AssemblyScript/assemblyscript","labels_url":"https://api.github.com/repos/AssemblyScript/assemblyscript/issues/240/labels{/name}","comments_url":"https://api.github.com/repos/AssemblyScript/assemblyscript/issues/240/comments","events_url":"https://api.github.com/repos/AssemblyScript/assemblyscript/issues/240/events","html_url":"https://github.com/AssemblyScript/assemblyscript/issues/240","id":357160881,"node_id":"MDU6SXNzdWUzNTcxNjA4ODE=","number":240,"title":"how to create UInt8Array in AssemblyScript and return it to caller ","user":{"login":"msbasanth","id":17777813,"node_id":"MDQ6VXNlcjE3Nzc3ODEz","avatar_url":"https://avatars3.githubusercontent.com/u/17777813?v=4","gravatar_id":"","url":"https://api.github.com/users/msbasanth","html_url":"https://github.com/msbasanth","followers_url":"https://api.github.com/users/msbasanth/followers","following_url":"https://api.github.com/users/msbasanth/following{/other_user}","gists_url":"https://api.github.com/users/msbasanth/gists{/gist_id}","starred_url":"https://api.github.com/users/msbasanth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/msbasanth/subscriptions","organizations_url":"https://api.github.com/users/msbasanth/orgs","repos_url":"https://api.github.com/users/msbasanth/repos","events_url":"https://api.github.com/users/msbasanth/events{/privacy}","received_events_url":"https://api.github.com/users/msbasanth/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":12,"created_at":"2018-09-05T10:16:37Z","updated_at":"2018-09-26T12:41:28Z","closed_at":null,"author_association":"NONE","body":"Hi,\r\n\r\nI am using AssemblyScript to convert my RLE decode code written in TypeScript to WebAssembly.\r\nThis is what I did,\r\n1. This is my decodeRLE code which is in my index.ts file which I am trying to convert to wasm.\r\n\r\n```ts\r\nexport function decodeRLE(encodedBuffer: Uint8Array): Uint8Array {\r\n    var decodedBuffer = [];\r\n    var encoderDataLength = encodedBuffer.byteLength;\r\n    var pos = 8;\r\n    let isRip: boolean;\r\n    let isRun: boolean;\r\n    let ripCount: number;\r\n    let runCount: number;\r\n    while (pos < encoderDataLength)\r\n    {\r\n      var cmd: number = getInt8(encodedBuffer[pos]);\r\n      isRip= cmd<0;\r\n      isRun= cmd>0;\r\n      if(cmd<0){ // rip\r\n        cmd=Math.abs(cmd);\r\n        pos+=1;\r\n       var posIndex = pos;\r\n        for (var i = 0; i < cmd; i++)\r\n        {\r\n          var myvalue = encodedBuffer[posIndex];\r\n          decodedBuffer.push(myvalue);\r\n          posIndex++;\r\n        }\r\n        pos+=cmd;\r\n      }\r\n      else // run\r\n      {\r\n        cmd +=2;\r\n        var v =encodedBuffer[pos + 1];\r\n        if(v != 0)\r\n        {\r\n          for (var j = 0; j < cmd; j++) {\r\n            decodedBuffer.push(v)\r\n          };\r\n        }\r\n        else\r\n        {\r\n          for (var j = 0; j < cmd; j++) {\r\n            decodedBuffer.push(0)\r\n          };\r\n        }\r\n        pos+=2;\r\n      }\r\n    };\r\n    return decodedBuffer;\r\n}\r\n```\r\n\r\n2. Errors:\r\nERROR AS100: Operation not supported.\r\n     var decodedBuffer = [];\r\n in assembly/index.ts(97,24)\r\n\r\nERROR TS2339: Property 'push' does not exist on type 'i32'.\r\n           decodedBuffer.push(myvalue);\r\n in assembly/index.ts(116,24)\r\n\r\nERROR AS200: Conversion from type 'f64' to 'i32' requires an explicit cast.\r\n         pos+=cmd;\r\n in assembly/index.ts(119,13)\r\n\r\nI would like to know how we can create a array (UInt8Array) in AssemblyScript? I aso want to return the created array back to consumers of my WASM. So that I can move the decode code to WASM.\r\n\r\nThanks\r\nBasanth"},"comment":{"url":"https://api.github.com/repos/AssemblyScript/assemblyscript/issues/comments/424700351","html_url":"https://github.com/AssemblyScript/assemblyscript/issues/240#issuecomment-424700351","issue_url":"https://api.github.com/repos/AssemblyScript/assemblyscript/issues/240","id":424700351,"node_id":"MDEyOklzc3VlQ29tbWVudDQyNDcwMDM1MQ==","user":{"login":"msbasanth","id":17777813,"node_id":"MDQ6VXNlcjE3Nzc3ODEz","avatar_url":"https://avatars3.githubusercontent.com/u/17777813?v=4","gravatar_id":"","url":"https://api.github.com/users/msbasanth","html_url":"https://github.com/msbasanth","followers_url":"https://api.github.com/users/msbasanth/followers","following_url":"https://api.github.com/users/msbasanth/following{/other_user}","gists_url":"https://api.github.com/users/msbasanth/gists{/gist_id}","starred_url":"https://api.github.com/users/msbasanth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/msbasanth/subscriptions","organizations_url":"https://api.github.com/users/msbasanth/orgs","repos_url":"https://api.github.com/users/msbasanth/repos","events_url":"https://api.github.com/users/msbasanth/events{/privacy}","received_events_url":"https://api.github.com/users/msbasanth/received_events","type":"User","site_admin":false},"created_at":"2018-09-26T12:41:28Z","updated_at":"2018-09-26T12:41:28Z","author_association":"NONE","body":"@kyr0 the sample worked fine which showed how we can share an array to WASM and get the array modified. This simplified the passing arrays between JS and WASM.\r\n\r\nThe same sample I am trying to run in browser (Angular) application. Instead of using loader.instantiateBuffer I used loader.instantiateStreaming.\r\n\r\n```\r\nasync anAsyncMethod() {\r\n    const imports = {};\r\n    const {instance} = await loader.instantiateStreaming(fetch('assets/optimized.wasm'), imports);\r\n    console.log('WASM succeeded' + instance);\r\n    const calcNums = new Int32Array([1, 2, 3, 4, 5, 0x7fffffff]);\r\n    console.log('Input array data to be summed:', calcNums);\r\n    const ptr = instance.newArray(calcNums);\r\n  }\r\nngAfterViewInit() {\r\n    this.anAsyncMethod();\r\n}\r\n```\r\n\r\nI am getting this error:\r\n\r\n```\r\nUncaught (in promise): RangeError: WebAssembly.Instance is disallowed on the main thread, if the buffer size is larger than 4KB. Use WebAssembly.instantiate.\r\nRangeError: WebAssembly.Instance is disallowed on the main thread, if the buffer size is larger than 4KB. Use WebAssembly.instantiate.\r\n```\r\n\r\nIs it the right way I am using loader.instantiateStreaming?\r\n\r\nRegards\r\nBasanth"}}
{"actor":{"display_login":"msbasanth"}}