{"action":"created","issue":{"url":"https://api.github.com/repos/nanopb/nanopb/issues/229","repository_url":"https://api.github.com/repos/nanopb/nanopb","labels_url":"https://api.github.com/repos/nanopb/nanopb/issues/229/labels{/name}","comments_url":"https://api.github.com/repos/nanopb/nanopb/issues/229/comments","events_url":"https://api.github.com/repos/nanopb/nanopb/issues/229/events","html_url":"https://github.com/nanopb/nanopb/issues/229","id":197354181,"number":229,"title":"Issues encoding/decoding messages that have several 'oneof's","user":{"login":"elusive-code","id":6000411,"avatar_url":"https://avatars1.githubusercontent.com/u/6000411?v=3","gravatar_id":"","url":"https://api.github.com/users/elusive-code","html_url":"https://github.com/elusive-code","followers_url":"https://api.github.com/users/elusive-code/followers","following_url":"https://api.github.com/users/elusive-code/following{/other_user}","gists_url":"https://api.github.com/users/elusive-code/gists{/gist_id}","starred_url":"https://api.github.com/users/elusive-code/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elusive-code/subscriptions","organizations_url":"https://api.github.com/users/elusive-code/orgs","repos_url":"https://api.github.com/users/elusive-code/repos","events_url":"https://api.github.com/users/elusive-code/events{/privacy}","received_events_url":"https://api.github.com/users/elusive-code/received_events","type":"User","site_admin":false},"labels":[{"id":205753447,"url":"https://api.github.com/repos/nanopb/nanopb/labels/Component-Design","name":"Component-Design","color":"ededed","default":false},{"id":205759008,"url":"https://api.github.com/repos/nanopb/nanopb/labels/FixedInGit","name":"FixedInGit","color":"009800","default":false},{"id":205753541,"url":"https://api.github.com/repos/nanopb/nanopb/labels/Priority-High","name":"Priority-High","color":"eb6420","default":false},{"id":205753420,"url":"https://api.github.com/repos/nanopb/nanopb/labels/Type-Defect","name":"Type-Defect","color":"e11d21","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-12-23T11:26:46Z","updated_at":"2017-03-05T16:57:17Z","closed_at":"2017-03-05T16:57:17Z","body":"It seems that there is an issue when several oneof fields present in single message\r\n\r\nWhen `simple.proto` example modified like this to simulate `has_<field>` in proto3:\r\n```\r\nsyntax = \"proto3\";\r\n\r\nmessage SimpleMessage {\r\n    oneof has_lucky_number {\r\n        uint32 lucky_number = 1;\r\n    }\r\n    oneof has_counter {\r\n        uint32 counter = 2;\r\n    }\r\n}\r\n```\r\nAfter running encoding in byte buffer and decoding I receive following output:\r\n```\r\nEncoding \r\nwhich_has_lucky_number=1\r\nlucky_number=2\r\nwhich_has_counter=2\r\ncounter=3\r\nBuffer contents:\r\n2 8 2 \r\nBytes left: 9\r\nDecoded\r\nwhich_has_lucky_number=1\r\nlucky_number=2\r\nwhich_has_counter=0\r\ncounter=0\r\n```\r\nEncoding is done like this:\r\n```\r\n  message.lucky_number = 2;\r\n  message.which_has_lucky_number = SimpleMessage_lucky_number_tag;\r\n  message.counter = 3;\r\n  message.which_has_counter = SimpleMessage_counter_tag;\r\n....\r\n  /* Now we are ready to encode the message! */\r\n  status = pb_encode_delimited(&stream, SimpleMessage_fields, &message);\r\n```\r\n\r\nWhen using external encoder (tried with java protobuf) nanopb decodes such messages adding values together.\r\nFor example, with message like\r\n```\r\nmessage IndicatorConfig {\r\n    oneof has_mode {\r\n        IndicatorMode mode = 1;\r\n    }\r\n    oneof has_value {\r\n        uint32 value = 2;\r\n    }\r\n    oneof has_brightness {\r\n        uint32 brightness = 3;\r\n    }\r\n    oneof has_blinking_delimeter {\r\n        bool blinking_delimeter = 4;\r\n    }\r\n}\r\n```\r\nsent from java with values\r\n```\r\n{\r\n  mode: IND_MANUAL\r\n  value: 1024\r\n  brightness: 2\r\n}\r\n```\r\ndecoded like this:\r\n```\r\n which_has_mode: 3\r\n which_has_value: 0\r\n which_has_brightness: 0\r\n which_has_blinking_delimeter: 0\r\n Mode: 1026\r\n value: 0\r\n brightness: 0\r\n blinking_delimeter:0\r\n```\r\n\r\nI tried both with `anonymous_oneof:true` and without it.\r\nNanopb version: nanopb-0.3.7 (2016-10-30).\r\n"},"comment":{"url":"https://api.github.com/repos/nanopb/nanopb/issues/comments/284243095","html_url":"https://github.com/nanopb/nanopb/issues/229#issuecomment-284243095","issue_url":"https://api.github.com/repos/nanopb/nanopb/issues/229","id":284243095,"user":{"login":"PetteriAimonen","id":922265,"avatar_url":"https://avatars1.githubusercontent.com/u/922265?v=3","gravatar_id":"","url":"https://api.github.com/users/PetteriAimonen","html_url":"https://github.com/PetteriAimonen","followers_url":"https://api.github.com/users/PetteriAimonen/followers","following_url":"https://api.github.com/users/PetteriAimonen/following{/other_user}","gists_url":"https://api.github.com/users/PetteriAimonen/gists{/gist_id}","starred_url":"https://api.github.com/users/PetteriAimonen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PetteriAimonen/subscriptions","organizations_url":"https://api.github.com/users/PetteriAimonen/orgs","repos_url":"https://api.github.com/users/PetteriAimonen/repos","events_url":"https://api.github.com/users/PetteriAimonen/events{/privacy}","received_events_url":"https://api.github.com/users/PetteriAimonen/received_events","type":"User","site_admin":false},"created_at":"2017-03-05T16:57:17Z","updated_at":"2017-03-05T16:57:17Z","body":"Fix released in nanopb-0.3.8."}}
{"actor":{"display_login":"PetteriAimonen"}}