protocolbuffers / protocolbuffers/protobuf-javascript
Generate alternate accessor for fields with presence
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 471
- Forks
- 91
- Avg merge
- 3h 57m
- Merged PRs (30d)
- 2
Description
When I executed the toObject method on a message with a field marked optional, that field became the default value like 0 or "". I expect it would be undefined.
I guess it is because the third argument of getFieldWithDefault is not undefined.
Since proto3 currently support optional keyword, when optional is specified, I think it should be undefined if it is not given.
proto
syntax = "proto3";
package com.book;
message OptTest {
optional string name = 1;
}
generated toObject code
proto.com.book.OptTest.toObject = function(includeInstance, msg) {
var f, obj = {
name: jspb.Message.getFieldWithDefault(msg, 1, "")
};
if (includeInstance) {
obj.$jspbMessageInstance = msg;
}
return obj;
};
versions
$ npm list --depth=0 -g
/usr/local/lib
+-- google-protobuf@3.21.2
+-- grpc_tools_node_protoc_ts@5.3.3
`-- grpc-tools@1.12.4
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the optional-field case by generating the shown OptTest message and calling toObject. Start with the generated toObject code and the getFieldWithDefault call; determine how presence should affect the default. Done means an unset optional field produces undefined rather than 0 or an empty string, with coverage for the demonstrated proto.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100