protobuf/reflect/service/
index.rs

1use crate::descriptor::MethodDescriptorProto;
2use crate::descriptor::ServiceDescriptorProto;
3use crate::reflect::field::index::ForwardProtobufTypeBox;
4use crate::reflect::file::building::FileDescriptorBuilding;
5
6#[derive(Debug)]
7pub(crate) struct ServiceIndex {
8    pub(crate) methods: Vec<MethodIndex>,
9}
10
11impl ServiceIndex {
12    pub(crate) fn index(
13        proto: &ServiceDescriptorProto,
14        building: &FileDescriptorBuilding,
15    ) -> crate::Result<ServiceIndex> {
16        let methods = proto
17            .method
18            .iter()
19            .map(|method| MethodIndex::index(method, building))
20            .collect::<crate::Result<Vec<_>>>()?;
21        Ok(ServiceIndex { methods })
22    }
23}
24
25#[derive(Debug)]
26pub(crate) struct MethodIndex {
27    pub(crate) input_type: ForwardProtobufTypeBox,
28    pub(crate) output_type: ForwardProtobufTypeBox,
29}
30
31impl MethodIndex {
32    pub(crate) fn index(
33        proto: &MethodDescriptorProto,
34        building: &FileDescriptorBuilding,
35    ) -> crate::Result<MethodIndex> {
36        let input_type = building.resolve_message(proto.input_type())?;
37        let output_type = building.resolve_message(proto.output_type())?;
38        Ok(MethodIndex {
39            input_type,
40            output_type,
41        })
42    }
43}