{"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":2,"created_at":"2018-09-05T10:16:37Z","updated_at":"2018-09-05T13:00:42Z","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/418721573","html_url":"https://github.com/AssemblyScript/assemblyscript/issues/240#issuecomment-418721573","issue_url":"https://api.github.com/repos/AssemblyScript/assemblyscript/issues/240","id":418721573,"node_id":"MDEyOklzc3VlQ29tbWVudDQxODcyMTU3Mw==","user":{"login":"MaxGraey","id":1301959,"node_id":"MDQ6VXNlcjEzMDE5NTk=","avatar_url":"https://avatars3.githubusercontent.com/u/1301959?v=4","gravatar_id":"","url":"https://api.github.com/users/MaxGraey","html_url":"https://github.com/MaxGraey","followers_url":"https://api.github.com/users/MaxGraey/followers","following_url":"https://api.github.com/users/MaxGraey/following{/other_user}","gists_url":"https://api.github.com/users/MaxGraey/gists{/gist_id}","starred_url":"https://api.github.com/users/MaxGraey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MaxGraey/subscriptions","organizations_url":"https://api.github.com/users/MaxGraey/orgs","repos_url":"https://api.github.com/users/MaxGraey/repos","events_url":"https://api.github.com/users/MaxGraey/events{/privacy}","received_events_url":"https://api.github.com/users/MaxGraey/received_events","type":"User","site_admin":false},"created_at":"2018-09-05T13:00:42Z","updated_at":"2018-09-05T13:00:42Z","author_association":"CONTRIBUTOR","body":"No, you just need import one of memory allocators.\r\nFor tests you can use `arena` for example. You should include it once in main file:\r\n```ts\r\nimport \"allocator/arena\";\r\n```"}}
{"actor":{"display_login":"MaxGraey"}}