{"action":"created","issue":{"url":"https://api.github.com/repos/kawanet/msgpack-lite/issues/40","repository_url":"https://api.github.com/repos/kawanet/msgpack-lite","labels_url":"https://api.github.com/repos/kawanet/msgpack-lite/issues/40/labels{/name}","comments_url":"https://api.github.com/repos/kawanet/msgpack-lite/issues/40/comments","events_url":"https://api.github.com/repos/kawanet/msgpack-lite/issues/40/events","html_url":"https://github.com/kawanet/msgpack-lite/issues/40","id":162499951,"number":40,"title":"Question: is there a ways to determine byte size of the packed message without actually decoding it?","user":{"login":"royaltm","id":615066,"avatar_url":"https://avatars.githubusercontent.com/u/615066?v=3","gravatar_id":"","url":"https://api.github.com/users/royaltm","html_url":"https://github.com/royaltm","followers_url":"https://api.github.com/users/royaltm/followers","following_url":"https://api.github.com/users/royaltm/following{/other_user}","gists_url":"https://api.github.com/users/royaltm/gists{/gist_id}","starred_url":"https://api.github.com/users/royaltm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/royaltm/subscriptions","organizations_url":"https://api.github.com/users/royaltm/orgs","repos_url":"https://api.github.com/users/royaltm/repos","events_url":"https://api.github.com/users/royaltm/events{/privacy}","received_events_url":"https://api.github.com/users/royaltm/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-06-27T17:00:51Z","updated_at":"2016-06-28T01:03:51Z","closed_at":null,"body":"The use case might be to only determine boudaries of the msgpack or count sequenced msgpacked items.\r\n\r\ne.g.\r\n```js\r\nvar data1 = encode(\"some data\"); // <Buffer a9 73 6f 6d 65 20 64 61 74 61>\r\nvar data2 = encode(123); // <Buffer 7b>\r\nvar data = Buffer.concat([data1, data2]);\r\n// hypothetical api:\r\ndecodeSize(data) // -> 10\r\ndecodeSize(data.slice(10)) // -> 1\r\ndecodeSize(data.slice(0, 9)) // -> undefined (truncated data)\r\n```\r\n\r\nPerhaps an interface similar to Decode().\r\n\r\n```js\r\nDecode().on('data', (n) => console.log(`number of bytes: ${n}`)).decodeSize(data);\r\n```\r\n\r\nAnother question: is there a way to encode message to provided buffer with offset and boundary length?\r\n\r\n```js\r\n// hypothetical api: encode(data[, buffer[, offset[, maxLength]]])\r\nencode(\"some data\", new Buffer(100), 10, 50);\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/kawanet/msgpack-lite/issues/comments/228920595","html_url":"https://github.com/kawanet/msgpack-lite/issues/40#issuecomment-228920595","issue_url":"https://api.github.com/repos/kawanet/msgpack-lite/issues/40","id":228920595,"user":{"login":"royaltm","id":615066,"avatar_url":"https://avatars.githubusercontent.com/u/615066?v=3","gravatar_id":"","url":"https://api.github.com/users/royaltm","html_url":"https://github.com/royaltm","followers_url":"https://api.github.com/users/royaltm/followers","following_url":"https://api.github.com/users/royaltm/following{/other_user}","gists_url":"https://api.github.com/users/royaltm/gists{/gist_id}","starred_url":"https://api.github.com/users/royaltm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/royaltm/subscriptions","organizations_url":"https://api.github.com/users/royaltm/orgs","repos_url":"https://api.github.com/users/royaltm/repos","events_url":"https://api.github.com/users/royaltm/events{/privacy}","received_events_url":"https://api.github.com/users/royaltm/received_events","type":"User","site_admin":false},"created_at":"2016-06-28T01:03:51Z","updated_at":"2016-06-28T01:03:51Z","body":"Yes I know that detecting the size would require to recursively iterate over maps and arrays but decoding data means also allocating Objects and later gc'ing them. I need to scan over large stream of msgpacked objects only cherrypicking n'th of them. For now I can just throw away whatever items I don't need but it's an obvious waste.\r\n\r\nThanks for the hint regarding 2nd question. This is a little bit verbose, but that will do :). I wonder however what happens when the message doesn't fit in the buffer?\r\n"}}
{"actor":{"display_login":"royaltm"}}