{"action":"created","comment":{"url":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/comments/235738310","pull_request_review_id":177672863,"id":235738310,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzNTczODMxMA==","diff_hunk":"@@ -765,14 +669,42 @@ int gcoap_req_init(coap_pkt_t *pdu, uint8_t *buf, size_t len,\n     }\n }\n \n+/*\n+ * Assumes pdu.payload_len attribute was reduced in gcoap_xxx_init() to\n+ * ensure enough space in PDU buffer to write Content-Format option and\n+ * payload marker here.\n+ */\n ssize_t gcoap_finish(coap_pkt_t *pdu, size_t payload_len, unsigned format)\n {\n-    /* reconstruct full PDU buffer length */\n-    size_t len = pdu->payload_len + (pdu->payload - (uint8_t *)pdu->hdr);\n+    if (pdu->options_len && payload_len) {","path":"sys/net/application_layer/gcoap/gcoap.c","position":186,"original_position":186,"commit_id":"71c02691bf13e0263b07a92c457472fb6032eea9","original_commit_id":"71c02691bf13e0263b07a92c457472fb6032eea9","user":{"login":"kb2ma","id":2944058,"node_id":"MDQ6VXNlcjI5NDQwNTg=","avatar_url":"https://avatars0.githubusercontent.com/u/2944058?v=4","gravatar_id":"","url":"https://api.github.com/users/kb2ma","html_url":"https://github.com/kb2ma","followers_url":"https://api.github.com/users/kb2ma/followers","following_url":"https://api.github.com/users/kb2ma/following{/other_user}","gists_url":"https://api.github.com/users/kb2ma/gists{/gist_id}","starred_url":"https://api.github.com/users/kb2ma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kb2ma/subscriptions","organizations_url":"https://api.github.com/users/kb2ma/orgs","repos_url":"https://api.github.com/users/kb2ma/repos","events_url":"https://api.github.com/users/kb2ma/events{/privacy}","received_events_url":"https://api.github.com/users/kb2ma/received_events","type":"User","site_admin":false},"body":"OK, I'll rework the assert. Your construct is more idiomatic although as you say the logic is a little harder to follow.","created_at":"2018-11-22T14:09:39Z","updated_at":"2018-11-22T14:09:39Z","html_url":"https://github.com/RIOT-OS/RIOT/pull/9156#discussion_r235738310","pull_request_url":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/9156","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/comments/235738310"},"html":{"href":"https://github.com/RIOT-OS/RIOT/pull/9156#discussion_r235738310"},"pull_request":{"href":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/9156"}},"in_reply_to_id":235646185},"pull_request":{"url":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/9156","id":189171405,"node_id":"MDExOlB1bGxSZXF1ZXN0MTg5MTcxNDA1","html_url":"https://github.com/RIOT-OS/RIOT/pull/9156","diff_url":"https://github.com/RIOT-OS/RIOT/pull/9156.diff","patch_url":"https://github.com/RIOT-OS/RIOT/pull/9156.patch","issue_url":"https://api.github.com/repos/RIOT-OS/RIOT/issues/9156","number":9156,"state":"open","locked":false,"title":"net/gcoap: Use nanocoap pkt/options API","user":{"login":"kb2ma","id":2944058,"node_id":"MDQ6VXNlcjI5NDQwNTg=","avatar_url":"https://avatars0.githubusercontent.com/u/2944058?v=4","gravatar_id":"","url":"https://api.github.com/users/kb2ma","html_url":"https://github.com/kb2ma","followers_url":"https://api.github.com/users/kb2ma/followers","following_url":"https://api.github.com/users/kb2ma/following{/other_user}","gists_url":"https://api.github.com/users/kb2ma/gists{/gist_id}","starred_url":"https://api.github.com/users/kb2ma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kb2ma/subscriptions","organizations_url":"https://api.github.com/users/kb2ma/orgs","repos_url":"https://api.github.com/users/kb2ma/repos","events_url":"https://api.github.com/users/kb2ma/events{/privacy}","received_events_url":"https://api.github.com/users/kb2ma/received_events","type":"User","site_admin":false},"body":"### Contribution description\r\nUpdates gcoap to use the nanocoap pkt/options API in #9085. This work allows removal of the gcoap-specific attributes in coap_pkt_t, which add a painful 130 bytes. (Now you know why I've been working so hard lately!) \r\n\r\nUse of this API allows gcoap to fully build on nanocoap as a higher-level API. gcoap has always used a coap_pkt_t to build a message, and now nanocoap does too. See how gcoap_req_init() prepares for coap_build_hdr(), and then calls coap_pkt_init(), coap_opt_add_string() for the path, and coap_opt_add_uint() for the content format.\r\n\r\n#### 2018-10-23 Update\r\nSimplified implementation of gcoap_finish(), which results in a minor API change. gcoap_finish() adds a Content-Format option to the packet after writing the payload. The original implementation of this PR accommodated options with any other option number that may have been added to the packet. Today I updated the implementation to accept  options only with an option number less than Content-Format.\r\n\r\nFundamentally, the gcoap_finish() function has become obsolete as we have increased the use of CoAP options. The updated CoAP API now uses coap_opt_finish() to finalize the packet header *before* writing the payload. We plan to deprecate gcoap_finish() soon.\r\n\r\nThis change significantly simplifies gcoap_finish() until we deprecate it, and reduces the text space in the executable for this function by half, around 120 bytes. The cost is that existing code breaks when setting a Uri-Query option and then setting the format in gcoap_finish(). (Uri-Query is the only option with an option number greater than Content-Format that gcoap used before this PR.) In fact, the new Resource Directory implementation, cord_ep, had this problem, so I added a commit to this PR to fix it.\r\n\r\n### Issues/PRs references\r\nDepends on #10223\r\n\r\nSee [CoAP API Options Update](https://github.com/RIOT-OS/RIOT/wiki/CoAP-API-Options-Update) wiki page for background, including how gcoap uses it.","created_at":"2018-05-19T05:08:12Z","updated_at":"2018-11-22T14:09:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"25851906e4d9877b5427c5627d4398aae21e7a2c","assignee":null,"assignees":[],"requested_reviewers":[{"login":"kaspar030","id":4679640,"node_id":"MDQ6VXNlcjQ2Nzk2NDA=","avatar_url":"https://avatars0.githubusercontent.com/u/4679640?v=4","gravatar_id":"","url":"https://api.github.com/users/kaspar030","html_url":"https://github.com/kaspar030","followers_url":"https://api.github.com/users/kaspar030/followers","following_url":"https://api.github.com/users/kaspar030/following{/other_user}","gists_url":"https://api.github.com/users/kaspar030/gists{/gist_id}","starred_url":"https://api.github.com/users/kaspar030/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kaspar030/subscriptions","organizations_url":"https://api.github.com/users/kaspar030/orgs","repos_url":"https://api.github.com/users/kaspar030/repos","events_url":"https://api.github.com/users/kaspar030/events{/privacy}","received_events_url":"https://api.github.com/users/kaspar030/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[{"id":944674418,"node_id":"MDU6TGFiZWw5NDQ2NzQ0MTg=","url":"https://api.github.com/repos/RIOT-OS/RIOT/labels/Area:%20CoAP","name":"Area: CoAP","color":"6600ff","default":false},{"id":86443543,"node_id":"MDU6TGFiZWw4NjQ0MzU0Mw==","url":"https://api.github.com/repos/RIOT-OS/RIOT/labels/Area:%20network","name":"Area: network","color":"6600ff","default":false},{"id":214816571,"node_id":"MDU6TGFiZWwyMTQ4MTY1NzE=","url":"https://api.github.com/repos/RIOT-OS/RIOT/labels/CI:%20ready%20for%20build","name":"CI: ready for build","color":"66ffcc","default":false},{"id":127102429,"node_id":"MDU6TGFiZWwxMjcxMDI0Mjk=","url":"https://api.github.com/repos/RIOT-OS/RIOT/labels/Process:%20API%20change","name":"Process: API change","color":"ff9933","default":false},{"id":1075449391,"node_id":"MDU6TGFiZWwxMDc1NDQ5Mzkx","url":"https://api.github.com/repos/RIOT-OS/RIOT/labels/Reviewed:%201-fundamentals","name":"Reviewed: 1-fundamentals","color":"00dd00","default":false},{"id":127387257,"node_id":"MDU6TGFiZWwxMjczODcyNTc=","url":"https://api.github.com/repos/RIOT-OS/RIOT/labels/State:%20waiting%20for%20other%20PR","name":"State: waiting for other PR","color":"ff66ff","default":false},{"id":23399100,"node_id":"MDU6TGFiZWwyMzM5OTEwMA==","url":"https://api.github.com/repos/RIOT-OS/RIOT/labels/Type:%20enhancement","name":"Type: enhancement","color":"ffff66","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/9156/commits","review_comments_url":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/9156/comments","review_comment_url":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/comments{/number}","comments_url":"https://api.github.com/repos/RIOT-OS/RIOT/issues/9156/comments","statuses_url":"https://api.github.com/repos/RIOT-OS/RIOT/statuses/71c02691bf13e0263b07a92c457472fb6032eea9","head":{"label":"kb2ma:gcoap/use_opt_add_api","ref":"gcoap/use_opt_add_api","sha":"71c02691bf13e0263b07a92c457472fb6032eea9","user":{"login":"kb2ma","id":2944058,"node_id":"MDQ6VXNlcjI5NDQwNTg=","avatar_url":"https://avatars0.githubusercontent.com/u/2944058?v=4","gravatar_id":"","url":"https://api.github.com/users/kb2ma","html_url":"https://github.com/kb2ma","followers_url":"https://api.github.com/users/kb2ma/followers","following_url":"https://api.github.com/users/kb2ma/following{/other_user}","gists_url":"https://api.github.com/users/kb2ma/gists{/gist_id}","starred_url":"https://api.github.com/users/kb2ma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kb2ma/subscriptions","organizations_url":"https://api.github.com/users/kb2ma/orgs","repos_url":"https://api.github.com/users/kb2ma/repos","events_url":"https://api.github.com/users/kb2ma/events{/privacy}","received_events_url":"https://api.github.com/users/kb2ma/received_events","type":"User","site_admin":false},"repo":{"id":39065415,"node_id":"MDEwOlJlcG9zaXRvcnkzOTA2NTQxNQ==","name":"RIOT","full_name":"kb2ma/RIOT","private":false,"owner":{"login":"kb2ma","id":2944058,"node_id":"MDQ6VXNlcjI5NDQwNTg=","avatar_url":"https://avatars0.githubusercontent.com/u/2944058?v=4","gravatar_id":"","url":"https://api.github.com/users/kb2ma","html_url":"https://github.com/kb2ma","followers_url":"https://api.github.com/users/kb2ma/followers","following_url":"https://api.github.com/users/kb2ma/following{/other_user}","gists_url":"https://api.github.com/users/kb2ma/gists{/gist_id}","starred_url":"https://api.github.com/users/kb2ma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kb2ma/subscriptions","organizations_url":"https://api.github.com/users/kb2ma/orgs","repos_url":"https://api.github.com/users/kb2ma/repos","events_url":"https://api.github.com/users/kb2ma/events{/privacy}","received_events_url":"https://api.github.com/users/kb2ma/received_events","type":"User","site_admin":false},"html_url":"https://github.com/kb2ma/RIOT","description":"RIOT -  The friendly OS for IoT","fork":true,"url":"https://api.github.com/repos/kb2ma/RIOT","forks_url":"https://api.github.com/repos/kb2ma/RIOT/forks","keys_url":"https://api.github.com/repos/kb2ma/RIOT/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kb2ma/RIOT/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kb2ma/RIOT/teams","hooks_url":"https://api.github.com/repos/kb2ma/RIOT/hooks","issue_events_url":"https://api.github.com/repos/kb2ma/RIOT/issues/events{/number}","events_url":"https://api.github.com/repos/kb2ma/RIOT/events","assignees_url":"https://api.github.com/repos/kb2ma/RIOT/assignees{/user}","branches_url":"https://api.github.com/repos/kb2ma/RIOT/branches{/branch}","tags_url":"https://api.github.com/repos/kb2ma/RIOT/tags","blobs_url":"https://api.github.com/repos/kb2ma/RIOT/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kb2ma/RIOT/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kb2ma/RIOT/git/refs{/sha}","trees_url":"https://api.github.com/repos/kb2ma/RIOT/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kb2ma/RIOT/statuses/{sha}","languages_url":"https://api.github.com/repos/kb2ma/RIOT/languages","stargazers_url":"https://api.github.com/repos/kb2ma/RIOT/stargazers","contributors_url":"https://api.github.com/repos/kb2ma/RIOT/contributors","subscribers_url":"https://api.github.com/repos/kb2ma/RIOT/subscribers","subscription_url":"https://api.github.com/repos/kb2ma/RIOT/subscription","commits_url":"https://api.github.com/repos/kb2ma/RIOT/commits{/sha}","git_commits_url":"https://api.github.com/repos/kb2ma/RIOT/git/commits{/sha}","comments_url":"https://api.github.com/repos/kb2ma/RIOT/comments{/number}","issue_comment_url":"https://api.github.com/repos/kb2ma/RIOT/issues/comments{/number}","contents_url":"https://api.github.com/repos/kb2ma/RIOT/contents/{+path}","compare_url":"https://api.github.com/repos/kb2ma/RIOT/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kb2ma/RIOT/merges","archive_url":"https://api.github.com/repos/kb2ma/RIOT/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kb2ma/RIOT/downloads","issues_url":"https://api.github.com/repos/kb2ma/RIOT/issues{/number}","pulls_url":"https://api.github.com/repos/kb2ma/RIOT/pulls{/number}","milestones_url":"https://api.github.com/repos/kb2ma/RIOT/milestones{/number}","notifications_url":"https://api.github.com/repos/kb2ma/RIOT/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kb2ma/RIOT/labels{/name}","releases_url":"https://api.github.com/repos/kb2ma/RIOT/releases{/id}","deployments_url":"https://api.github.com/repos/kb2ma/RIOT/deployments","created_at":"2015-07-14T09:15:57Z","updated_at":"2017-01-14T11:53:11Z","pushed_at":"2018-11-22T07:53:49Z","git_url":"git://github.com/kb2ma/RIOT.git","ssh_url":"git@github.com:kb2ma/RIOT.git","clone_url":"https://github.com/kb2ma/RIOT.git","svn_url":"https://github.com/kb2ma/RIOT","homepage":"https://github.com/RIOT-OS/RIOT/wiki","size":59317,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":7,"license":{"key":"lgpl-2.1","name":"GNU Lesser General Public License v2.1","spdx_id":"LGPL-2.1","url":"https://api.github.com/licenses/lgpl-2.1","node_id":"MDc6TGljZW5zZTEx"},"forks":0,"open_issues":7,"watchers":0,"default_branch":"master"}},"base":{"label":"RIOT-OS:master","ref":"master","sha":"4d85bcf510689eb3bf27b984efbfee965d33ff03","user":{"login":"RIOT-OS","id":3079480,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMwNzk0ODA=","avatar_url":"https://avatars2.githubusercontent.com/u/3079480?v=4","gravatar_id":"","url":"https://api.github.com/users/RIOT-OS","html_url":"https://github.com/RIOT-OS","followers_url":"https://api.github.com/users/RIOT-OS/followers","following_url":"https://api.github.com/users/RIOT-OS/following{/other_user}","gists_url":"https://api.github.com/users/RIOT-OS/gists{/gist_id}","starred_url":"https://api.github.com/users/RIOT-OS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RIOT-OS/subscriptions","organizations_url":"https://api.github.com/users/RIOT-OS/orgs","repos_url":"https://api.github.com/users/RIOT-OS/repos","events_url":"https://api.github.com/users/RIOT-OS/events{/privacy}","received_events_url":"https://api.github.com/users/RIOT-OS/received_events","type":"Organization","site_admin":false},"repo":{"id":7370241,"node_id":"MDEwOlJlcG9zaXRvcnk3MzcwMjQx","name":"RIOT","full_name":"RIOT-OS/RIOT","private":false,"owner":{"login":"RIOT-OS","id":3079480,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMwNzk0ODA=","avatar_url":"https://avatars2.githubusercontent.com/u/3079480?v=4","gravatar_id":"","url":"https://api.github.com/users/RIOT-OS","html_url":"https://github.com/RIOT-OS","followers_url":"https://api.github.com/users/RIOT-OS/followers","following_url":"https://api.github.com/users/RIOT-OS/following{/other_user}","gists_url":"https://api.github.com/users/RIOT-OS/gists{/gist_id}","starred_url":"https://api.github.com/users/RIOT-OS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RIOT-OS/subscriptions","organizations_url":"https://api.github.com/users/RIOT-OS/orgs","repos_url":"https://api.github.com/users/RIOT-OS/repos","events_url":"https://api.github.com/users/RIOT-OS/events{/privacy}","received_events_url":"https://api.github.com/users/RIOT-OS/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/RIOT-OS/RIOT","description":"RIOT -  The friendly OS for IoT","fork":false,"url":"https://api.github.com/repos/RIOT-OS/RIOT","forks_url":"https://api.github.com/repos/RIOT-OS/RIOT/forks","keys_url":"https://api.github.com/repos/RIOT-OS/RIOT/keys{/key_id}","collaborators_url":"https://api.github.com/repos/RIOT-OS/RIOT/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/RIOT-OS/RIOT/teams","hooks_url":"https://api.github.com/repos/RIOT-OS/RIOT/hooks","issue_events_url":"https://api.github.com/repos/RIOT-OS/RIOT/issues/events{/number}","events_url":"https://api.github.com/repos/RIOT-OS/RIOT/events","assignees_url":"https://api.github.com/repos/RIOT-OS/RIOT/assignees{/user}","branches_url":"https://api.github.com/repos/RIOT-OS/RIOT/branches{/branch}","tags_url":"https://api.github.com/repos/RIOT-OS/RIOT/tags","blobs_url":"https://api.github.com/repos/RIOT-OS/RIOT/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/RIOT-OS/RIOT/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/RIOT-OS/RIOT/git/refs{/sha}","trees_url":"https://api.github.com/repos/RIOT-OS/RIOT/git/trees{/sha}","statuses_url":"https://api.github.com/repos/RIOT-OS/RIOT/statuses/{sha}","languages_url":"https://api.github.com/repos/RIOT-OS/RIOT/languages","stargazers_url":"https://api.github.com/repos/RIOT-OS/RIOT/stargazers","contributors_url":"https://api.github.com/repos/RIOT-OS/RIOT/contributors","subscribers_url":"https://api.github.com/repos/RIOT-OS/RIOT/subscribers","subscription_url":"https://api.github.com/repos/RIOT-OS/RIOT/subscription","commits_url":"https://api.github.com/repos/RIOT-OS/RIOT/commits{/sha}","git_commits_url":"https://api.github.com/repos/RIOT-OS/RIOT/git/commits{/sha}","comments_url":"https://api.github.com/repos/RIOT-OS/RIOT/comments{/number}","issue_comment_url":"https://api.github.com/repos/RIOT-OS/RIOT/issues/comments{/number}","contents_url":"https://api.github.com/repos/RIOT-OS/RIOT/contents/{+path}","compare_url":"https://api.github.com/repos/RIOT-OS/RIOT/compare/{base}...{head}","merges_url":"https://api.github.com/repos/RIOT-OS/RIOT/merges","archive_url":"https://api.github.com/repos/RIOT-OS/RIOT/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/RIOT-OS/RIOT/downloads","issues_url":"https://api.github.com/repos/RIOT-OS/RIOT/issues{/number}","pulls_url":"https://api.github.com/repos/RIOT-OS/RIOT/pulls{/number}","milestones_url":"https://api.github.com/repos/RIOT-OS/RIOT/milestones{/number}","notifications_url":"https://api.github.com/repos/RIOT-OS/RIOT/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/RIOT-OS/RIOT/labels{/name}","releases_url":"https://api.github.com/repos/RIOT-OS/RIOT/releases{/id}","deployments_url":"https://api.github.com/repos/RIOT-OS/RIOT/deployments","created_at":"2012-12-29T20:38:40Z","updated_at":"2018-11-22T13:22:26Z","pushed_at":"2018-11-22T14:08:47Z","git_url":"git://github.com/RIOT-OS/RIOT.git","ssh_url":"git@github.com:RIOT-OS/RIOT.git","clone_url":"https://github.com/RIOT-OS/RIOT.git","svn_url":"https://github.com/RIOT-OS/RIOT","homepage":"https://github.com/RIOT-OS/RIOT/wiki","size":59498,"stargazers_count":2124,"watchers_count":2124,"language":"C","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1181,"mirror_url":null,"archived":false,"open_issues_count":900,"license":{"key":"lgpl-2.1","name":"GNU Lesser General Public License v2.1","spdx_id":"LGPL-2.1","url":"https://api.github.com/licenses/lgpl-2.1","node_id":"MDc6TGljZW5zZTEx"},"forks":1181,"open_issues":900,"watchers":2124,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/9156"},"html":{"href":"https://github.com/RIOT-OS/RIOT/pull/9156"},"issue":{"href":"https://api.github.com/repos/RIOT-OS/RIOT/issues/9156"},"comments":{"href":"https://api.github.com/repos/RIOT-OS/RIOT/issues/9156/comments"},"review_comments":{"href":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/9156/comments"},"review_comment":{"href":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/9156/commits"},"statuses":{"href":"https://api.github.com/repos/RIOT-OS/RIOT/statuses/71c02691bf13e0263b07a92c457472fb6032eea9"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"kb2ma"}}