gpt4 book ai didi

javascript - Protocol Buffer - 分配嵌套消息

转载 作者:行者123 更新时间:2023-12-04 02:20:29 26 4
gpt4 key购买 nike

我的 PB 架构如下所示:

message ProductRecommendationReply {
string productid = 1;
message recommendationlist{
string recommendedproductid = 1;
string recommendedproductname = 2;
string recommendedproductprice = 3;
}
}

在服务器端(node.js),我正在尝试设置如下属性:
var message = {
productid: '',
recommendationlist: []
};
message.productid = result_list.product_Id;
message.recommendationlist.recommendedproductid = result_list.recomendation_list[0].recommended_product_id;
message.recommendationlist.recommendedproductname = result_list.recomendation_list[0].recommended_product_name;
message.recommendationlist.recommendedproductprice = result_list.recomendation_list[0].recommended_product_price;

callback(null,message); // send the result back to consumer.

问题是在调试clinet端时,只有 productid有一个赋值给它, recommendationlist是空的。

如何正确地为嵌套消息赋值?

最佳答案

您定义了一条消息,但没有声明该消息类型的字段。我想你的意思是

message ProductRecommendationReply {
string productid = 1;
message productrecommendationlist {
string recommendedproductid = 1;
string recommendedproductname = 2;
string recommendedproductprice = 3;
}
repeated productrecommendationlist recommendationlist = 2;
}

关于javascript - Protocol Buffer - 分配嵌套消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60040099/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com