OLD | NEW |
1 # Protocol Buffers - Google's data interchange format | 1 # Protocol Buffers - Google's data interchange format |
2 # Copyright 2008 Google Inc. All rights reserved. | 2 # Copyright 2008 Google Inc. All rights reserved. |
3 # https://developers.google.com/protocol-buffers/ | 3 # https://developers.google.com/protocol-buffers/ |
4 # | 4 # |
5 # Redistribution and use in source and binary forms, with or without | 5 # Redistribution and use in source and binary forms, with or without |
6 # modification, are permitted provided that the following conditions are | 6 # modification, are permitted provided that the following conditions are |
7 # met: | 7 # met: |
8 # | 8 # |
9 # * Redistributions of source code must retain the above copyright | 9 # * Redistributions of source code must retain the above copyright |
10 # notice, this list of conditions and the following disclaimer. | 10 # notice, this list of conditions and the following disclaimer. |
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 Note that enum_types_by_name, extensions_by_name, and dependencies | 776 Note that enum_types_by_name, extensions_by_name, and dependencies |
777 fields are only set by the message_factory module, and not by the | 777 fields are only set by the message_factory module, and not by the |
778 generated proto code. | 778 generated proto code. |
779 | 779 |
780 name: name of file, relative to root of source tree. | 780 name: name of file, relative to root of source tree. |
781 package: name of the package | 781 package: name of the package |
782 syntax: string indicating syntax of the file (can be "proto2" or "proto3") | 782 syntax: string indicating syntax of the file (can be "proto2" or "proto3") |
783 serialized_pb: (str) Byte string of serialized | 783 serialized_pb: (str) Byte string of serialized |
784 descriptor_pb2.FileDescriptorProto. | 784 descriptor_pb2.FileDescriptorProto. |
785 dependencies: List of other FileDescriptors this FileDescriptor depends on. | 785 dependencies: List of other FileDescriptors this FileDescriptor depends on. |
| 786 public_dependencies: A list of FileDescriptors, subset of the dependencies |
| 787 above, which were declared as "public". |
786 message_types_by_name: Dict of message names of their descriptors. | 788 message_types_by_name: Dict of message names of their descriptors. |
787 enum_types_by_name: Dict of enum names and their descriptors. | 789 enum_types_by_name: Dict of enum names and their descriptors. |
788 extensions_by_name: Dict of extension names and their descriptors. | 790 extensions_by_name: Dict of extension names and their descriptors. |
789 pool: the DescriptorPool this descriptor belongs to. When not passed to the | 791 pool: the DescriptorPool this descriptor belongs to. When not passed to the |
790 constructor, the global default pool is used. | 792 constructor, the global default pool is used. |
791 """ | 793 """ |
792 | 794 |
793 if _USE_C_DESCRIPTORS: | 795 if _USE_C_DESCRIPTORS: |
794 _C_DESCRIPTOR_CLASS = _message.FileDescriptor | 796 _C_DESCRIPTOR_CLASS = _message.FileDescriptor |
795 | 797 |
796 def __new__(cls, name, package, options=None, serialized_pb=None, | 798 def __new__(cls, name, package, options=None, serialized_pb=None, |
797 dependencies=None, syntax=None, pool=None): | 799 dependencies=None, public_dependencies=None, |
| 800 syntax=None, pool=None): |
798 # FileDescriptor() is called from various places, not only from generated | 801 # FileDescriptor() is called from various places, not only from generated |
799 # files, to register dynamic proto files and messages. | 802 # files, to register dynamic proto files and messages. |
800 if serialized_pb: | 803 if serialized_pb: |
801 # TODO(amauryfa): use the pool passed as argument. This will work only | 804 # TODO(amauryfa): use the pool passed as argument. This will work only |
802 # for C++-implemented DescriptorPools. | 805 # for C++-implemented DescriptorPools. |
803 return _message.default_pool.AddSerializedFile(serialized_pb) | 806 return _message.default_pool.AddSerializedFile(serialized_pb) |
804 else: | 807 else: |
805 return super(FileDescriptor, cls).__new__(cls) | 808 return super(FileDescriptor, cls).__new__(cls) |
806 | 809 |
807 def __init__(self, name, package, options=None, serialized_pb=None, | 810 def __init__(self, name, package, options=None, serialized_pb=None, |
808 dependencies=None, syntax=None, pool=None): | 811 dependencies=None, public_dependencies=None, |
| 812 syntax=None, pool=None): |
809 """Constructor.""" | 813 """Constructor.""" |
810 super(FileDescriptor, self).__init__(options, 'FileOptions') | 814 super(FileDescriptor, self).__init__(options, 'FileOptions') |
811 | 815 |
812 if pool is None: | 816 if pool is None: |
813 from google.protobuf import descriptor_pool | 817 from google.protobuf import descriptor_pool |
814 pool = descriptor_pool.Default() | 818 pool = descriptor_pool.Default() |
815 self.pool = pool | 819 self.pool = pool |
816 self.message_types_by_name = {} | 820 self.message_types_by_name = {} |
817 self.name = name | 821 self.name = name |
818 self.package = package | 822 self.package = package |
819 self.syntax = syntax or "proto2" | 823 self.syntax = syntax or "proto2" |
820 self.serialized_pb = serialized_pb | 824 self.serialized_pb = serialized_pb |
821 | 825 |
822 self.enum_types_by_name = {} | 826 self.enum_types_by_name = {} |
823 self.extensions_by_name = {} | 827 self.extensions_by_name = {} |
824 self.dependencies = (dependencies or []) | 828 self.dependencies = (dependencies or []) |
| 829 self.public_dependencies = (public_dependencies or []) |
825 | 830 |
826 if (api_implementation.Type() == 'cpp' and | 831 if (api_implementation.Type() == 'cpp' and |
827 self.serialized_pb is not None): | 832 self.serialized_pb is not None): |
828 _message.default_pool.AddSerializedFile(self.serialized_pb) | 833 _message.default_pool.AddSerializedFile(self.serialized_pb) |
829 | 834 |
830 def CopyToProto(self, proto): | 835 def CopyToProto(self, proto): |
831 """Copies this to a descriptor_pb2.FileDescriptorProto. | 836 """Copies this to a descriptor_pb2.FileDescriptorProto. |
832 | 837 |
833 Args: | 838 Args: |
834 proto: An empty descriptor_pb2.FileDescriptorProto. | 839 proto: An empty descriptor_pb2.FileDescriptorProto. |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
957 field_proto.number, field_proto.type, | 962 field_proto.number, field_proto.type, |
958 FieldDescriptor.ProtoTypeToCppProtoType(field_proto.type), | 963 FieldDescriptor.ProtoTypeToCppProtoType(field_proto.type), |
959 field_proto.label, None, nested_desc, enum_desc, None, False, None, | 964 field_proto.label, None, nested_desc, enum_desc, None, False, None, |
960 options=field_proto.options, has_default_value=False) | 965 options=field_proto.options, has_default_value=False) |
961 fields.append(field) | 966 fields.append(field) |
962 | 967 |
963 desc_name = '.'.join(full_message_name) | 968 desc_name = '.'.join(full_message_name) |
964 return Descriptor(desc_proto.name, desc_name, None, None, fields, | 969 return Descriptor(desc_proto.name, desc_name, None, None, fields, |
965 list(nested_types.values()), list(enum_types.values()), [], | 970 list(nested_types.values()), list(enum_types.values()), [], |
966 options=desc_proto.options) | 971 options=desc_proto.options) |
OLD | NEW |