Skip to content

Commit

Permalink
Add MethodDescriptor.CopyToProto()
Browse files Browse the repository at this point in the history
  • Loading branch information
alkasm committed Feb 22, 2021
1 parent 133e5e7 commit 393e453
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions python/google/protobuf/descriptor.py
Expand Up @@ -912,6 +912,24 @@ def __init__(self, name, full_name, index, containing_service,
self.containing_service = containing_service
self.input_type = input_type
self.output_type = output_type

def CopyToProto(self, proto):
"""Copies this to a descriptor_pb2.MethodDescriptorProto.
Args:
proto (descriptor_pb2.MethodDescriptorProto): An empty descriptor proto.
Raises:
Error: If self couldn't be serialized, due to too few constructor
arguments.
"""
if self.containing_service is not None:
from google.protobuf import descriptor_pb2
service_proto = descriptor_pb2.ServiceDescriptorProto()
self.containing_service.CopyToProto(service_proto)
proto.CopyFrom(service_proto.method[self.index])
else:
raise Error('Descriptor does not contain a service.')


class FileDescriptor(DescriptorBase):
Expand Down

0 comments on commit 393e453

Please sign in to comment.