{"action":"created","issue":{"url":"https://api.github.com/repos/dcodeIO/protobuf.js/issues/380","labels_url":"https://api.github.com/repos/dcodeIO/protobuf.js/issues/380/labels{/name}","comments_url":"https://api.github.com/repos/dcodeIO/protobuf.js/issues/380/comments","events_url":"https://api.github.com/repos/dcodeIO/protobuf.js/issues/380/events","html_url":"https://github.com/dcodeIO/protobuf.js/pull/380","id":124479332,"number":380,"title":"Move default values to prototypes and ditch nulls","user":{"login":"seishun","id":988441,"avatar_url":"https://avatars.githubusercontent.com/u/988441?v=3","gravatar_id":"","url":"https://api.github.com/users/seishun","html_url":"https://github.com/seishun","followers_url":"https://api.github.com/users/seishun/followers","following_url":"https://api.github.com/users/seishun/following{/other_user}","gists_url":"https://api.github.com/users/seishun/gists{/gist_id}","starred_url":"https://api.github.com/users/seishun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/seishun/subscriptions","organizations_url":"https://api.github.com/users/seishun/orgs","repos_url":"https://api.github.com/users/seishun/repos","events_url":"https://api.github.com/users/seishun/events{/privacy}","received_events_url":"https://api.github.com/users/seishun/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":15,"created_at":"2015-12-31T15:16:21Z","updated_at":"2016-01-07T17:59:18Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/dcodeIO/protobuf.js/pulls/380","html_url":"https://github.com/dcodeIO/protobuf.js/pull/380","diff_url":"https://github.com/dcodeIO/protobuf.js/pull/380.diff","patch_url":"https://github.com/dcodeIO/protobuf.js/pull/380.patch"},"body":"This fixes https://github.com/dcodeIO/protobuf.js/issues/200 by implementing the API described in https://github.com/dcodeIO/protobuf.js/issues/200#issuecomment-98153230.\r\n\r\n* Fields without an explicit default are treated as if the default were a type-specific value, as per the spec and the official implementations. For example, `optional bool foo = 0;` is now equivalent to `optional bool foo = 0 [default = false];`.\r\n* For every non-repeated non-map field, there is an equivalently named property on the message prototype. Its value is the field's default value.\r\n* When constructing a message object, its properties are no longer set for non-repeated non-map values. Consequently, attempting to read any of its fields results in the default value.\r\n* When encoding, only own properties are taken into account, unless it's a required field (previously, required fields with explicit defaults were set on construction, so one could encode without explicitly setting them).\r\n* When decoding, fields are no longer set to their defaults if they were missing on the wire, since the default values are already in the prototype. If a required field is missing on the wire, decoding throws even if the field has an explicit default.\r\n* The `ProtoBuf.populateDefaults` option is removed.\r\n\r\nThe changes are breaking for some (unlikely) use cases, but I tried to be as conservative as possible. Also note that all the above only applies to `proto2`. The behavior of `proto3` should be exactly the same as before.\r\n\r\nAlso fixes #319, #373."},"comment":{"url":"https://api.github.com/repos/dcodeIO/protobuf.js/issues/comments/169757019","html_url":"https://github.com/dcodeIO/protobuf.js/pull/380#issuecomment-169757019","issue_url":"https://api.github.com/repos/dcodeIO/protobuf.js/issues/380","id":169757019,"user":{"login":"Braingines","id":12314588,"avatar_url":"https://avatars.githubusercontent.com/u/12314588?v=3","gravatar_id":"","url":"https://api.github.com/users/Braingines","html_url":"https://github.com/Braingines","followers_url":"https://api.github.com/users/Braingines/followers","following_url":"https://api.github.com/users/Braingines/following{/other_user}","gists_url":"https://api.github.com/users/Braingines/gists{/gist_id}","starred_url":"https://api.github.com/users/Braingines/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Braingines/subscriptions","organizations_url":"https://api.github.com/users/Braingines/orgs","repos_url":"https://api.github.com/users/Braingines/repos","events_url":"https://api.github.com/users/Braingines/events{/privacy}","received_events_url":"https://api.github.com/users/Braingines/received_events","type":"User","site_admin":false},"created_at":"2016-01-07T17:59:18Z","updated_at":"2016-01-07T17:59:18Z","body":"I feel sorry but I should join your 'dick-measuring contest' because that was my initiative to push this feature implementation\r\n\r\nDear all ProtoBuf.js maintainers, let's read this short article from ProtoBuf (and Cap'n'Proto) dev team:\r\n\r\nhttps://developers.google.com/protocol-buffers/docs/overview#a-bit-of-history\r\n\r\n<<Protocol buffers were initially developed at Google to deal with an index server request/response protocol. Prior to protocol buffers, there was a format for requests and responses that used hand marshalling/unmarshalling of requests and responses, and that supported a number of versions of the protocol. This resulted in some very ugly code, like:\r\n\r\n if (version == 3) {\r\n   ...\r\n } else if (version > 4) {\r\n   if (version == 5) {\r\n     ...\r\n   }\r\n   ...\r\n }\r\n\r\n>>\r\n\r\n...\r\n\r\n<<\r\nProtocol buffers were designed to solve many of these problems:\r\n\r\nNew fields could be easily introduced, and intermediate servers that didn't need to inspect the data could simply parse it and pass through the data without needing to know about all the fields.>>\r\n\r\nAnd what you just did? \r\n\r\nYou implemented something like tricky V8 - based binary stream reader and writer that work excluding data scheme. \r\n\r\nTHAT'S IT.\r\n\r\nThe whole feature set mentioned above were completely IGNORED the whole your implementation story, so please do not even try to tell that this is ProtoBuf implementation. \r\n\r\nThis is ProtoBuf API - compatible V8 - based reader and writer implementation. That's all.\r\n\r\nYou have no possibility in code to get list of fields that were changed! \r\n\r\nWhat's the point to use your implementation? \r\n\r\nYour current version just save the traffic bytes, ok, well done guys, well done! \r\n\r\nI'm just wondering and can't imagine your .js code, how do you work with rich protocols (many message with many fields)? \r\n\r\nLooks like you do tens of if / else or switch / case statements in your code. In our case this is not tens, but hundreds of this useless code jumps because of your 'implementation'.\r\n\r\nNow, If you have some little doubts about how your super - duper - faster - hidden V8 - based code works, just ask the ProtoBuf initial developer what does he think about implementation without empty reflection feature set and your '.js null - features'."}}