Proto Repeated Custom Item Syntax
I came across this code:
message MapTaskAssignment {
uint32 task = 1;
uint32 worker_id = 2;
}
message GetTaskReply {
...
repeated MapTaskAssignment map_task_assignments = 10;
}
I've seen repeated string
before. But what does it mean when the repeated item is another proto object (repeated MapT开发者_StackOverflowaskAssignment
)? How does it work and how can I access the fields inside?
Edit:
Specifically, using rust, what type does repeated MapTaskAssignment
convert to? is it a Vec
of struct MapTaskAssignment
?
In the same manner RepeatedField
is defined in google/protobuf/repeated_field.h, prost - Protocol Buffers implementation for Rust defines repeated
: Vec<T>
.
For your sample Protocol Buffers definition tonic-build would create
pub struct MapTaskAssignment {
#[prost(uint32, tag = "1")]
pub task: u32,
#[prost(uint32, tag = "2")]
pub worker_id: u32,
}
pub struct GetTaskReply {
#[prost(message, repeated, tag = "10")]
pub map_task_assignments: ::prost::alloc::vec::Vec<MapTaskAssignment>,
}
精彩评论