通过protobuf传递对象数组

时间:2017-11-27 02:49:12

标签: protocol-buffers grpc

我一直遇到同样的错误:keyOrObj.hasOwnProperty is not a function

要传递的数据

{
  "stocks": [{
    "quantity":3,
    "substore_uuid": "2343423443423"
  }]
}

这是我的原型宣言

service Procurement {
  rpc distributeUpsert (ProcurementStockDistributionUpsertReq) returns (ProcurementStockDistributionRes) {}
}

message ProcurementStockDistributionUpsertReq {
  message ProcurementStockDistributionUpsertReqInput {
    string uuid = 1;
    int32 quantity = 2;
    string procurement_detail_uuid = 3;
    string distribution_officer_uuid = 4;
    string substore_uuid = 5;
  }
  repeated ProcurementStockDistributionUpsertReqInput stocks = 1;
}

这里是触发错误的代码

const protoArgs = cloneDeep({
   stocks: [...args.stocks.map(stock => stock)],
});
svc.SM.Procurement.distributeUpsert(
   protoArgs,
   (err, response = {}) => {
      if (err) {
         reject(err);
         return;
      }
      resolve(response);
   },
);

我是否必须使用如here所示的流。有什么建议吗?

0 个答案:

没有答案