如何在 kotlin 中销毁 grpc 消息?
How to destruct a grpc message in kotlin?
我想像这样销毁一个 grpc 消息。
message AskOrUpdateQuestionRequest {
int64 user_id = 1;
int64 product_id = 2;
core.model.QuestionProfile question = 3;
}
message QuestionProfile {
int64 id = 1;
Question.Status status = 2;
Question.Type type = 3;
string title = 4;
}
我尝试破坏这个对象? Kotlin 中的(grpc 消息)
val (title) = request.question
但是,它因错误而失败。
Destructuring declaration initializer of type QuestionModelProtos.QuestionProfile! must have a 'component1()' function
我怎样才能做到这一点
希望这是有道理的。
已解决:@Alex Filatov 的回答帮助我解决了问题。
val (title) = request.question
compiles to val title = request.question.component1()
. Protobuf classes don't have componentX()
methods, so you need to add them:
operator fun QuestionModelProtos.QuestionProfile.component1() = this.title
我想像这样销毁一个 grpc 消息。
message AskOrUpdateQuestionRequest {
int64 user_id = 1;
int64 product_id = 2;
core.model.QuestionProfile question = 3;
}
message QuestionProfile {
int64 id = 1;
Question.Status status = 2;
Question.Type type = 3;
string title = 4;
}
我尝试破坏这个对象? Kotlin 中的(grpc 消息)
val (title) = request.question
但是,它因错误而失败。
Destructuring declaration initializer of type QuestionModelProtos.QuestionProfile! must have a 'component1()' function
我怎样才能做到这一点
希望这是有道理的。
已解决:@Alex Filatov 的回答帮助我解决了问题。
val (title) = request.question
compiles to val title = request.question.component1()
. Protobuf classes don't have componentX()
methods, so you need to add them:
operator fun QuestionModelProtos.QuestionProfile.component1() = this.title