Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/google/protobuf/pyext/cpp_message.py: 88%

8 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-12-08 06:40 +0000

1# Protocol Buffers - Google's data interchange format 

2# Copyright 2008 Google Inc. All rights reserved. 

3# 

4# Use of this source code is governed by a BSD-style 

5# license that can be found in the LICENSE file or at 

6# https://developers.google.com/open-source/licenses/bsd 

7 

8"""Protocol message implementation hooks for C++ implementation. 

9 

10Contains helper functions used to create protocol message classes from 

11Descriptor objects at runtime backed by the protocol buffer C++ API. 

12""" 

13 

14__author__ = 'tibell@google.com (Johan Tibell)' 

15 

16from google.protobuf.internal import api_implementation 

17 

18 

19# pylint: disable=protected-access 

20_message = api_implementation._c_module 

21# TODO: Remove this import after fix api_implementation 

22if _message is None: 

23 from google.protobuf.pyext import _message 

24 

25 

26class GeneratedProtocolMessageType(_message.MessageMeta): 

27 

28 """Metaclass for protocol message classes created at runtime from Descriptors. 

29 

30 The protocol compiler currently uses this metaclass to create protocol 

31 message classes at runtime. Clients can also manually create their own 

32 classes at runtime, as in this example: 

33 

34 mydescriptor = Descriptor(.....) 

35 factory = symbol_database.Default() 

36 factory.pool.AddDescriptor(mydescriptor) 

37 MyProtoClass = factory.GetPrototype(mydescriptor) 

38 myproto_instance = MyProtoClass() 

39 myproto.foo_field = 23 

40 ... 

41 

42 The above example will not work for nested types. If you wish to include them, 

43 use reflection.MakeClass() instead of manually instantiating the class in 

44 order to create the appropriate class structure. 

45 """ 

46 

47 # Must be consistent with the protocol-compiler code in 

48 # proto2/compiler/internal/generator.*. 

49 _DESCRIPTOR_KEY = 'DESCRIPTOR'