{"action":"created","issue":{"url":"https://api.github.com/repos/AssemblyScript/assemblyscript/issues/315","repository_url":"https://api.github.com/repos/AssemblyScript/assemblyscript","labels_url":"https://api.github.com/repos/AssemblyScript/assemblyscript/issues/315/labels{/name}","comments_url":"https://api.github.com/repos/AssemblyScript/assemblyscript/issues/315/comments","events_url":"https://api.github.com/repos/AssemblyScript/assemblyscript/issues/315/events","html_url":"https://github.com/AssemblyScript/assemblyscript/issues/315","id":378394956,"node_id":"MDU6SXNzdWUzNzgzOTQ5NTY=","number":315,"title":"[Feature] Add DataView implementation","user":{"login":"LinusU","id":189580,"node_id":"MDQ6VXNlcjE4OTU4MA==","avatar_url":"https://avatars0.githubusercontent.com/u/189580?v=4","gravatar_id":"","url":"https://api.github.com/users/LinusU","html_url":"https://github.com/LinusU","followers_url":"https://api.github.com/users/LinusU/followers","following_url":"https://api.github.com/users/LinusU/following{/other_user}","gists_url":"https://api.github.com/users/LinusU/gists{/gist_id}","starred_url":"https://api.github.com/users/LinusU/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LinusU/subscriptions","organizations_url":"https://api.github.com/users/LinusU/orgs","repos_url":"https://api.github.com/users/LinusU/repos","events_url":"https://api.github.com/users/LinusU/events{/privacy}","received_events_url":"https://api.github.com/users/LinusU/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-11-07T17:36:28Z","updated_at":"2018-11-07T17:47:41Z","closed_at":null,"author_association":"NONE","body":"Currently using the following small work around in order to port a script that uses `DataView`, but would be very nice with native support:\r\n\r\n```ts\r\nclass DataView {\r\n  source: Uint8Array\r\n  buffer: ArrayBuffer\r\n  byteOffset: u32\r\n  byteLength: u32\r\n\r\n  constructor (source: Uint8Array) {\r\n    this.source = source\r\n    this.buffer = source.buffer\r\n    this.byteOffset = source.byteOffset\r\n    this.byteLength = source.byteLength\r\n  }\r\n\r\n  getUint32 (byteOffset: u32, littleEndian: boolean): u32 {\r\n    return (this.source[byteOffset] << 24) & (this.source[byteOffset + 1] << 16) & (this.source[byteOffset + 2] << 8) & (this.source[byteOffset + 3])\r\n  }\r\n\r\n  getUint16 (byteOffset: u32, littleEndian: boolean): u32 {\r\n    return (this.source[byteOffset] << 8) & (this.source[byteOffset + 1])\r\n  }\r\n}\r\n```\r\n\r\nIf someone could point me in the right direction I would be happy to try and implement this ☺️ "},"comment":{"url":"https://api.github.com/repos/AssemblyScript/assemblyscript/issues/comments/436714233","html_url":"https://github.com/AssemblyScript/assemblyscript/issues/315#issuecomment-436714233","issue_url":"https://api.github.com/repos/AssemblyScript/assemblyscript/issues/315","id":436714233,"node_id":"MDEyOklzc3VlQ29tbWVudDQzNjcxNDIzMw==","user":{"login":"dcodeIO","id":1136893,"node_id":"MDQ6VXNlcjExMzY4OTM=","avatar_url":"https://avatars0.githubusercontent.com/u/1136893?v=4","gravatar_id":"","url":"https://api.github.com/users/dcodeIO","html_url":"https://github.com/dcodeIO","followers_url":"https://api.github.com/users/dcodeIO/followers","following_url":"https://api.github.com/users/dcodeIO/following{/other_user}","gists_url":"https://api.github.com/users/dcodeIO/gists{/gist_id}","starred_url":"https://api.github.com/users/dcodeIO/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dcodeIO/subscriptions","organizations_url":"https://api.github.com/users/dcodeIO/orgs","repos_url":"https://api.github.com/users/dcodeIO/repos","events_url":"https://api.github.com/users/dcodeIO/events{/privacy}","received_events_url":"https://api.github.com/users/dcodeIO/received_events","type":"User","site_admin":false},"created_at":"2018-11-07T17:47:41Z","updated_at":"2018-11-07T17:47:41Z","author_association":"MEMBER","body":"Sure, go ahead :)\r\n\r\nThe place to add standard library components is in [std/assembly](https://github.com/AssemblyScript/assemblyscript/tree/master/std/assembly), a `dataview.ts` in this case. By `export class DataView { ... }` in this file the implementation becomes available in the environment.\r\n\r\nThe standard [DataView constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView#Syntax) seems to take an ArrayBuffer, though.. Possible optimizations here could be to annotate the getters as `@inline`, and to reuse the `loadUnsafe` etc. helpers from `internal/arraybuffer` for low-level access to the buffer directly, similar to what typed arrays already do."}}
{"actor":{"display_login":"dcodeIO"}}