Generate alternate accessor for fields with presence

未关闭
#182 3 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
javascript
领域
backend

调研方向

通过生成所示的 OptTest 消息并调用 toObject,重现可选字段的情况。先从生成的 toObject 代码和 getFieldWithDefault 调用入手;确定 presence 应如何影响默认值。完成标准是:未设置的可选字段产生 undefined,而不是 0 或空字符串,并且为所示的 proto 提供覆盖。

由索引模型根据 Issue 内容生成。

描述

enhancement port-fix triaged

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
主要语言
JavaScript
星标
471
派生
91
平均合并
3 小时 57 分钟
30 天内合并 PR
2

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

protocolbuffers/protobuf-javascript 的其他 Issue

查看 protocolbuffers/protobuf-javascript 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。