Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/google/protobuf/internal/message_listener.py: 75%

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"""Defines a listener interface for observing certain 

9state transitions on Message objects. 

10 

11Also defines a null implementation of this interface. 

12""" 

13 

14__author__ = 'robinson@google.com (Will Robinson)' 

15 

16 

17class MessageListener(object): 

18 

19 """Listens for modifications made to a message. Meant to be registered via 

20 Message._SetListener(). 

21 

22 Attributes: 

23 dirty: If True, then calling Modified() would be a no-op. This can be 

24 used to avoid these calls entirely in the common case. 

25 """ 

26 

27 def Modified(self): 

28 """Called every time the message is modified in such a way that the parent 

29 message may need to be updated. This currently means either: 

30 (a) The message was modified for the first time, so the parent message 

31 should henceforth mark the message as present. 

32 (b) The message's cached byte size became dirty -- i.e. the message was 

33 modified for the first time after a previous call to ByteSize(). 

34 Therefore the parent should also mark its byte size as dirty. 

35 Note that (a) implies (b), since new objects start out with a client cached 

36 size (zero). However, we document (a) explicitly because it is important. 

37 

38 Modified() will *only* be called in response to one of these two events -- 

39 not every time the sub-message is modified. 

40 

41 Note that if the listener's |dirty| attribute is true, then calling 

42 Modified at the moment would be a no-op, so it can be skipped. Performance- 

43 sensitive callers should check this attribute directly before calling since 

44 it will be true most of the time. 

45 """ 

46 

47 raise NotImplementedError 

48 

49 

50class NullMessageListener(object): 

51 

52 """No-op MessageListener implementation.""" 

53 

54 def Modified(self): 

55 pass