{"action":"created","issue":{"url":"https://api.github.com/repos/micropython/micropython/issues/1747","labels_url":"https://api.github.com/repos/micropython/micropython/issues/1747/labels{/name}","comments_url":"https://api.github.com/repos/micropython/micropython/issues/1747/comments","events_url":"https://api.github.com/repos/micropython/micropython/issues/1747/events","html_url":"https://github.com/micropython/micropython/pull/1747","id":123753845,"number":1747,"title":"py: Add ustruct.pack_into and unpack_from","user":{"login":"dhylands","id":127500,"avatar_url":"https://avatars.githubusercontent.com/u/127500?v=3","gravatar_id":"","url":"https://api.github.com/users/dhylands","html_url":"https://github.com/dhylands","followers_url":"https://api.github.com/users/dhylands/followers","following_url":"https://api.github.com/users/dhylands/following{/other_user}","gists_url":"https://api.github.com/users/dhylands/gists{/gist_id}","starred_url":"https://api.github.com/users/dhylands/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dhylands/subscriptions","organizations_url":"https://api.github.com/users/dhylands/orgs","repos_url":"https://api.github.com/users/dhylands/repos","events_url":"https://api.github.com/users/dhylands/events{/privacy}","received_events_url":"https://api.github.com/users/dhylands/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-12-24T03:29:56Z","updated_at":"2015-12-27T21:24:56Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/micropython/micropython/pulls/1747","html_url":"https://github.com/micropython/micropython/pull/1747","diff_url":"https://github.com/micropython/micropython/pull/1747.diff","patch_url":"https://github.com/micropython/micropython/pull/1747.patch"},"body":"Having pack_into and unpack_from allows allocating fewer buffers."},"comment":{"url":"https://api.github.com/repos/micropython/micropython/issues/comments/167442445","html_url":"https://github.com/micropython/micropython/pull/1747#issuecomment-167442445","issue_url":"https://api.github.com/repos/micropython/micropython/issues/1747","id":167442445,"user":{"login":"dhylands","id":127500,"avatar_url":"https://avatars.githubusercontent.com/u/127500?v=3","gravatar_id":"","url":"https://api.github.com/users/dhylands","html_url":"https://github.com/dhylands","followers_url":"https://api.github.com/users/dhylands/followers","following_url":"https://api.github.com/users/dhylands/following{/other_user}","gists_url":"https://api.github.com/users/dhylands/gists{/gist_id}","starred_url":"https://api.github.com/users/dhylands/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dhylands/subscriptions","organizations_url":"https://api.github.com/users/dhylands/orgs","repos_url":"https://api.github.com/users/dhylands/repos","events_url":"https://api.github.com/users/dhylands/events{/privacy}","received_events_url":"https://api.github.com/users/dhylands/received_events","type":"User","site_admin":false},"created_at":"2015-12-27T21:24:56Z","updated_at":"2015-12-27T21:24:56Z","body":"> Fewer, but not exactly zero. And this same trait (fewer buffers) is achievable by uctypes. So, what improvement this patch gives? How many bytes does it cost?\r\n\r\nWell you need the underlying buffer object, but that's true for uctypes as well. I might be able to use uctypes, but it would a bunch more code required, since I'm using this to unpack packets over the uart, and the packet layout varies from packet to packet (and no the packet format is not controllable by me - I'm talking to Bioloid AX-12 servos, and I can't change the firmware in the servos.\r\n\r\nI might be able to use uctypes - not sure. Using uctypes will cost me RAM to store the structures. Using pack_into and unpack_from costs me flash (and a bit of RAM for the strings which describe the packing format).\r\n\r\nThis adds about 400 bytes of flash to implement both pack_into and unpack_from (a big chunk of that is for the parameter checking and the exceptions).\r\n\r\nI'm also happy to make these configable. I saw that there was a config option for struct as a whole. I'd be happy to make them individually configable, or as a pair (and perhaps even make pack and unpack configable."}}