From 53fab9f838a08925e35b31971562d8a3aff94a35 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Thu, 15 Oct 2020 08:24:59 +0800 Subject: [PATCH] 1.1.6 --- docs/meshtastic/index.html | 26 +- docs/meshtastic/mesh_pb2.html | 9540 ++++++++++++++++++++++++++++++++- setup.py | 2 +- 3 files changed, 9421 insertions(+), 147 deletions(-) diff --git a/docs/meshtastic/index.html b/docs/meshtastic/index.html index 9caf5d2..7ecc916 100644 --- a/docs/meshtastic/index.html +++ b/docs/meshtastic/index.html @@ -456,8 +456,17 @@ class MeshInterface: # For text messages, we go ahead and decode the text to ascii for our users if asDict["decoded"]["data"]["typ"] == "CLEAR_TEXT": topic = "meshtastic.receive.text" - asDict["decoded"]["data"]["text"] = meshPacket.decoded.data.payload.decode( - "utf-8") + + # We don't throw if the utf8 is invalid in the text message. Instead we just don't populate + # the decoded.data.text and we log an error message. This at least allows some delivery to + # the app and the app can deal with the missing decoded representation. + # + # Usually btw this problem is caused by apps sending binary data but setting the payload type to + # text. + try: + asDict["decoded"]["data"]["text"] = meshPacket.decoded.data.payload.decode("utf-8") + except Exception as ex: + logging.error(f"Malformatted utf8 in text message: {ex}") pub.sendMessage(topic, packet=asDict, interface=self) @@ -1141,8 +1150,17 @@ debugOut

# For text messages, we go ahead and decode the text to ascii for our users if asDict["decoded"]["data"]["typ"] == "CLEAR_TEXT": topic = "meshtastic.receive.text" - asDict["decoded"]["data"]["text"] = meshPacket.decoded.data.payload.decode( - "utf-8") + + # We don't throw if the utf8 is invalid in the text message. Instead we just don't populate + # the decoded.data.text and we log an error message. This at least allows some delivery to + # the app and the app can deal with the missing decoded representation. + # + # Usually btw this problem is caused by apps sending binary data but setting the payload type to + # text. + try: + asDict["decoded"]["data"]["text"] = meshPacket.decoded.data.payload.decode("utf-8") + except Exception as ex: + logging.error(f"Malformatted utf8 in text message: {ex}") pub.sendMessage(topic, packet=asDict, interface=self) diff --git a/docs/meshtastic/mesh_pb2.html b/docs/meshtastic/mesh_pb2.html index a091770..673292c 100644 --- a/docs/meshtastic/mesh_pb2.html +++ b/docs/meshtastic/mesh_pb2.html @@ -1775,17 +1775,24 @@ DESCRIPTOR._options = None
class ChannelSettings -(*args, **kwargs) +(**kwargs)
-

A ProtocolMessage

+

Abstract base class for protocol messages.

+

Protocol message classes are almost always generated by the protocol +compiler. +These generated types subclass Message and implement the methods +shown below.

Ancestors

    -
  • google.protobuf.pyext._message.CMessage
  • google.protobuf.message.Message

Class variables

+
var BANDWIDTH_FIELD_NUMBER
+
+
+
var Bw125Cr45Sf128
@@ -1802,60 +1809,661 @@ DESCRIPTOR._options = None
+
var CHANNEL_NUM_FIELD_NUMBER
+
+
+
+
var CODING_RATE_FIELD_NUMBER
+
+
+
var DESCRIPTOR
+
var MODEM_CONFIG_FIELD_NUMBER
+
+
+
var ModemConfig
+
var NAME_FIELD_NUMBER
+
+
+
+
var PSK_FIELD_NUMBER
+
+
+
+
var SPREAD_FACTOR_FIELD_NUMBER
+
+
+
+
var TX_POWER_FIELD_NUMBER
+
+
+
+
+

Static methods

+
+
+def FromString(s) +
+
+
+
+ +Expand source code + +
def FromString(s):
+  message = cls()
+  message.MergeFromString(s)
+  return message
+
+
+
+def RegisterExtension(extension_handle) +
+
+
+
+ +Expand source code + +
def RegisterExtension(extension_handle):
+  extension_handle.containing_type = cls.DESCRIPTOR
+  # TODO(amauryfa): Use cls.MESSAGE_FACTORY.pool when available.
+  # pylint: disable=protected-access
+  cls.DESCRIPTOR.file.pool._AddExtensionDescriptor(extension_handle)
+  _AttachFieldHelpers(cls, extension_handle)
+
+

Instance variables

var bandwidth
-

Field ChannelSettings.bandwidth

+

Getter for bandwidth.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var channel_num
-

Field ChannelSettings.channel_num

+

Getter for channel_num.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var coding_rate
-

Field ChannelSettings.coding_rate

+

Getter for coding_rate.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var modem_config
-

Field ChannelSettings.modem_config

+

Getter for modem_config.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var name
-

Field ChannelSettings.name

+

Getter for name.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var psk
-

Field ChannelSettings.psk

+

Getter for psk.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var spread_factor
-

Field ChannelSettings.spread_factor

+

Getter for spread_factor.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var tx_power
-

Field ChannelSettings.tx_power

+

Getter for tx_power.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
+
+
+

Methods

+
+
+def ByteSize(self) +
+
+
+
+ +Expand source code + +
def ByteSize(self):
+  if not self._cached_byte_size_dirty:
+    return self._cached_byte_size
+
+  size = 0
+  descriptor = self.DESCRIPTOR
+  if descriptor.GetOptions().map_entry:
+    # Fields of map entry should always be serialized.
+    size = descriptor.fields_by_name['key']._sizer(self.key)
+    size += descriptor.fields_by_name['value']._sizer(self.value)
+  else:
+    for field_descriptor, field_value in self.ListFields():
+      size += field_descriptor._sizer(field_value)
+    for tag_bytes, value_bytes in self._unknown_fields:
+      size += len(tag_bytes) + len(value_bytes)
+
+  self._cached_byte_size = size
+  self._cached_byte_size_dirty = False
+  self._listener_for_children.dirty = False
+  return size
+
+
+
+def Clear(self) +
+
+
+
+ +Expand source code + +
def _Clear(self):
+  # Clear fields.
+  self._fields = {}
+  self._unknown_fields = ()
+  # pylint: disable=protected-access
+  if self._unknown_field_set is not None:
+    self._unknown_field_set._clear()
+    self._unknown_field_set = None
+
+  self._oneofs = {}
+  self._Modified()
+
+
+
+def ClearField(self, field_name) +
+
+
+
+ +Expand source code + +
def ClearField(self, field_name):
+  try:
+    field = message_descriptor.fields_by_name[field_name]
+  except KeyError:
+    try:
+      field = message_descriptor.oneofs_by_name[field_name]
+      if field in self._oneofs:
+        field = self._oneofs[field]
+      else:
+        return
+    except KeyError:
+      raise ValueError('Protocol message %s has no "%s" field.' %
+                       (message_descriptor.name, field_name))
+
+  if field in self._fields:
+    # To match the C++ implementation, we need to invalidate iterators
+    # for map fields when ClearField() happens.
+    if hasattr(self._fields[field], 'InvalidateIterators'):
+      self._fields[field].InvalidateIterators()
+
+    # Note:  If the field is a sub-message, its listener will still point
+    #   at us.  That's fine, because the worst than can happen is that it
+    #   will call _Modified() and invalidate our byte size.  Big deal.
+    del self._fields[field]
+
+    if self._oneofs.get(field.containing_oneof, None) is field:
+      del self._oneofs[field.containing_oneof]
+
+  # Always call _Modified() -- even if nothing was changed, this is
+  # a mutating method, and thus calling it should cause the field to become
+  # present in the parent message.
+  self._Modified()
+
+
+
+def DiscardUnknownFields(self) +
+
+
+
+ +Expand source code + +
def _DiscardUnknownFields(self):
+  self._unknown_fields = []
+  self._unknown_field_set = None      # pylint: disable=protected-access
+  for field, value in self.ListFields():
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if _IsMapField(field):
+        if _IsMessageMapField(field):
+          for key in value:
+            value[key].DiscardUnknownFields()
+      elif field.label == _FieldDescriptor.LABEL_REPEATED:
+        for sub_message in value:
+          sub_message.DiscardUnknownFields()
+      else:
+        value.DiscardUnknownFields()
+
+
+
+def FindInitializationErrors(self) +
+
+

Finds required fields which are not initialized.

+

Returns

+

A list of strings. +Each string is a path to an uninitialized field from +the top-level message, e.g. "foo.bar[5].baz".

+
+ +Expand source code + +
def FindInitializationErrors(self):
+  """Finds required fields which are not initialized.
+
+  Returns:
+    A list of strings.  Each string is a path to an uninitialized field from
+    the top-level message, e.g. "foo.bar[5].baz".
+  """
+
+  errors = []  # simplify things
+
+  for field in required_fields:
+    if not self.HasField(field.name):
+      errors.append(field.name)
+
+  for field, value in self.ListFields():
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if field.is_extension:
+        name = '(%s)' % field.full_name
+      else:
+        name = field.name
+
+      if _IsMapField(field):
+        if _IsMessageMapField(field):
+          for key in value:
+            element = value[key]
+            prefix = '%s[%s].' % (name, key)
+            sub_errors = element.FindInitializationErrors()
+            errors += [prefix + error for error in sub_errors]
+        else:
+          # ScalarMaps can't have any initialization errors.
+          pass
+      elif field.label == _FieldDescriptor.LABEL_REPEATED:
+        for i in range(len(value)):
+          element = value[i]
+          prefix = '%s[%d].' % (name, i)
+          sub_errors = element.FindInitializationErrors()
+          errors += [prefix + error for error in sub_errors]
+      else:
+        prefix = name + '.'
+        sub_errors = value.FindInitializationErrors()
+        errors += [prefix + error for error in sub_errors]
+
+  return errors
+
+
+
+def HasField(self, field_name) +
+
+
+
+ +Expand source code + +
def HasField(self, field_name):
+  try:
+    field = hassable_fields[field_name]
+  except KeyError:
+    raise ValueError(error_msg % (message_descriptor.full_name, field_name))
+
+  if isinstance(field, descriptor_mod.OneofDescriptor):
+    try:
+      return HasField(self, self._oneofs[field].name)
+    except KeyError:
+      return False
+  else:
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      value = self._fields.get(field)
+      return value is not None and value._is_present_in_parent
+    else:
+      return field in self._fields
+
+
+
+def IsInitialized(self, errors=None) +
+
+

Checks if all required fields of a message are set.

+

Args

+
+
errors
+
A list which, if provided, will be populated with the field +paths of all missing required fields.
+
+

Returns

+

True iff the specified message has all required fields set.

+
+ +Expand source code + +
def IsInitialized(self, errors=None):
+  """Checks if all required fields of a message are set.
+
+  Args:
+    errors:  A list which, if provided, will be populated with the field
+             paths of all missing required fields.
+
+  Returns:
+    True iff the specified message has all required fields set.
+  """
+
+  # Performance is critical so we avoid HasField() and ListFields().
+
+  for field in required_fields:
+    if (field not in self._fields or
+        (field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE and
+         not self._fields[field]._is_present_in_parent)):
+      if errors is not None:
+        errors.extend(self.FindInitializationErrors())
+      return False
+
+  for field, value in list(self._fields.items()):  # dict can change size!
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if field.label == _FieldDescriptor.LABEL_REPEATED:
+        if (field.message_type.has_options and
+            field.message_type.GetOptions().map_entry):
+          continue
+        for element in value:
+          if not element.IsInitialized():
+            if errors is not None:
+              errors.extend(self.FindInitializationErrors())
+            return False
+      elif value._is_present_in_parent and not value.IsInitialized():
+        if errors is not None:
+          errors.extend(self.FindInitializationErrors())
+        return False
+
+  return True
+
+
+
+def ListFields(self) +
+
+
+
+ +Expand source code + +
def ListFields(self):
+  all_fields = [item for item in self._fields.items() if _IsPresent(item)]
+  all_fields.sort(key = lambda item: item[0].number)
+  return all_fields
+
+
+
+def MergeFrom(self, msg) +
+
+
+
+ +Expand source code + +
def MergeFrom(self, msg):
+  if not isinstance(msg, cls):
+    raise TypeError(
+        'Parameter to MergeFrom() must be instance of same class: '
+        'expected %s got %s.' % (cls.__name__, msg.__class__.__name__))
+
+  assert msg is not self
+  self._Modified()
+
+  fields = self._fields
+
+  for field, value in msg._fields.items():
+    if field.label == LABEL_REPEATED:
+      field_value = fields.get(field)
+      if field_value is None:
+        # Construct a new object to represent this field.
+        field_value = field._default_constructor(self)
+        fields[field] = field_value
+      field_value.MergeFrom(value)
+    elif field.cpp_type == CPPTYPE_MESSAGE:
+      if value._is_present_in_parent:
+        field_value = fields.get(field)
+        if field_value is None:
+          # Construct a new object to represent this field.
+          field_value = field._default_constructor(self)
+          fields[field] = field_value
+        field_value.MergeFrom(value)
+    else:
+      self._fields[field] = value
+      if field.containing_oneof:
+        self._UpdateOneofState(field)
+
+  if msg._unknown_fields:
+    if not self._unknown_fields:
+      self._unknown_fields = []
+    self._unknown_fields.extend(msg._unknown_fields)
+    # pylint: disable=protected-access
+    if self._unknown_field_set is None:
+      self._unknown_field_set = containers.UnknownFieldSet()
+    self._unknown_field_set._extend(msg._unknown_field_set)
+
+
+
+def MergeFromString(self, serialized) +
+
+
+
+ +Expand source code + +
def MergeFromString(self, serialized):
+  if isinstance(serialized, memoryview) and six.PY2:
+    raise TypeError(
+        'memoryview not supported in Python 2 with the pure Python proto '
+        'implementation: this is to maintain compatibility with the C++ '
+        'implementation')
+
+  serialized = memoryview(serialized)
+  length = len(serialized)
+  try:
+    if self._InternalParse(serialized, 0, length) != length:
+      # The only reason _InternalParse would return early is if it
+      # encountered an end-group tag.
+      raise message_mod.DecodeError('Unexpected end-group tag.')
+  except (IndexError, TypeError):
+    # Now ord(buf[p:p+1]) == ord('') gets TypeError.
+    raise message_mod.DecodeError('Truncated message.')
+  except struct.error as e:
+    raise message_mod.DecodeError(e)
+  return length   # Return this for legacy reasons.
+
+
+
+def SerializePartialToString(self, **kwargs) +
+
+
+
+ +Expand source code + +
def SerializePartialToString(self, **kwargs):
+  out = BytesIO()
+  self._InternalSerialize(out.write, **kwargs)
+  return out.getvalue()
+
+
+
+def SerializeToString(self, **kwargs) +
+
+
+
+ +Expand source code + +
def SerializeToString(self, **kwargs):
+  # Check if the message has all of its required fields set.
+  if not self.IsInitialized():
+    raise message_mod.EncodeError(
+        'Message %s is missing required fields: %s' % (
+        self.DESCRIPTOR.full_name, ','.join(self.FindInitializationErrors())))
+  return self.SerializePartialToString(**kwargs)
+
+
+
+def SetInParent(self) +
+
+

Sets the _cached_byte_size_dirty bit to true, +and propagates this to our listener iff this was a state change.

+
+ +Expand source code + +
def Modified(self):
+  """Sets the _cached_byte_size_dirty bit to true,
+  and propagates this to our listener iff this was a state change.
+  """
+
+  # Note:  Some callers check _cached_byte_size_dirty before calling
+  #   _Modified() as an extra optimization.  So, if this method is ever
+  #   changed such that it does stuff even when _cached_byte_size_dirty is
+  #   already true, the callers need to be updated.
+  if not self._cached_byte_size_dirty:
+    self._cached_byte_size_dirty = True
+    self._listener_for_children.dirty = True
+    self._is_present_in_parent = True
+    self._listener.Modified()
+
+
+
+def UnknownFields(self) +
+
+
+
+ +Expand source code + +
def _UnknownFields(self):
+  if self._unknown_field_set is None:  # pylint: disable=protected-access
+    # pylint: disable=protected-access
+    self._unknown_field_set = containers.UnknownFieldSet()
+  return self._unknown_field_set    # pylint: disable=protected-access
+
+
+
+def WhichOneof(self, oneof_name) +
+
+

Returns the name of the currently set field inside a oneof, or None.

+
+ +Expand source code + +
def WhichOneof(self, oneof_name):
+  """Returns the name of the currently set field inside a oneof, or None."""
+  try:
+    field = message_descriptor.oneofs_by_name[oneof_name]
+  except KeyError:
+    raise ValueError(
+        'Protocol message has no oneof "%s" field.' % oneof_name)
+
+  nested_field = self._oneofs.get(field, None)
+  if nested_field is not None and self.HasField(nested_field.name):
+    return nested_field.name
+  else:
+    return None
+
class Data -(*args, **kwargs) +(**kwargs)
-

A ProtocolMessage

+

Abstract base class for protocol messages.

+

Protocol message classes are almost always generated by the protocol +compiler. +These generated types subclass Message and implement the methods +shown below.

Ancestors

    -
  • google.protobuf.pyext._message.CMessage
  • google.protobuf.message.Message

Class variables

@@ -1876,32 +2484,559 @@ DESCRIPTOR._options = None
+
var PAYLOAD_FIELD_NUMBER
+
+
+
+
var TYP_FIELD_NUMBER
+
+
+
var Type
+

Static methods

+
+
+def FromString(s) +
+
+
+
+ +Expand source code + +
def FromString(s):
+  message = cls()
+  message.MergeFromString(s)
+  return message
+
+
+
+def RegisterExtension(extension_handle) +
+
+
+
+ +Expand source code + +
def RegisterExtension(extension_handle):
+  extension_handle.containing_type = cls.DESCRIPTOR
+  # TODO(amauryfa): Use cls.MESSAGE_FACTORY.pool when available.
+  # pylint: disable=protected-access
+  cls.DESCRIPTOR.file.pool._AddExtensionDescriptor(extension_handle)
+  _AttachFieldHelpers(cls, extension_handle)
+
+
+

Instance variables

var payload
-

Field Data.payload

+

Getter for payload.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var typ
-

Field Data.typ

+

Getter for typ.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
+
+
+

Methods

+
+
+def ByteSize(self) +
+
+
+
+ +Expand source code + +
def ByteSize(self):
+  if not self._cached_byte_size_dirty:
+    return self._cached_byte_size
+
+  size = 0
+  descriptor = self.DESCRIPTOR
+  if descriptor.GetOptions().map_entry:
+    # Fields of map entry should always be serialized.
+    size = descriptor.fields_by_name['key']._sizer(self.key)
+    size += descriptor.fields_by_name['value']._sizer(self.value)
+  else:
+    for field_descriptor, field_value in self.ListFields():
+      size += field_descriptor._sizer(field_value)
+    for tag_bytes, value_bytes in self._unknown_fields:
+      size += len(tag_bytes) + len(value_bytes)
+
+  self._cached_byte_size = size
+  self._cached_byte_size_dirty = False
+  self._listener_for_children.dirty = False
+  return size
+
+
+
+def Clear(self) +
+
+
+
+ +Expand source code + +
def _Clear(self):
+  # Clear fields.
+  self._fields = {}
+  self._unknown_fields = ()
+  # pylint: disable=protected-access
+  if self._unknown_field_set is not None:
+    self._unknown_field_set._clear()
+    self._unknown_field_set = None
+
+  self._oneofs = {}
+  self._Modified()
+
+
+
+def ClearField(self, field_name) +
+
+
+
+ +Expand source code + +
def ClearField(self, field_name):
+  try:
+    field = message_descriptor.fields_by_name[field_name]
+  except KeyError:
+    try:
+      field = message_descriptor.oneofs_by_name[field_name]
+      if field in self._oneofs:
+        field = self._oneofs[field]
+      else:
+        return
+    except KeyError:
+      raise ValueError('Protocol message %s has no "%s" field.' %
+                       (message_descriptor.name, field_name))
+
+  if field in self._fields:
+    # To match the C++ implementation, we need to invalidate iterators
+    # for map fields when ClearField() happens.
+    if hasattr(self._fields[field], 'InvalidateIterators'):
+      self._fields[field].InvalidateIterators()
+
+    # Note:  If the field is a sub-message, its listener will still point
+    #   at us.  That's fine, because the worst than can happen is that it
+    #   will call _Modified() and invalidate our byte size.  Big deal.
+    del self._fields[field]
+
+    if self._oneofs.get(field.containing_oneof, None) is field:
+      del self._oneofs[field.containing_oneof]
+
+  # Always call _Modified() -- even if nothing was changed, this is
+  # a mutating method, and thus calling it should cause the field to become
+  # present in the parent message.
+  self._Modified()
+
+
+
+def DiscardUnknownFields(self) +
+
+
+
+ +Expand source code + +
def _DiscardUnknownFields(self):
+  self._unknown_fields = []
+  self._unknown_field_set = None      # pylint: disable=protected-access
+  for field, value in self.ListFields():
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if _IsMapField(field):
+        if _IsMessageMapField(field):
+          for key in value:
+            value[key].DiscardUnknownFields()
+      elif field.label == _FieldDescriptor.LABEL_REPEATED:
+        for sub_message in value:
+          sub_message.DiscardUnknownFields()
+      else:
+        value.DiscardUnknownFields()
+
+
+
+def FindInitializationErrors(self) +
+
+

Finds required fields which are not initialized.

+

Returns

+

A list of strings. +Each string is a path to an uninitialized field from +the top-level message, e.g. "foo.bar[5].baz".

+
+ +Expand source code + +
def FindInitializationErrors(self):
+  """Finds required fields which are not initialized.
+
+  Returns:
+    A list of strings.  Each string is a path to an uninitialized field from
+    the top-level message, e.g. "foo.bar[5].baz".
+  """
+
+  errors = []  # simplify things
+
+  for field in required_fields:
+    if not self.HasField(field.name):
+      errors.append(field.name)
+
+  for field, value in self.ListFields():
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if field.is_extension:
+        name = '(%s)' % field.full_name
+      else:
+        name = field.name
+
+      if _IsMapField(field):
+        if _IsMessageMapField(field):
+          for key in value:
+            element = value[key]
+            prefix = '%s[%s].' % (name, key)
+            sub_errors = element.FindInitializationErrors()
+            errors += [prefix + error for error in sub_errors]
+        else:
+          # ScalarMaps can't have any initialization errors.
+          pass
+      elif field.label == _FieldDescriptor.LABEL_REPEATED:
+        for i in range(len(value)):
+          element = value[i]
+          prefix = '%s[%d].' % (name, i)
+          sub_errors = element.FindInitializationErrors()
+          errors += [prefix + error for error in sub_errors]
+      else:
+        prefix = name + '.'
+        sub_errors = value.FindInitializationErrors()
+        errors += [prefix + error for error in sub_errors]
+
+  return errors
+
+
+
+def HasField(self, field_name) +
+
+
+
+ +Expand source code + +
def HasField(self, field_name):
+  try:
+    field = hassable_fields[field_name]
+  except KeyError:
+    raise ValueError(error_msg % (message_descriptor.full_name, field_name))
+
+  if isinstance(field, descriptor_mod.OneofDescriptor):
+    try:
+      return HasField(self, self._oneofs[field].name)
+    except KeyError:
+      return False
+  else:
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      value = self._fields.get(field)
+      return value is not None and value._is_present_in_parent
+    else:
+      return field in self._fields
+
+
+
+def IsInitialized(self, errors=None) +
+
+

Checks if all required fields of a message are set.

+

Args

+
+
errors
+
A list which, if provided, will be populated with the field +paths of all missing required fields.
+
+

Returns

+

True iff the specified message has all required fields set.

+
+ +Expand source code + +
def IsInitialized(self, errors=None):
+  """Checks if all required fields of a message are set.
+
+  Args:
+    errors:  A list which, if provided, will be populated with the field
+             paths of all missing required fields.
+
+  Returns:
+    True iff the specified message has all required fields set.
+  """
+
+  # Performance is critical so we avoid HasField() and ListFields().
+
+  for field in required_fields:
+    if (field not in self._fields or
+        (field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE and
+         not self._fields[field]._is_present_in_parent)):
+      if errors is not None:
+        errors.extend(self.FindInitializationErrors())
+      return False
+
+  for field, value in list(self._fields.items()):  # dict can change size!
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if field.label == _FieldDescriptor.LABEL_REPEATED:
+        if (field.message_type.has_options and
+            field.message_type.GetOptions().map_entry):
+          continue
+        for element in value:
+          if not element.IsInitialized():
+            if errors is not None:
+              errors.extend(self.FindInitializationErrors())
+            return False
+      elif value._is_present_in_parent and not value.IsInitialized():
+        if errors is not None:
+          errors.extend(self.FindInitializationErrors())
+        return False
+
+  return True
+
+
+
+def ListFields(self) +
+
+
+
+ +Expand source code + +
def ListFields(self):
+  all_fields = [item for item in self._fields.items() if _IsPresent(item)]
+  all_fields.sort(key = lambda item: item[0].number)
+  return all_fields
+
+
+
+def MergeFrom(self, msg) +
+
+
+
+ +Expand source code + +
def MergeFrom(self, msg):
+  if not isinstance(msg, cls):
+    raise TypeError(
+        'Parameter to MergeFrom() must be instance of same class: '
+        'expected %s got %s.' % (cls.__name__, msg.__class__.__name__))
+
+  assert msg is not self
+  self._Modified()
+
+  fields = self._fields
+
+  for field, value in msg._fields.items():
+    if field.label == LABEL_REPEATED:
+      field_value = fields.get(field)
+      if field_value is None:
+        # Construct a new object to represent this field.
+        field_value = field._default_constructor(self)
+        fields[field] = field_value
+      field_value.MergeFrom(value)
+    elif field.cpp_type == CPPTYPE_MESSAGE:
+      if value._is_present_in_parent:
+        field_value = fields.get(field)
+        if field_value is None:
+          # Construct a new object to represent this field.
+          field_value = field._default_constructor(self)
+          fields[field] = field_value
+        field_value.MergeFrom(value)
+    else:
+      self._fields[field] = value
+      if field.containing_oneof:
+        self._UpdateOneofState(field)
+
+  if msg._unknown_fields:
+    if not self._unknown_fields:
+      self._unknown_fields = []
+    self._unknown_fields.extend(msg._unknown_fields)
+    # pylint: disable=protected-access
+    if self._unknown_field_set is None:
+      self._unknown_field_set = containers.UnknownFieldSet()
+    self._unknown_field_set._extend(msg._unknown_field_set)
+
+
+
+def MergeFromString(self, serialized) +
+
+
+
+ +Expand source code + +
def MergeFromString(self, serialized):
+  if isinstance(serialized, memoryview) and six.PY2:
+    raise TypeError(
+        'memoryview not supported in Python 2 with the pure Python proto '
+        'implementation: this is to maintain compatibility with the C++ '
+        'implementation')
+
+  serialized = memoryview(serialized)
+  length = len(serialized)
+  try:
+    if self._InternalParse(serialized, 0, length) != length:
+      # The only reason _InternalParse would return early is if it
+      # encountered an end-group tag.
+      raise message_mod.DecodeError('Unexpected end-group tag.')
+  except (IndexError, TypeError):
+    # Now ord(buf[p:p+1]) == ord('') gets TypeError.
+    raise message_mod.DecodeError('Truncated message.')
+  except struct.error as e:
+    raise message_mod.DecodeError(e)
+  return length   # Return this for legacy reasons.
+
+
+
+def SerializePartialToString(self, **kwargs) +
+
+
+
+ +Expand source code + +
def SerializePartialToString(self, **kwargs):
+  out = BytesIO()
+  self._InternalSerialize(out.write, **kwargs)
+  return out.getvalue()
+
+
+
+def SerializeToString(self, **kwargs) +
+
+
+
+ +Expand source code + +
def SerializeToString(self, **kwargs):
+  # Check if the message has all of its required fields set.
+  if not self.IsInitialized():
+    raise message_mod.EncodeError(
+        'Message %s is missing required fields: %s' % (
+        self.DESCRIPTOR.full_name, ','.join(self.FindInitializationErrors())))
+  return self.SerializePartialToString(**kwargs)
+
+
+
+def SetInParent(self) +
+
+

Sets the _cached_byte_size_dirty bit to true, +and propagates this to our listener iff this was a state change.

+
+ +Expand source code + +
def Modified(self):
+  """Sets the _cached_byte_size_dirty bit to true,
+  and propagates this to our listener iff this was a state change.
+  """
+
+  # Note:  Some callers check _cached_byte_size_dirty before calling
+  #   _Modified() as an extra optimization.  So, if this method is ever
+  #   changed such that it does stuff even when _cached_byte_size_dirty is
+  #   already true, the callers need to be updated.
+  if not self._cached_byte_size_dirty:
+    self._cached_byte_size_dirty = True
+    self._listener_for_children.dirty = True
+    self._is_present_in_parent = True
+    self._listener.Modified()
+
+
+
+def UnknownFields(self) +
+
+
+
+ +Expand source code + +
def _UnknownFields(self):
+  if self._unknown_field_set is None:  # pylint: disable=protected-access
+    # pylint: disable=protected-access
+    self._unknown_field_set = containers.UnknownFieldSet()
+  return self._unknown_field_set    # pylint: disable=protected-access
+
+
+
+def WhichOneof(self, oneof_name) +
+
+

Returns the name of the currently set field inside a oneof, or None.

+
+ +Expand source code + +
def WhichOneof(self, oneof_name):
+  """Returns the name of the currently set field inside a oneof, or None."""
+  try:
+    field = message_descriptor.oneofs_by_name[oneof_name]
+  except KeyError:
+    raise ValueError(
+        'Protocol message has no oneof "%s" field.' % oneof_name)
+
+  nested_field = self._oneofs.get(field, None)
+  if nested_field is not None and self.HasField(nested_field.name):
+    return nested_field.name
+  else:
+    return None
+
class DebugString -(*args, **kwargs) +(**kwargs)
-

A ProtocolMessage

+

Abstract base class for protocol messages.

+

Protocol message classes are almost always generated by the protocol +compiler. +These generated types subclass Message and implement the methods +shown below.

Ancestors

Class variables

@@ -1910,24 +3045,538 @@ DESCRIPTOR._options = None
+
var MESSAGE_FIELD_NUMBER
+
+
+
+ +

Static methods

+
+
+def FromString(s) +
+
+
+
+ +Expand source code + +
def FromString(s):
+  message = cls()
+  message.MergeFromString(s)
+  return message
+
+
+
+def RegisterExtension(extension_handle) +
+
+
+
+ +Expand source code + +
def RegisterExtension(extension_handle):
+  extension_handle.containing_type = cls.DESCRIPTOR
+  # TODO(amauryfa): Use cls.MESSAGE_FACTORY.pool when available.
+  # pylint: disable=protected-access
+  cls.DESCRIPTOR.file.pool._AddExtensionDescriptor(extension_handle)
+  _AttachFieldHelpers(cls, extension_handle)
+
+

Instance variables

var message
-

Field DebugString.message

+

Getter for message.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
+
+
+

Methods

+
+
+def ByteSize(self) +
+
+
+
+ +Expand source code + +
def ByteSize(self):
+  if not self._cached_byte_size_dirty:
+    return self._cached_byte_size
+
+  size = 0
+  descriptor = self.DESCRIPTOR
+  if descriptor.GetOptions().map_entry:
+    # Fields of map entry should always be serialized.
+    size = descriptor.fields_by_name['key']._sizer(self.key)
+    size += descriptor.fields_by_name['value']._sizer(self.value)
+  else:
+    for field_descriptor, field_value in self.ListFields():
+      size += field_descriptor._sizer(field_value)
+    for tag_bytes, value_bytes in self._unknown_fields:
+      size += len(tag_bytes) + len(value_bytes)
+
+  self._cached_byte_size = size
+  self._cached_byte_size_dirty = False
+  self._listener_for_children.dirty = False
+  return size
+
+
+
+def Clear(self) +
+
+
+
+ +Expand source code + +
def _Clear(self):
+  # Clear fields.
+  self._fields = {}
+  self._unknown_fields = ()
+  # pylint: disable=protected-access
+  if self._unknown_field_set is not None:
+    self._unknown_field_set._clear()
+    self._unknown_field_set = None
+
+  self._oneofs = {}
+  self._Modified()
+
+
+
+def ClearField(self, field_name) +
+
+
+
+ +Expand source code + +
def ClearField(self, field_name):
+  try:
+    field = message_descriptor.fields_by_name[field_name]
+  except KeyError:
+    try:
+      field = message_descriptor.oneofs_by_name[field_name]
+      if field in self._oneofs:
+        field = self._oneofs[field]
+      else:
+        return
+    except KeyError:
+      raise ValueError('Protocol message %s has no "%s" field.' %
+                       (message_descriptor.name, field_name))
+
+  if field in self._fields:
+    # To match the C++ implementation, we need to invalidate iterators
+    # for map fields when ClearField() happens.
+    if hasattr(self._fields[field], 'InvalidateIterators'):
+      self._fields[field].InvalidateIterators()
+
+    # Note:  If the field is a sub-message, its listener will still point
+    #   at us.  That's fine, because the worst than can happen is that it
+    #   will call _Modified() and invalidate our byte size.  Big deal.
+    del self._fields[field]
+
+    if self._oneofs.get(field.containing_oneof, None) is field:
+      del self._oneofs[field.containing_oneof]
+
+  # Always call _Modified() -- even if nothing was changed, this is
+  # a mutating method, and thus calling it should cause the field to become
+  # present in the parent message.
+  self._Modified()
+
+
+
+def DiscardUnknownFields(self) +
+
+
+
+ +Expand source code + +
def _DiscardUnknownFields(self):
+  self._unknown_fields = []
+  self._unknown_field_set = None      # pylint: disable=protected-access
+  for field, value in self.ListFields():
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if _IsMapField(field):
+        if _IsMessageMapField(field):
+          for key in value:
+            value[key].DiscardUnknownFields()
+      elif field.label == _FieldDescriptor.LABEL_REPEATED:
+        for sub_message in value:
+          sub_message.DiscardUnknownFields()
+      else:
+        value.DiscardUnknownFields()
+
+
+
+def FindInitializationErrors(self) +
+
+

Finds required fields which are not initialized.

+

Returns

+

A list of strings. +Each string is a path to an uninitialized field from +the top-level message, e.g. "foo.bar[5].baz".

+
+ +Expand source code + +
def FindInitializationErrors(self):
+  """Finds required fields which are not initialized.
+
+  Returns:
+    A list of strings.  Each string is a path to an uninitialized field from
+    the top-level message, e.g. "foo.bar[5].baz".
+  """
+
+  errors = []  # simplify things
+
+  for field in required_fields:
+    if not self.HasField(field.name):
+      errors.append(field.name)
+
+  for field, value in self.ListFields():
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if field.is_extension:
+        name = '(%s)' % field.full_name
+      else:
+        name = field.name
+
+      if _IsMapField(field):
+        if _IsMessageMapField(field):
+          for key in value:
+            element = value[key]
+            prefix = '%s[%s].' % (name, key)
+            sub_errors = element.FindInitializationErrors()
+            errors += [prefix + error for error in sub_errors]
+        else:
+          # ScalarMaps can't have any initialization errors.
+          pass
+      elif field.label == _FieldDescriptor.LABEL_REPEATED:
+        for i in range(len(value)):
+          element = value[i]
+          prefix = '%s[%d].' % (name, i)
+          sub_errors = element.FindInitializationErrors()
+          errors += [prefix + error for error in sub_errors]
+      else:
+        prefix = name + '.'
+        sub_errors = value.FindInitializationErrors()
+        errors += [prefix + error for error in sub_errors]
+
+  return errors
+
+
+
+def HasField(self, field_name) +
+
+
+
+ +Expand source code + +
def HasField(self, field_name):
+  try:
+    field = hassable_fields[field_name]
+  except KeyError:
+    raise ValueError(error_msg % (message_descriptor.full_name, field_name))
+
+  if isinstance(field, descriptor_mod.OneofDescriptor):
+    try:
+      return HasField(self, self._oneofs[field].name)
+    except KeyError:
+      return False
+  else:
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      value = self._fields.get(field)
+      return value is not None and value._is_present_in_parent
+    else:
+      return field in self._fields
+
+
+
+def IsInitialized(self, errors=None) +
+
+

Checks if all required fields of a message are set.

+

Args

+
+
errors
+
A list which, if provided, will be populated with the field +paths of all missing required fields.
+
+

Returns

+

True iff the specified message has all required fields set.

+
+ +Expand source code + +
def IsInitialized(self, errors=None):
+  """Checks if all required fields of a message are set.
+
+  Args:
+    errors:  A list which, if provided, will be populated with the field
+             paths of all missing required fields.
+
+  Returns:
+    True iff the specified message has all required fields set.
+  """
+
+  # Performance is critical so we avoid HasField() and ListFields().
+
+  for field in required_fields:
+    if (field not in self._fields or
+        (field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE and
+         not self._fields[field]._is_present_in_parent)):
+      if errors is not None:
+        errors.extend(self.FindInitializationErrors())
+      return False
+
+  for field, value in list(self._fields.items()):  # dict can change size!
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if field.label == _FieldDescriptor.LABEL_REPEATED:
+        if (field.message_type.has_options and
+            field.message_type.GetOptions().map_entry):
+          continue
+        for element in value:
+          if not element.IsInitialized():
+            if errors is not None:
+              errors.extend(self.FindInitializationErrors())
+            return False
+      elif value._is_present_in_parent and not value.IsInitialized():
+        if errors is not None:
+          errors.extend(self.FindInitializationErrors())
+        return False
+
+  return True
+
+
+
+def ListFields(self) +
+
+
+
+ +Expand source code + +
def ListFields(self):
+  all_fields = [item for item in self._fields.items() if _IsPresent(item)]
+  all_fields.sort(key = lambda item: item[0].number)
+  return all_fields
+
+
+
+def MergeFrom(self, msg) +
+
+
+
+ +Expand source code + +
def MergeFrom(self, msg):
+  if not isinstance(msg, cls):
+    raise TypeError(
+        'Parameter to MergeFrom() must be instance of same class: '
+        'expected %s got %s.' % (cls.__name__, msg.__class__.__name__))
+
+  assert msg is not self
+  self._Modified()
+
+  fields = self._fields
+
+  for field, value in msg._fields.items():
+    if field.label == LABEL_REPEATED:
+      field_value = fields.get(field)
+      if field_value is None:
+        # Construct a new object to represent this field.
+        field_value = field._default_constructor(self)
+        fields[field] = field_value
+      field_value.MergeFrom(value)
+    elif field.cpp_type == CPPTYPE_MESSAGE:
+      if value._is_present_in_parent:
+        field_value = fields.get(field)
+        if field_value is None:
+          # Construct a new object to represent this field.
+          field_value = field._default_constructor(self)
+          fields[field] = field_value
+        field_value.MergeFrom(value)
+    else:
+      self._fields[field] = value
+      if field.containing_oneof:
+        self._UpdateOneofState(field)
+
+  if msg._unknown_fields:
+    if not self._unknown_fields:
+      self._unknown_fields = []
+    self._unknown_fields.extend(msg._unknown_fields)
+    # pylint: disable=protected-access
+    if self._unknown_field_set is None:
+      self._unknown_field_set = containers.UnknownFieldSet()
+    self._unknown_field_set._extend(msg._unknown_field_set)
+
+
+
+def MergeFromString(self, serialized) +
+
+
+
+ +Expand source code + +
def MergeFromString(self, serialized):
+  if isinstance(serialized, memoryview) and six.PY2:
+    raise TypeError(
+        'memoryview not supported in Python 2 with the pure Python proto '
+        'implementation: this is to maintain compatibility with the C++ '
+        'implementation')
+
+  serialized = memoryview(serialized)
+  length = len(serialized)
+  try:
+    if self._InternalParse(serialized, 0, length) != length:
+      # The only reason _InternalParse would return early is if it
+      # encountered an end-group tag.
+      raise message_mod.DecodeError('Unexpected end-group tag.')
+  except (IndexError, TypeError):
+    # Now ord(buf[p:p+1]) == ord('') gets TypeError.
+    raise message_mod.DecodeError('Truncated message.')
+  except struct.error as e:
+    raise message_mod.DecodeError(e)
+  return length   # Return this for legacy reasons.
+
+
+
+def SerializePartialToString(self, **kwargs) +
+
+
+
+ +Expand source code + +
def SerializePartialToString(self, **kwargs):
+  out = BytesIO()
+  self._InternalSerialize(out.write, **kwargs)
+  return out.getvalue()
+
+
+
+def SerializeToString(self, **kwargs) +
+
+
+
+ +Expand source code + +
def SerializeToString(self, **kwargs):
+  # Check if the message has all of its required fields set.
+  if not self.IsInitialized():
+    raise message_mod.EncodeError(
+        'Message %s is missing required fields: %s' % (
+        self.DESCRIPTOR.full_name, ','.join(self.FindInitializationErrors())))
+  return self.SerializePartialToString(**kwargs)
+
+
+
+def SetInParent(self) +
+
+

Sets the _cached_byte_size_dirty bit to true, +and propagates this to our listener iff this was a state change.

+
+ +Expand source code + +
def Modified(self):
+  """Sets the _cached_byte_size_dirty bit to true,
+  and propagates this to our listener iff this was a state change.
+  """
+
+  # Note:  Some callers check _cached_byte_size_dirty before calling
+  #   _Modified() as an extra optimization.  So, if this method is ever
+  #   changed such that it does stuff even when _cached_byte_size_dirty is
+  #   already true, the callers need to be updated.
+  if not self._cached_byte_size_dirty:
+    self._cached_byte_size_dirty = True
+    self._listener_for_children.dirty = True
+    self._is_present_in_parent = True
+    self._listener.Modified()
+
+
+
+def UnknownFields(self) +
+
+
+
+ +Expand source code + +
def _UnknownFields(self):
+  if self._unknown_field_set is None:  # pylint: disable=protected-access
+    # pylint: disable=protected-access
+    self._unknown_field_set = containers.UnknownFieldSet()
+  return self._unknown_field_set    # pylint: disable=protected-access
+
+
+
+def WhichOneof(self, oneof_name) +
+
+

Returns the name of the currently set field inside a oneof, or None.

+
+ +Expand source code + +
def WhichOneof(self, oneof_name):
+  """Returns the name of the currently set field inside a oneof, or None."""
+  try:
+    field = message_descriptor.oneofs_by_name[oneof_name]
+  except KeyError:
+    raise ValueError(
+        'Protocol message has no oneof "%s" field.' % oneof_name)
+
+  nested_field = self._oneofs.get(field, None)
+  if nested_field is not None and self.HasField(nested_field.name):
+    return nested_field.name
+  else:
+    return None
+
class DeviceState -(*args, **kwargs) +(**kwargs)
-

A ProtocolMessage

+

Abstract base class for protocol messages.

+

Protocol message classes are almost always generated by the protocol +compiler. +These generated types subclass Message and implement the methods +shown below.

Ancestors

Class variables

@@ -1936,110 +3585,1443 @@ DESCRIPTOR._options = None
+
var DID_GPS_RESET_FIELD_NUMBER
+
+
+
+
var MY_NODE_FIELD_NUMBER
+
+
+
+
var NODE_DB_FIELD_NUMBER
+
+
+
+
var NO_SAVE_FIELD_NUMBER
+
+
+
+
var OWNER_FIELD_NUMBER
+
+
+
+
var RADIO_FIELD_NUMBER
+
+
+
+
var RECEIVE_QUEUE_FIELD_NUMBER
+
+
+
+
var RX_TEXT_MESSAGE_FIELD_NUMBER
+
+
+
+
var VERSION_FIELD_NUMBER
+
+
+
+ +

Static methods

+
+
+def FromString(s) +
+
+
+
+ +Expand source code + +
def FromString(s):
+  message = cls()
+  message.MergeFromString(s)
+  return message
+
+
+
+def RegisterExtension(extension_handle) +
+
+
+
+ +Expand source code + +
def RegisterExtension(extension_handle):
+  extension_handle.containing_type = cls.DESCRIPTOR
+  # TODO(amauryfa): Use cls.MESSAGE_FACTORY.pool when available.
+  # pylint: disable=protected-access
+  cls.DESCRIPTOR.file.pool._AddExtensionDescriptor(extension_handle)
+  _AttachFieldHelpers(cls, extension_handle)
+
+

Instance variables

var did_gps_reset
-

Field DeviceState.did_gps_reset

+

Getter for did_gps_reset.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var my_node
-

Field DeviceState.my_node

+

Getter for my_node.

+
+ +Expand source code + +
def getter(self):
+  field_value = self._fields.get(field)
+  if field_value is None:
+    # Construct a new object to represent this field.
+    field_value = field._default_constructor(self)
+
+    # Atomically check if another thread has preempted us and, if not, swap
+    # in the new object we just created.  If someone has preempted us, we
+    # take that object and discard ours.
+    # WARNING:  We are relying on setdefault() being atomic.  This is true
+    #   in CPython but we haven't investigated others.  This warning appears
+    #   in several other locations in this file.
+    field_value = self._fields.setdefault(field, field_value)
+  return field_value
+
var no_save
-

Field DeviceState.no_save

+

Getter for no_save.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var node_db
-

Field DeviceState.node_db

+

Getter for node_db.

+
+ +Expand source code + +
def getter(self):
+  field_value = self._fields.get(field)
+  if field_value is None:
+    # Construct a new object to represent this field.
+    field_value = field._default_constructor(self)
+
+    # Atomically check if another thread has preempted us and, if not, swap
+    # in the new object we just created.  If someone has preempted us, we
+    # take that object and discard ours.
+    # WARNING:  We are relying on setdefault() being atomic.  This is true
+    #   in CPython but we haven't investigated others.  This warning appears
+    #   in several other locations in this file.
+    field_value = self._fields.setdefault(field, field_value)
+  return field_value
+
var owner
-

Field DeviceState.owner

+

Getter for owner.

+
+ +Expand source code + +
def getter(self):
+  field_value = self._fields.get(field)
+  if field_value is None:
+    # Construct a new object to represent this field.
+    field_value = field._default_constructor(self)
+
+    # Atomically check if another thread has preempted us and, if not, swap
+    # in the new object we just created.  If someone has preempted us, we
+    # take that object and discard ours.
+    # WARNING:  We are relying on setdefault() being atomic.  This is true
+    #   in CPython but we haven't investigated others.  This warning appears
+    #   in several other locations in this file.
+    field_value = self._fields.setdefault(field, field_value)
+  return field_value
+
var radio
-

Field DeviceState.radio

+

Getter for radio.

+
+ +Expand source code + +
def getter(self):
+  field_value = self._fields.get(field)
+  if field_value is None:
+    # Construct a new object to represent this field.
+    field_value = field._default_constructor(self)
+
+    # Atomically check if another thread has preempted us and, if not, swap
+    # in the new object we just created.  If someone has preempted us, we
+    # take that object and discard ours.
+    # WARNING:  We are relying on setdefault() being atomic.  This is true
+    #   in CPython but we haven't investigated others.  This warning appears
+    #   in several other locations in this file.
+    field_value = self._fields.setdefault(field, field_value)
+  return field_value
+
var receive_queue
-

Field DeviceState.receive_queue

+

Getter for receive_queue.

+
+ +Expand source code + +
def getter(self):
+  field_value = self._fields.get(field)
+  if field_value is None:
+    # Construct a new object to represent this field.
+    field_value = field._default_constructor(self)
+
+    # Atomically check if another thread has preempted us and, if not, swap
+    # in the new object we just created.  If someone has preempted us, we
+    # take that object and discard ours.
+    # WARNING:  We are relying on setdefault() being atomic.  This is true
+    #   in CPython but we haven't investigated others.  This warning appears
+    #   in several other locations in this file.
+    field_value = self._fields.setdefault(field, field_value)
+  return field_value
+
var rx_text_message
-

Field DeviceState.rx_text_message

+

Getter for rx_text_message.

+
+ +Expand source code + +
def getter(self):
+  field_value = self._fields.get(field)
+  if field_value is None:
+    # Construct a new object to represent this field.
+    field_value = field._default_constructor(self)
+
+    # Atomically check if another thread has preempted us and, if not, swap
+    # in the new object we just created.  If someone has preempted us, we
+    # take that object and discard ours.
+    # WARNING:  We are relying on setdefault() being atomic.  This is true
+    #   in CPython but we haven't investigated others.  This warning appears
+    #   in several other locations in this file.
+    field_value = self._fields.setdefault(field, field_value)
+  return field_value
+
var version
-

Field DeviceState.version

+

Getter for version.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
+
+
+

Methods

+
+
+def ByteSize(self) +
+
+
+
+ +Expand source code + +
def ByteSize(self):
+  if not self._cached_byte_size_dirty:
+    return self._cached_byte_size
+
+  size = 0
+  descriptor = self.DESCRIPTOR
+  if descriptor.GetOptions().map_entry:
+    # Fields of map entry should always be serialized.
+    size = descriptor.fields_by_name['key']._sizer(self.key)
+    size += descriptor.fields_by_name['value']._sizer(self.value)
+  else:
+    for field_descriptor, field_value in self.ListFields():
+      size += field_descriptor._sizer(field_value)
+    for tag_bytes, value_bytes in self._unknown_fields:
+      size += len(tag_bytes) + len(value_bytes)
+
+  self._cached_byte_size = size
+  self._cached_byte_size_dirty = False
+  self._listener_for_children.dirty = False
+  return size
+
+
+
+def Clear(self) +
+
+
+
+ +Expand source code + +
def _Clear(self):
+  # Clear fields.
+  self._fields = {}
+  self._unknown_fields = ()
+  # pylint: disable=protected-access
+  if self._unknown_field_set is not None:
+    self._unknown_field_set._clear()
+    self._unknown_field_set = None
+
+  self._oneofs = {}
+  self._Modified()
+
+
+
+def ClearField(self, field_name) +
+
+
+
+ +Expand source code + +
def ClearField(self, field_name):
+  try:
+    field = message_descriptor.fields_by_name[field_name]
+  except KeyError:
+    try:
+      field = message_descriptor.oneofs_by_name[field_name]
+      if field in self._oneofs:
+        field = self._oneofs[field]
+      else:
+        return
+    except KeyError:
+      raise ValueError('Protocol message %s has no "%s" field.' %
+                       (message_descriptor.name, field_name))
+
+  if field in self._fields:
+    # To match the C++ implementation, we need to invalidate iterators
+    # for map fields when ClearField() happens.
+    if hasattr(self._fields[field], 'InvalidateIterators'):
+      self._fields[field].InvalidateIterators()
+
+    # Note:  If the field is a sub-message, its listener will still point
+    #   at us.  That's fine, because the worst than can happen is that it
+    #   will call _Modified() and invalidate our byte size.  Big deal.
+    del self._fields[field]
+
+    if self._oneofs.get(field.containing_oneof, None) is field:
+      del self._oneofs[field.containing_oneof]
+
+  # Always call _Modified() -- even if nothing was changed, this is
+  # a mutating method, and thus calling it should cause the field to become
+  # present in the parent message.
+  self._Modified()
+
+
+
+def DiscardUnknownFields(self) +
+
+
+
+ +Expand source code + +
def _DiscardUnknownFields(self):
+  self._unknown_fields = []
+  self._unknown_field_set = None      # pylint: disable=protected-access
+  for field, value in self.ListFields():
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if _IsMapField(field):
+        if _IsMessageMapField(field):
+          for key in value:
+            value[key].DiscardUnknownFields()
+      elif field.label == _FieldDescriptor.LABEL_REPEATED:
+        for sub_message in value:
+          sub_message.DiscardUnknownFields()
+      else:
+        value.DiscardUnknownFields()
+
+
+
+def FindInitializationErrors(self) +
+
+

Finds required fields which are not initialized.

+

Returns

+

A list of strings. +Each string is a path to an uninitialized field from +the top-level message, e.g. "foo.bar[5].baz".

+
+ +Expand source code + +
def FindInitializationErrors(self):
+  """Finds required fields which are not initialized.
+
+  Returns:
+    A list of strings.  Each string is a path to an uninitialized field from
+    the top-level message, e.g. "foo.bar[5].baz".
+  """
+
+  errors = []  # simplify things
+
+  for field in required_fields:
+    if not self.HasField(field.name):
+      errors.append(field.name)
+
+  for field, value in self.ListFields():
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if field.is_extension:
+        name = '(%s)' % field.full_name
+      else:
+        name = field.name
+
+      if _IsMapField(field):
+        if _IsMessageMapField(field):
+          for key in value:
+            element = value[key]
+            prefix = '%s[%s].' % (name, key)
+            sub_errors = element.FindInitializationErrors()
+            errors += [prefix + error for error in sub_errors]
+        else:
+          # ScalarMaps can't have any initialization errors.
+          pass
+      elif field.label == _FieldDescriptor.LABEL_REPEATED:
+        for i in range(len(value)):
+          element = value[i]
+          prefix = '%s[%d].' % (name, i)
+          sub_errors = element.FindInitializationErrors()
+          errors += [prefix + error for error in sub_errors]
+      else:
+        prefix = name + '.'
+        sub_errors = value.FindInitializationErrors()
+        errors += [prefix + error for error in sub_errors]
+
+  return errors
+
+
+
+def HasField(self, field_name) +
+
+
+
+ +Expand source code + +
def HasField(self, field_name):
+  try:
+    field = hassable_fields[field_name]
+  except KeyError:
+    raise ValueError(error_msg % (message_descriptor.full_name, field_name))
+
+  if isinstance(field, descriptor_mod.OneofDescriptor):
+    try:
+      return HasField(self, self._oneofs[field].name)
+    except KeyError:
+      return False
+  else:
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      value = self._fields.get(field)
+      return value is not None and value._is_present_in_parent
+    else:
+      return field in self._fields
+
+
+
+def IsInitialized(self, errors=None) +
+
+

Checks if all required fields of a message are set.

+

Args

+
+
errors
+
A list which, if provided, will be populated with the field +paths of all missing required fields.
+
+

Returns

+

True iff the specified message has all required fields set.

+
+ +Expand source code + +
def IsInitialized(self, errors=None):
+  """Checks if all required fields of a message are set.
+
+  Args:
+    errors:  A list which, if provided, will be populated with the field
+             paths of all missing required fields.
+
+  Returns:
+    True iff the specified message has all required fields set.
+  """
+
+  # Performance is critical so we avoid HasField() and ListFields().
+
+  for field in required_fields:
+    if (field not in self._fields or
+        (field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE and
+         not self._fields[field]._is_present_in_parent)):
+      if errors is not None:
+        errors.extend(self.FindInitializationErrors())
+      return False
+
+  for field, value in list(self._fields.items()):  # dict can change size!
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if field.label == _FieldDescriptor.LABEL_REPEATED:
+        if (field.message_type.has_options and
+            field.message_type.GetOptions().map_entry):
+          continue
+        for element in value:
+          if not element.IsInitialized():
+            if errors is not None:
+              errors.extend(self.FindInitializationErrors())
+            return False
+      elif value._is_present_in_parent and not value.IsInitialized():
+        if errors is not None:
+          errors.extend(self.FindInitializationErrors())
+        return False
+
+  return True
+
+
+
+def ListFields(self) +
+
+
+
+ +Expand source code + +
def ListFields(self):
+  all_fields = [item for item in self._fields.items() if _IsPresent(item)]
+  all_fields.sort(key = lambda item: item[0].number)
+  return all_fields
+
+
+
+def MergeFrom(self, msg) +
+
+
+
+ +Expand source code + +
def MergeFrom(self, msg):
+  if not isinstance(msg, cls):
+    raise TypeError(
+        'Parameter to MergeFrom() must be instance of same class: '
+        'expected %s got %s.' % (cls.__name__, msg.__class__.__name__))
+
+  assert msg is not self
+  self._Modified()
+
+  fields = self._fields
+
+  for field, value in msg._fields.items():
+    if field.label == LABEL_REPEATED:
+      field_value = fields.get(field)
+      if field_value is None:
+        # Construct a new object to represent this field.
+        field_value = field._default_constructor(self)
+        fields[field] = field_value
+      field_value.MergeFrom(value)
+    elif field.cpp_type == CPPTYPE_MESSAGE:
+      if value._is_present_in_parent:
+        field_value = fields.get(field)
+        if field_value is None:
+          # Construct a new object to represent this field.
+          field_value = field._default_constructor(self)
+          fields[field] = field_value
+        field_value.MergeFrom(value)
+    else:
+      self._fields[field] = value
+      if field.containing_oneof:
+        self._UpdateOneofState(field)
+
+  if msg._unknown_fields:
+    if not self._unknown_fields:
+      self._unknown_fields = []
+    self._unknown_fields.extend(msg._unknown_fields)
+    # pylint: disable=protected-access
+    if self._unknown_field_set is None:
+      self._unknown_field_set = containers.UnknownFieldSet()
+    self._unknown_field_set._extend(msg._unknown_field_set)
+
+
+
+def MergeFromString(self, serialized) +
+
+
+
+ +Expand source code + +
def MergeFromString(self, serialized):
+  if isinstance(serialized, memoryview) and six.PY2:
+    raise TypeError(
+        'memoryview not supported in Python 2 with the pure Python proto '
+        'implementation: this is to maintain compatibility with the C++ '
+        'implementation')
+
+  serialized = memoryview(serialized)
+  length = len(serialized)
+  try:
+    if self._InternalParse(serialized, 0, length) != length:
+      # The only reason _InternalParse would return early is if it
+      # encountered an end-group tag.
+      raise message_mod.DecodeError('Unexpected end-group tag.')
+  except (IndexError, TypeError):
+    # Now ord(buf[p:p+1]) == ord('') gets TypeError.
+    raise message_mod.DecodeError('Truncated message.')
+  except struct.error as e:
+    raise message_mod.DecodeError(e)
+  return length   # Return this for legacy reasons.
+
+
+
+def SerializePartialToString(self, **kwargs) +
+
+
+
+ +Expand source code + +
def SerializePartialToString(self, **kwargs):
+  out = BytesIO()
+  self._InternalSerialize(out.write, **kwargs)
+  return out.getvalue()
+
+
+
+def SerializeToString(self, **kwargs) +
+
+
+
+ +Expand source code + +
def SerializeToString(self, **kwargs):
+  # Check if the message has all of its required fields set.
+  if not self.IsInitialized():
+    raise message_mod.EncodeError(
+        'Message %s is missing required fields: %s' % (
+        self.DESCRIPTOR.full_name, ','.join(self.FindInitializationErrors())))
+  return self.SerializePartialToString(**kwargs)
+
+
+
+def SetInParent(self) +
+
+

Sets the _cached_byte_size_dirty bit to true, +and propagates this to our listener iff this was a state change.

+
+ +Expand source code + +
def Modified(self):
+  """Sets the _cached_byte_size_dirty bit to true,
+  and propagates this to our listener iff this was a state change.
+  """
+
+  # Note:  Some callers check _cached_byte_size_dirty before calling
+  #   _Modified() as an extra optimization.  So, if this method is ever
+  #   changed such that it does stuff even when _cached_byte_size_dirty is
+  #   already true, the callers need to be updated.
+  if not self._cached_byte_size_dirty:
+    self._cached_byte_size_dirty = True
+    self._listener_for_children.dirty = True
+    self._is_present_in_parent = True
+    self._listener.Modified()
+
+
+
+def UnknownFields(self) +
+
+
+
+ +Expand source code + +
def _UnknownFields(self):
+  if self._unknown_field_set is None:  # pylint: disable=protected-access
+    # pylint: disable=protected-access
+    self._unknown_field_set = containers.UnknownFieldSet()
+  return self._unknown_field_set    # pylint: disable=protected-access
+
+
+
+def WhichOneof(self, oneof_name) +
+
+

Returns the name of the currently set field inside a oneof, or None.

+
+ +Expand source code + +
def WhichOneof(self, oneof_name):
+  """Returns the name of the currently set field inside a oneof, or None."""
+  try:
+    field = message_descriptor.oneofs_by_name[oneof_name]
+  except KeyError:
+    raise ValueError(
+        'Protocol message has no oneof "%s" field.' % oneof_name)
+
+  nested_field = self._oneofs.get(field, None)
+  if nested_field is not None and self.HasField(nested_field.name):
+    return nested_field.name
+  else:
+    return None
+
class FromRadio -(*args, **kwargs) +(**kwargs)
-

A ProtocolMessage

+

Abstract base class for protocol messages.

+

Protocol message classes are almost always generated by the protocol +compiler. +These generated types subclass Message and implement the methods +shown below.

Ancestors

Class variables

+
var CONFIG_COMPLETE_ID_FIELD_NUMBER
+
+
+
+
var DEBUG_STRING_FIELD_NUMBER
+
+
+
var DESCRIPTOR
+
var MY_INFO_FIELD_NUMBER
+
+
+
+
var NODE_INFO_FIELD_NUMBER
+
+
+
+
var NUM_FIELD_NUMBER
+
+
+
+
var PACKET_FIELD_NUMBER
+
+
+
+
var RADIO_FIELD_NUMBER
+
+
+
+
var REBOOTED_FIELD_NUMBER
+
+
+
+
+

Static methods

+
+
+def FromString(s) +
+
+
+
+ +Expand source code + +
def FromString(s):
+  message = cls()
+  message.MergeFromString(s)
+  return message
+
+
+
+def RegisterExtension(extension_handle) +
+
+
+
+ +Expand source code + +
def RegisterExtension(extension_handle):
+  extension_handle.containing_type = cls.DESCRIPTOR
+  # TODO(amauryfa): Use cls.MESSAGE_FACTORY.pool when available.
+  # pylint: disable=protected-access
+  cls.DESCRIPTOR.file.pool._AddExtensionDescriptor(extension_handle)
+  _AttachFieldHelpers(cls, extension_handle)
+
+

Instance variables

var config_complete_id
-

Field FromRadio.config_complete_id

+

Getter for config_complete_id.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var debug_string
-

Field FromRadio.debug_string

+

Getter for debug_string.

+
+ +Expand source code + +
def getter(self):
+  field_value = self._fields.get(field)
+  if field_value is None:
+    # Construct a new object to represent this field.
+    field_value = field._default_constructor(self)
+
+    # Atomically check if another thread has preempted us and, if not, swap
+    # in the new object we just created.  If someone has preempted us, we
+    # take that object and discard ours.
+    # WARNING:  We are relying on setdefault() being atomic.  This is true
+    #   in CPython but we haven't investigated others.  This warning appears
+    #   in several other locations in this file.
+    field_value = self._fields.setdefault(field, field_value)
+  return field_value
+
var my_info
-

Field FromRadio.my_info

+

Getter for my_info.

+
+ +Expand source code + +
def getter(self):
+  field_value = self._fields.get(field)
+  if field_value is None:
+    # Construct a new object to represent this field.
+    field_value = field._default_constructor(self)
+
+    # Atomically check if another thread has preempted us and, if not, swap
+    # in the new object we just created.  If someone has preempted us, we
+    # take that object and discard ours.
+    # WARNING:  We are relying on setdefault() being atomic.  This is true
+    #   in CPython but we haven't investigated others.  This warning appears
+    #   in several other locations in this file.
+    field_value = self._fields.setdefault(field, field_value)
+  return field_value
+
var node_info
-

Field FromRadio.node_info

+

Getter for node_info.

+
+ +Expand source code + +
def getter(self):
+  field_value = self._fields.get(field)
+  if field_value is None:
+    # Construct a new object to represent this field.
+    field_value = field._default_constructor(self)
+
+    # Atomically check if another thread has preempted us and, if not, swap
+    # in the new object we just created.  If someone has preempted us, we
+    # take that object and discard ours.
+    # WARNING:  We are relying on setdefault() being atomic.  This is true
+    #   in CPython but we haven't investigated others.  This warning appears
+    #   in several other locations in this file.
+    field_value = self._fields.setdefault(field, field_value)
+  return field_value
+
var num
-

Field FromRadio.num

+

Getter for num.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var packet
-

Field FromRadio.packet

+

Getter for packet.

+
+ +Expand source code + +
def getter(self):
+  field_value = self._fields.get(field)
+  if field_value is None:
+    # Construct a new object to represent this field.
+    field_value = field._default_constructor(self)
+
+    # Atomically check if another thread has preempted us and, if not, swap
+    # in the new object we just created.  If someone has preempted us, we
+    # take that object and discard ours.
+    # WARNING:  We are relying on setdefault() being atomic.  This is true
+    #   in CPython but we haven't investigated others.  This warning appears
+    #   in several other locations in this file.
+    field_value = self._fields.setdefault(field, field_value)
+  return field_value
+
var radio
-

Field FromRadio.radio

+

Getter for radio.

+
+ +Expand source code + +
def getter(self):
+  field_value = self._fields.get(field)
+  if field_value is None:
+    # Construct a new object to represent this field.
+    field_value = field._default_constructor(self)
+
+    # Atomically check if another thread has preempted us and, if not, swap
+    # in the new object we just created.  If someone has preempted us, we
+    # take that object and discard ours.
+    # WARNING:  We are relying on setdefault() being atomic.  This is true
+    #   in CPython but we haven't investigated others.  This warning appears
+    #   in several other locations in this file.
+    field_value = self._fields.setdefault(field, field_value)
+  return field_value
+
var rebooted
-

Field FromRadio.rebooted

+

Getter for rebooted.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
+
+
+

Methods

+
+
+def ByteSize(self) +
+
+
+
+ +Expand source code + +
def ByteSize(self):
+  if not self._cached_byte_size_dirty:
+    return self._cached_byte_size
+
+  size = 0
+  descriptor = self.DESCRIPTOR
+  if descriptor.GetOptions().map_entry:
+    # Fields of map entry should always be serialized.
+    size = descriptor.fields_by_name['key']._sizer(self.key)
+    size += descriptor.fields_by_name['value']._sizer(self.value)
+  else:
+    for field_descriptor, field_value in self.ListFields():
+      size += field_descriptor._sizer(field_value)
+    for tag_bytes, value_bytes in self._unknown_fields:
+      size += len(tag_bytes) + len(value_bytes)
+
+  self._cached_byte_size = size
+  self._cached_byte_size_dirty = False
+  self._listener_for_children.dirty = False
+  return size
+
+
+
+def Clear(self) +
+
+
+
+ +Expand source code + +
def _Clear(self):
+  # Clear fields.
+  self._fields = {}
+  self._unknown_fields = ()
+  # pylint: disable=protected-access
+  if self._unknown_field_set is not None:
+    self._unknown_field_set._clear()
+    self._unknown_field_set = None
+
+  self._oneofs = {}
+  self._Modified()
+
+
+
+def ClearField(self, field_name) +
+
+
+
+ +Expand source code + +
def ClearField(self, field_name):
+  try:
+    field = message_descriptor.fields_by_name[field_name]
+  except KeyError:
+    try:
+      field = message_descriptor.oneofs_by_name[field_name]
+      if field in self._oneofs:
+        field = self._oneofs[field]
+      else:
+        return
+    except KeyError:
+      raise ValueError('Protocol message %s has no "%s" field.' %
+                       (message_descriptor.name, field_name))
+
+  if field in self._fields:
+    # To match the C++ implementation, we need to invalidate iterators
+    # for map fields when ClearField() happens.
+    if hasattr(self._fields[field], 'InvalidateIterators'):
+      self._fields[field].InvalidateIterators()
+
+    # Note:  If the field is a sub-message, its listener will still point
+    #   at us.  That's fine, because the worst than can happen is that it
+    #   will call _Modified() and invalidate our byte size.  Big deal.
+    del self._fields[field]
+
+    if self._oneofs.get(field.containing_oneof, None) is field:
+      del self._oneofs[field.containing_oneof]
+
+  # Always call _Modified() -- even if nothing was changed, this is
+  # a mutating method, and thus calling it should cause the field to become
+  # present in the parent message.
+  self._Modified()
+
+
+
+def DiscardUnknownFields(self) +
+
+
+
+ +Expand source code + +
def _DiscardUnknownFields(self):
+  self._unknown_fields = []
+  self._unknown_field_set = None      # pylint: disable=protected-access
+  for field, value in self.ListFields():
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if _IsMapField(field):
+        if _IsMessageMapField(field):
+          for key in value:
+            value[key].DiscardUnknownFields()
+      elif field.label == _FieldDescriptor.LABEL_REPEATED:
+        for sub_message in value:
+          sub_message.DiscardUnknownFields()
+      else:
+        value.DiscardUnknownFields()
+
+
+
+def FindInitializationErrors(self) +
+
+

Finds required fields which are not initialized.

+

Returns

+

A list of strings. +Each string is a path to an uninitialized field from +the top-level message, e.g. "foo.bar[5].baz".

+
+ +Expand source code + +
def FindInitializationErrors(self):
+  """Finds required fields which are not initialized.
+
+  Returns:
+    A list of strings.  Each string is a path to an uninitialized field from
+    the top-level message, e.g. "foo.bar[5].baz".
+  """
+
+  errors = []  # simplify things
+
+  for field in required_fields:
+    if not self.HasField(field.name):
+      errors.append(field.name)
+
+  for field, value in self.ListFields():
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if field.is_extension:
+        name = '(%s)' % field.full_name
+      else:
+        name = field.name
+
+      if _IsMapField(field):
+        if _IsMessageMapField(field):
+          for key in value:
+            element = value[key]
+            prefix = '%s[%s].' % (name, key)
+            sub_errors = element.FindInitializationErrors()
+            errors += [prefix + error for error in sub_errors]
+        else:
+          # ScalarMaps can't have any initialization errors.
+          pass
+      elif field.label == _FieldDescriptor.LABEL_REPEATED:
+        for i in range(len(value)):
+          element = value[i]
+          prefix = '%s[%d].' % (name, i)
+          sub_errors = element.FindInitializationErrors()
+          errors += [prefix + error for error in sub_errors]
+      else:
+        prefix = name + '.'
+        sub_errors = value.FindInitializationErrors()
+        errors += [prefix + error for error in sub_errors]
+
+  return errors
+
+
+
+def HasField(self, field_name) +
+
+
+
+ +Expand source code + +
def HasField(self, field_name):
+  try:
+    field = hassable_fields[field_name]
+  except KeyError:
+    raise ValueError(error_msg % (message_descriptor.full_name, field_name))
+
+  if isinstance(field, descriptor_mod.OneofDescriptor):
+    try:
+      return HasField(self, self._oneofs[field].name)
+    except KeyError:
+      return False
+  else:
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      value = self._fields.get(field)
+      return value is not None and value._is_present_in_parent
+    else:
+      return field in self._fields
+
+
+
+def IsInitialized(self, errors=None) +
+
+

Checks if all required fields of a message are set.

+

Args

+
+
errors
+
A list which, if provided, will be populated with the field +paths of all missing required fields.
+
+

Returns

+

True iff the specified message has all required fields set.

+
+ +Expand source code + +
def IsInitialized(self, errors=None):
+  """Checks if all required fields of a message are set.
+
+  Args:
+    errors:  A list which, if provided, will be populated with the field
+             paths of all missing required fields.
+
+  Returns:
+    True iff the specified message has all required fields set.
+  """
+
+  # Performance is critical so we avoid HasField() and ListFields().
+
+  for field in required_fields:
+    if (field not in self._fields or
+        (field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE and
+         not self._fields[field]._is_present_in_parent)):
+      if errors is not None:
+        errors.extend(self.FindInitializationErrors())
+      return False
+
+  for field, value in list(self._fields.items()):  # dict can change size!
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if field.label == _FieldDescriptor.LABEL_REPEATED:
+        if (field.message_type.has_options and
+            field.message_type.GetOptions().map_entry):
+          continue
+        for element in value:
+          if not element.IsInitialized():
+            if errors is not None:
+              errors.extend(self.FindInitializationErrors())
+            return False
+      elif value._is_present_in_parent and not value.IsInitialized():
+        if errors is not None:
+          errors.extend(self.FindInitializationErrors())
+        return False
+
+  return True
+
+
+
+def ListFields(self) +
+
+
+
+ +Expand source code + +
def ListFields(self):
+  all_fields = [item for item in self._fields.items() if _IsPresent(item)]
+  all_fields.sort(key = lambda item: item[0].number)
+  return all_fields
+
+
+
+def MergeFrom(self, msg) +
+
+
+
+ +Expand source code + +
def MergeFrom(self, msg):
+  if not isinstance(msg, cls):
+    raise TypeError(
+        'Parameter to MergeFrom() must be instance of same class: '
+        'expected %s got %s.' % (cls.__name__, msg.__class__.__name__))
+
+  assert msg is not self
+  self._Modified()
+
+  fields = self._fields
+
+  for field, value in msg._fields.items():
+    if field.label == LABEL_REPEATED:
+      field_value = fields.get(field)
+      if field_value is None:
+        # Construct a new object to represent this field.
+        field_value = field._default_constructor(self)
+        fields[field] = field_value
+      field_value.MergeFrom(value)
+    elif field.cpp_type == CPPTYPE_MESSAGE:
+      if value._is_present_in_parent:
+        field_value = fields.get(field)
+        if field_value is None:
+          # Construct a new object to represent this field.
+          field_value = field._default_constructor(self)
+          fields[field] = field_value
+        field_value.MergeFrom(value)
+    else:
+      self._fields[field] = value
+      if field.containing_oneof:
+        self._UpdateOneofState(field)
+
+  if msg._unknown_fields:
+    if not self._unknown_fields:
+      self._unknown_fields = []
+    self._unknown_fields.extend(msg._unknown_fields)
+    # pylint: disable=protected-access
+    if self._unknown_field_set is None:
+      self._unknown_field_set = containers.UnknownFieldSet()
+    self._unknown_field_set._extend(msg._unknown_field_set)
+
+
+
+def MergeFromString(self, serialized) +
+
+
+
+ +Expand source code + +
def MergeFromString(self, serialized):
+  if isinstance(serialized, memoryview) and six.PY2:
+    raise TypeError(
+        'memoryview not supported in Python 2 with the pure Python proto '
+        'implementation: this is to maintain compatibility with the C++ '
+        'implementation')
+
+  serialized = memoryview(serialized)
+  length = len(serialized)
+  try:
+    if self._InternalParse(serialized, 0, length) != length:
+      # The only reason _InternalParse would return early is if it
+      # encountered an end-group tag.
+      raise message_mod.DecodeError('Unexpected end-group tag.')
+  except (IndexError, TypeError):
+    # Now ord(buf[p:p+1]) == ord('') gets TypeError.
+    raise message_mod.DecodeError('Truncated message.')
+  except struct.error as e:
+    raise message_mod.DecodeError(e)
+  return length   # Return this for legacy reasons.
+
+
+
+def SerializePartialToString(self, **kwargs) +
+
+
+
+ +Expand source code + +
def SerializePartialToString(self, **kwargs):
+  out = BytesIO()
+  self._InternalSerialize(out.write, **kwargs)
+  return out.getvalue()
+
+
+
+def SerializeToString(self, **kwargs) +
+
+
+
+ +Expand source code + +
def SerializeToString(self, **kwargs):
+  # Check if the message has all of its required fields set.
+  if not self.IsInitialized():
+    raise message_mod.EncodeError(
+        'Message %s is missing required fields: %s' % (
+        self.DESCRIPTOR.full_name, ','.join(self.FindInitializationErrors())))
+  return self.SerializePartialToString(**kwargs)
+
+
+
+def SetInParent(self) +
+
+

Sets the _cached_byte_size_dirty bit to true, +and propagates this to our listener iff this was a state change.

+
+ +Expand source code + +
def Modified(self):
+  """Sets the _cached_byte_size_dirty bit to true,
+  and propagates this to our listener iff this was a state change.
+  """
+
+  # Note:  Some callers check _cached_byte_size_dirty before calling
+  #   _Modified() as an extra optimization.  So, if this method is ever
+  #   changed such that it does stuff even when _cached_byte_size_dirty is
+  #   already true, the callers need to be updated.
+  if not self._cached_byte_size_dirty:
+    self._cached_byte_size_dirty = True
+    self._listener_for_children.dirty = True
+    self._is_present_in_parent = True
+    self._listener.Modified()
+
+
+
+def UnknownFields(self) +
+
+
+
+ +Expand source code + +
def _UnknownFields(self):
+  if self._unknown_field_set is None:  # pylint: disable=protected-access
+    # pylint: disable=protected-access
+    self._unknown_field_set = containers.UnknownFieldSet()
+  return self._unknown_field_set    # pylint: disable=protected-access
+
+
+
+def WhichOneof(self, oneof_name) +
+
+

Returns the name of the currently set field inside a oneof, or None.

+
+ +Expand source code + +
def WhichOneof(self, oneof_name):
+  """Returns the name of the currently set field inside a oneof, or None."""
+  try:
+    field = message_descriptor.oneofs_by_name[oneof_name]
+  except KeyError:
+    raise ValueError(
+        'Protocol message has no oneof "%s" field.' % oneof_name)
+
+  nested_field = self._oneofs.get(field, None)
+  if nested_field is not None and self.HasField(nested_field.name):
+    return nested_field.name
+  else:
+    return None
+
class ManufacturingData -(*args, **kwargs) +(**kwargs)
-

A ProtocolMessage

+

Abstract base class for protocol messages.

+

Protocol message classes are almost always generated by the protocol +compiler. +These generated types subclass Message and implement the methods +shown below.

Ancestors

Class variables

@@ -2048,172 +5030,2036 @@ DESCRIPTOR._options = None
+
var FRADIOFREQ_FIELD_NUMBER
+
+
+
+
var HW_MODEL_FIELD_NUMBER
+
+
+
+
var HW_VERSION_FIELD_NUMBER
+
+
+
+
var SELFTEST_RESULT_FIELD_NUMBER
+
+
+
+ +

Static methods

+
+
+def FromString(s) +
+
+
+
+ +Expand source code + +
def FromString(s):
+  message = cls()
+  message.MergeFromString(s)
+  return message
+
+
+
+def RegisterExtension(extension_handle) +
+
+
+
+ +Expand source code + +
def RegisterExtension(extension_handle):
+  extension_handle.containing_type = cls.DESCRIPTOR
+  # TODO(amauryfa): Use cls.MESSAGE_FACTORY.pool when available.
+  # pylint: disable=protected-access
+  cls.DESCRIPTOR.file.pool._AddExtensionDescriptor(extension_handle)
+  _AttachFieldHelpers(cls, extension_handle)
+
+

Instance variables

var fradioFreq
-

Field ManufacturingData.fradioFreq

+

Getter for fradioFreq.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var hw_model
-

Field ManufacturingData.hw_model

+

Getter for hw_model.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var hw_version
-

Field ManufacturingData.hw_version

+

Getter for hw_version.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var selftest_result
-

Field ManufacturingData.selftest_result

+

Getter for selftest_result.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
+
+
+

Methods

+
+
+def ByteSize(self) +
+
+
+
+ +Expand source code + +
def ByteSize(self):
+  if not self._cached_byte_size_dirty:
+    return self._cached_byte_size
+
+  size = 0
+  descriptor = self.DESCRIPTOR
+  if descriptor.GetOptions().map_entry:
+    # Fields of map entry should always be serialized.
+    size = descriptor.fields_by_name['key']._sizer(self.key)
+    size += descriptor.fields_by_name['value']._sizer(self.value)
+  else:
+    for field_descriptor, field_value in self.ListFields():
+      size += field_descriptor._sizer(field_value)
+    for tag_bytes, value_bytes in self._unknown_fields:
+      size += len(tag_bytes) + len(value_bytes)
+
+  self._cached_byte_size = size
+  self._cached_byte_size_dirty = False
+  self._listener_for_children.dirty = False
+  return size
+
+
+
+def Clear(self) +
+
+
+
+ +Expand source code + +
def _Clear(self):
+  # Clear fields.
+  self._fields = {}
+  self._unknown_fields = ()
+  # pylint: disable=protected-access
+  if self._unknown_field_set is not None:
+    self._unknown_field_set._clear()
+    self._unknown_field_set = None
+
+  self._oneofs = {}
+  self._Modified()
+
+
+
+def ClearField(self, field_name) +
+
+
+
+ +Expand source code + +
def ClearField(self, field_name):
+  try:
+    field = message_descriptor.fields_by_name[field_name]
+  except KeyError:
+    try:
+      field = message_descriptor.oneofs_by_name[field_name]
+      if field in self._oneofs:
+        field = self._oneofs[field]
+      else:
+        return
+    except KeyError:
+      raise ValueError('Protocol message %s has no "%s" field.' %
+                       (message_descriptor.name, field_name))
+
+  if field in self._fields:
+    # To match the C++ implementation, we need to invalidate iterators
+    # for map fields when ClearField() happens.
+    if hasattr(self._fields[field], 'InvalidateIterators'):
+      self._fields[field].InvalidateIterators()
+
+    # Note:  If the field is a sub-message, its listener will still point
+    #   at us.  That's fine, because the worst than can happen is that it
+    #   will call _Modified() and invalidate our byte size.  Big deal.
+    del self._fields[field]
+
+    if self._oneofs.get(field.containing_oneof, None) is field:
+      del self._oneofs[field.containing_oneof]
+
+  # Always call _Modified() -- even if nothing was changed, this is
+  # a mutating method, and thus calling it should cause the field to become
+  # present in the parent message.
+  self._Modified()
+
+
+
+def DiscardUnknownFields(self) +
+
+
+
+ +Expand source code + +
def _DiscardUnknownFields(self):
+  self._unknown_fields = []
+  self._unknown_field_set = None      # pylint: disable=protected-access
+  for field, value in self.ListFields():
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if _IsMapField(field):
+        if _IsMessageMapField(field):
+          for key in value:
+            value[key].DiscardUnknownFields()
+      elif field.label == _FieldDescriptor.LABEL_REPEATED:
+        for sub_message in value:
+          sub_message.DiscardUnknownFields()
+      else:
+        value.DiscardUnknownFields()
+
+
+
+def FindInitializationErrors(self) +
+
+

Finds required fields which are not initialized.

+

Returns

+

A list of strings. +Each string is a path to an uninitialized field from +the top-level message, e.g. "foo.bar[5].baz".

+
+ +Expand source code + +
def FindInitializationErrors(self):
+  """Finds required fields which are not initialized.
+
+  Returns:
+    A list of strings.  Each string is a path to an uninitialized field from
+    the top-level message, e.g. "foo.bar[5].baz".
+  """
+
+  errors = []  # simplify things
+
+  for field in required_fields:
+    if not self.HasField(field.name):
+      errors.append(field.name)
+
+  for field, value in self.ListFields():
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if field.is_extension:
+        name = '(%s)' % field.full_name
+      else:
+        name = field.name
+
+      if _IsMapField(field):
+        if _IsMessageMapField(field):
+          for key in value:
+            element = value[key]
+            prefix = '%s[%s].' % (name, key)
+            sub_errors = element.FindInitializationErrors()
+            errors += [prefix + error for error in sub_errors]
+        else:
+          # ScalarMaps can't have any initialization errors.
+          pass
+      elif field.label == _FieldDescriptor.LABEL_REPEATED:
+        for i in range(len(value)):
+          element = value[i]
+          prefix = '%s[%d].' % (name, i)
+          sub_errors = element.FindInitializationErrors()
+          errors += [prefix + error for error in sub_errors]
+      else:
+        prefix = name + '.'
+        sub_errors = value.FindInitializationErrors()
+        errors += [prefix + error for error in sub_errors]
+
+  return errors
+
+
+
+def HasField(self, field_name) +
+
+
+
+ +Expand source code + +
def HasField(self, field_name):
+  try:
+    field = hassable_fields[field_name]
+  except KeyError:
+    raise ValueError(error_msg % (message_descriptor.full_name, field_name))
+
+  if isinstance(field, descriptor_mod.OneofDescriptor):
+    try:
+      return HasField(self, self._oneofs[field].name)
+    except KeyError:
+      return False
+  else:
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      value = self._fields.get(field)
+      return value is not None and value._is_present_in_parent
+    else:
+      return field in self._fields
+
+
+
+def IsInitialized(self, errors=None) +
+
+

Checks if all required fields of a message are set.

+

Args

+
+
errors
+
A list which, if provided, will be populated with the field +paths of all missing required fields.
+
+

Returns

+

True iff the specified message has all required fields set.

+
+ +Expand source code + +
def IsInitialized(self, errors=None):
+  """Checks if all required fields of a message are set.
+
+  Args:
+    errors:  A list which, if provided, will be populated with the field
+             paths of all missing required fields.
+
+  Returns:
+    True iff the specified message has all required fields set.
+  """
+
+  # Performance is critical so we avoid HasField() and ListFields().
+
+  for field in required_fields:
+    if (field not in self._fields or
+        (field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE and
+         not self._fields[field]._is_present_in_parent)):
+      if errors is not None:
+        errors.extend(self.FindInitializationErrors())
+      return False
+
+  for field, value in list(self._fields.items()):  # dict can change size!
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if field.label == _FieldDescriptor.LABEL_REPEATED:
+        if (field.message_type.has_options and
+            field.message_type.GetOptions().map_entry):
+          continue
+        for element in value:
+          if not element.IsInitialized():
+            if errors is not None:
+              errors.extend(self.FindInitializationErrors())
+            return False
+      elif value._is_present_in_parent and not value.IsInitialized():
+        if errors is not None:
+          errors.extend(self.FindInitializationErrors())
+        return False
+
+  return True
+
+
+
+def ListFields(self) +
+
+
+
+ +Expand source code + +
def ListFields(self):
+  all_fields = [item for item in self._fields.items() if _IsPresent(item)]
+  all_fields.sort(key = lambda item: item[0].number)
+  return all_fields
+
+
+
+def MergeFrom(self, msg) +
+
+
+
+ +Expand source code + +
def MergeFrom(self, msg):
+  if not isinstance(msg, cls):
+    raise TypeError(
+        'Parameter to MergeFrom() must be instance of same class: '
+        'expected %s got %s.' % (cls.__name__, msg.__class__.__name__))
+
+  assert msg is not self
+  self._Modified()
+
+  fields = self._fields
+
+  for field, value in msg._fields.items():
+    if field.label == LABEL_REPEATED:
+      field_value = fields.get(field)
+      if field_value is None:
+        # Construct a new object to represent this field.
+        field_value = field._default_constructor(self)
+        fields[field] = field_value
+      field_value.MergeFrom(value)
+    elif field.cpp_type == CPPTYPE_MESSAGE:
+      if value._is_present_in_parent:
+        field_value = fields.get(field)
+        if field_value is None:
+          # Construct a new object to represent this field.
+          field_value = field._default_constructor(self)
+          fields[field] = field_value
+        field_value.MergeFrom(value)
+    else:
+      self._fields[field] = value
+      if field.containing_oneof:
+        self._UpdateOneofState(field)
+
+  if msg._unknown_fields:
+    if not self._unknown_fields:
+      self._unknown_fields = []
+    self._unknown_fields.extend(msg._unknown_fields)
+    # pylint: disable=protected-access
+    if self._unknown_field_set is None:
+      self._unknown_field_set = containers.UnknownFieldSet()
+    self._unknown_field_set._extend(msg._unknown_field_set)
+
+
+
+def MergeFromString(self, serialized) +
+
+
+
+ +Expand source code + +
def MergeFromString(self, serialized):
+  if isinstance(serialized, memoryview) and six.PY2:
+    raise TypeError(
+        'memoryview not supported in Python 2 with the pure Python proto '
+        'implementation: this is to maintain compatibility with the C++ '
+        'implementation')
+
+  serialized = memoryview(serialized)
+  length = len(serialized)
+  try:
+    if self._InternalParse(serialized, 0, length) != length:
+      # The only reason _InternalParse would return early is if it
+      # encountered an end-group tag.
+      raise message_mod.DecodeError('Unexpected end-group tag.')
+  except (IndexError, TypeError):
+    # Now ord(buf[p:p+1]) == ord('') gets TypeError.
+    raise message_mod.DecodeError('Truncated message.')
+  except struct.error as e:
+    raise message_mod.DecodeError(e)
+  return length   # Return this for legacy reasons.
+
+
+
+def SerializePartialToString(self, **kwargs) +
+
+
+
+ +Expand source code + +
def SerializePartialToString(self, **kwargs):
+  out = BytesIO()
+  self._InternalSerialize(out.write, **kwargs)
+  return out.getvalue()
+
+
+
+def SerializeToString(self, **kwargs) +
+
+
+
+ +Expand source code + +
def SerializeToString(self, **kwargs):
+  # Check if the message has all of its required fields set.
+  if not self.IsInitialized():
+    raise message_mod.EncodeError(
+        'Message %s is missing required fields: %s' % (
+        self.DESCRIPTOR.full_name, ','.join(self.FindInitializationErrors())))
+  return self.SerializePartialToString(**kwargs)
+
+
+
+def SetInParent(self) +
+
+

Sets the _cached_byte_size_dirty bit to true, +and propagates this to our listener iff this was a state change.

+
+ +Expand source code + +
def Modified(self):
+  """Sets the _cached_byte_size_dirty bit to true,
+  and propagates this to our listener iff this was a state change.
+  """
+
+  # Note:  Some callers check _cached_byte_size_dirty before calling
+  #   _Modified() as an extra optimization.  So, if this method is ever
+  #   changed such that it does stuff even when _cached_byte_size_dirty is
+  #   already true, the callers need to be updated.
+  if not self._cached_byte_size_dirty:
+    self._cached_byte_size_dirty = True
+    self._listener_for_children.dirty = True
+    self._is_present_in_parent = True
+    self._listener.Modified()
+
+
+
+def UnknownFields(self) +
+
+
+
+ +Expand source code + +
def _UnknownFields(self):
+  if self._unknown_field_set is None:  # pylint: disable=protected-access
+    # pylint: disable=protected-access
+    self._unknown_field_set = containers.UnknownFieldSet()
+  return self._unknown_field_set    # pylint: disable=protected-access
+
+
+
+def WhichOneof(self, oneof_name) +
+
+

Returns the name of the currently set field inside a oneof, or None.

+
+ +Expand source code + +
def WhichOneof(self, oneof_name):
+  """Returns the name of the currently set field inside a oneof, or None."""
+  try:
+    field = message_descriptor.oneofs_by_name[oneof_name]
+  except KeyError:
+    raise ValueError(
+        'Protocol message has no oneof "%s" field.' % oneof_name)
+
+  nested_field = self._oneofs.get(field, None)
+  if nested_field is not None and self.HasField(nested_field.name):
+    return nested_field.name
+  else:
+    return None
+
class MeshPacket -(*args, **kwargs) +(**kwargs)
-

A ProtocolMessage

+

Abstract base class for protocol messages.

+

Protocol message classes are almost always generated by the protocol +compiler. +These generated types subclass Message and implement the methods +shown below.

Ancestors

Class variables

+
var DECODED_FIELD_NUMBER
+
+
+
var DESCRIPTOR
+
var ENCRYPTED_FIELD_NUMBER
+
+
+
+
var FROM_FIELD_NUMBER
+
+
+
+
var HOP_LIMIT_FIELD_NUMBER
+
+
+
+
var ID_FIELD_NUMBER
+
+
+
+
var RX_SNR_FIELD_NUMBER
+
+
+
+
var RX_TIME_FIELD_NUMBER
+
+
+
+
var TO_FIELD_NUMBER
+
+
+
+
var WANT_ACK_FIELD_NUMBER
+
+
+
+
+

Static methods

+
+
+def FromString(s) +
+
+
+
+ +Expand source code + +
def FromString(s):
+  message = cls()
+  message.MergeFromString(s)
+  return message
+
+
+
+def RegisterExtension(extension_handle) +
+
+
+
+ +Expand source code + +
def RegisterExtension(extension_handle):
+  extension_handle.containing_type = cls.DESCRIPTOR
+  # TODO(amauryfa): Use cls.MESSAGE_FACTORY.pool when available.
+  # pylint: disable=protected-access
+  cls.DESCRIPTOR.file.pool._AddExtensionDescriptor(extension_handle)
+  _AttachFieldHelpers(cls, extension_handle)
+
+

Instance variables

var decoded
-

Field MeshPacket.decoded

+

Getter for decoded.

+
+ +Expand source code + +
def getter(self):
+  field_value = self._fields.get(field)
+  if field_value is None:
+    # Construct a new object to represent this field.
+    field_value = field._default_constructor(self)
+
+    # Atomically check if another thread has preempted us and, if not, swap
+    # in the new object we just created.  If someone has preempted us, we
+    # take that object and discard ours.
+    # WARNING:  We are relying on setdefault() being atomic.  This is true
+    #   in CPython but we haven't investigated others.  This warning appears
+    #   in several other locations in this file.
+    field_value = self._fields.setdefault(field, field_value)
+  return field_value
+
var encrypted
-

Field MeshPacket.encrypted

+

Getter for encrypted.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var from
-

Field MeshPacket.from

+

Getter for from.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var hop_limit
-

Field MeshPacket.hop_limit

+

Getter for hop_limit.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var id
-

Field MeshPacket.id

+

Getter for id.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var rx_snr
-

Field MeshPacket.rx_snr

+

Getter for rx_snr.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var rx_time
-

Field MeshPacket.rx_time

+

Getter for rx_time.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var to
-

Field MeshPacket.to

+

Getter for to.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var want_ack
-

Field MeshPacket.want_ack

+

Getter for want_ack.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
+
+
+

Methods

+
+
+def ByteSize(self) +
+
+
+
+ +Expand source code + +
def ByteSize(self):
+  if not self._cached_byte_size_dirty:
+    return self._cached_byte_size
+
+  size = 0
+  descriptor = self.DESCRIPTOR
+  if descriptor.GetOptions().map_entry:
+    # Fields of map entry should always be serialized.
+    size = descriptor.fields_by_name['key']._sizer(self.key)
+    size += descriptor.fields_by_name['value']._sizer(self.value)
+  else:
+    for field_descriptor, field_value in self.ListFields():
+      size += field_descriptor._sizer(field_value)
+    for tag_bytes, value_bytes in self._unknown_fields:
+      size += len(tag_bytes) + len(value_bytes)
+
+  self._cached_byte_size = size
+  self._cached_byte_size_dirty = False
+  self._listener_for_children.dirty = False
+  return size
+
+
+
+def Clear(self) +
+
+
+
+ +Expand source code + +
def _Clear(self):
+  # Clear fields.
+  self._fields = {}
+  self._unknown_fields = ()
+  # pylint: disable=protected-access
+  if self._unknown_field_set is not None:
+    self._unknown_field_set._clear()
+    self._unknown_field_set = None
+
+  self._oneofs = {}
+  self._Modified()
+
+
+
+def ClearField(self, field_name) +
+
+
+
+ +Expand source code + +
def ClearField(self, field_name):
+  try:
+    field = message_descriptor.fields_by_name[field_name]
+  except KeyError:
+    try:
+      field = message_descriptor.oneofs_by_name[field_name]
+      if field in self._oneofs:
+        field = self._oneofs[field]
+      else:
+        return
+    except KeyError:
+      raise ValueError('Protocol message %s has no "%s" field.' %
+                       (message_descriptor.name, field_name))
+
+  if field in self._fields:
+    # To match the C++ implementation, we need to invalidate iterators
+    # for map fields when ClearField() happens.
+    if hasattr(self._fields[field], 'InvalidateIterators'):
+      self._fields[field].InvalidateIterators()
+
+    # Note:  If the field is a sub-message, its listener will still point
+    #   at us.  That's fine, because the worst than can happen is that it
+    #   will call _Modified() and invalidate our byte size.  Big deal.
+    del self._fields[field]
+
+    if self._oneofs.get(field.containing_oneof, None) is field:
+      del self._oneofs[field.containing_oneof]
+
+  # Always call _Modified() -- even if nothing was changed, this is
+  # a mutating method, and thus calling it should cause the field to become
+  # present in the parent message.
+  self._Modified()
+
+
+
+def DiscardUnknownFields(self) +
+
+
+
+ +Expand source code + +
def _DiscardUnknownFields(self):
+  self._unknown_fields = []
+  self._unknown_field_set = None      # pylint: disable=protected-access
+  for field, value in self.ListFields():
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if _IsMapField(field):
+        if _IsMessageMapField(field):
+          for key in value:
+            value[key].DiscardUnknownFields()
+      elif field.label == _FieldDescriptor.LABEL_REPEATED:
+        for sub_message in value:
+          sub_message.DiscardUnknownFields()
+      else:
+        value.DiscardUnknownFields()
+
+
+
+def FindInitializationErrors(self) +
+
+

Finds required fields which are not initialized.

+

Returns

+

A list of strings. +Each string is a path to an uninitialized field from +the top-level message, e.g. "foo.bar[5].baz".

+
+ +Expand source code + +
def FindInitializationErrors(self):
+  """Finds required fields which are not initialized.
+
+  Returns:
+    A list of strings.  Each string is a path to an uninitialized field from
+    the top-level message, e.g. "foo.bar[5].baz".
+  """
+
+  errors = []  # simplify things
+
+  for field in required_fields:
+    if not self.HasField(field.name):
+      errors.append(field.name)
+
+  for field, value in self.ListFields():
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if field.is_extension:
+        name = '(%s)' % field.full_name
+      else:
+        name = field.name
+
+      if _IsMapField(field):
+        if _IsMessageMapField(field):
+          for key in value:
+            element = value[key]
+            prefix = '%s[%s].' % (name, key)
+            sub_errors = element.FindInitializationErrors()
+            errors += [prefix + error for error in sub_errors]
+        else:
+          # ScalarMaps can't have any initialization errors.
+          pass
+      elif field.label == _FieldDescriptor.LABEL_REPEATED:
+        for i in range(len(value)):
+          element = value[i]
+          prefix = '%s[%d].' % (name, i)
+          sub_errors = element.FindInitializationErrors()
+          errors += [prefix + error for error in sub_errors]
+      else:
+        prefix = name + '.'
+        sub_errors = value.FindInitializationErrors()
+        errors += [prefix + error for error in sub_errors]
+
+  return errors
+
+
+
+def HasField(self, field_name) +
+
+
+
+ +Expand source code + +
def HasField(self, field_name):
+  try:
+    field = hassable_fields[field_name]
+  except KeyError:
+    raise ValueError(error_msg % (message_descriptor.full_name, field_name))
+
+  if isinstance(field, descriptor_mod.OneofDescriptor):
+    try:
+      return HasField(self, self._oneofs[field].name)
+    except KeyError:
+      return False
+  else:
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      value = self._fields.get(field)
+      return value is not None and value._is_present_in_parent
+    else:
+      return field in self._fields
+
+
+
+def IsInitialized(self, errors=None) +
+
+

Checks if all required fields of a message are set.

+

Args

+
+
errors
+
A list which, if provided, will be populated with the field +paths of all missing required fields.
+
+

Returns

+

True iff the specified message has all required fields set.

+
+ +Expand source code + +
def IsInitialized(self, errors=None):
+  """Checks if all required fields of a message are set.
+
+  Args:
+    errors:  A list which, if provided, will be populated with the field
+             paths of all missing required fields.
+
+  Returns:
+    True iff the specified message has all required fields set.
+  """
+
+  # Performance is critical so we avoid HasField() and ListFields().
+
+  for field in required_fields:
+    if (field not in self._fields or
+        (field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE and
+         not self._fields[field]._is_present_in_parent)):
+      if errors is not None:
+        errors.extend(self.FindInitializationErrors())
+      return False
+
+  for field, value in list(self._fields.items()):  # dict can change size!
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if field.label == _FieldDescriptor.LABEL_REPEATED:
+        if (field.message_type.has_options and
+            field.message_type.GetOptions().map_entry):
+          continue
+        for element in value:
+          if not element.IsInitialized():
+            if errors is not None:
+              errors.extend(self.FindInitializationErrors())
+            return False
+      elif value._is_present_in_parent and not value.IsInitialized():
+        if errors is not None:
+          errors.extend(self.FindInitializationErrors())
+        return False
+
+  return True
+
+
+
+def ListFields(self) +
+
+
+
+ +Expand source code + +
def ListFields(self):
+  all_fields = [item for item in self._fields.items() if _IsPresent(item)]
+  all_fields.sort(key = lambda item: item[0].number)
+  return all_fields
+
+
+
+def MergeFrom(self, msg) +
+
+
+
+ +Expand source code + +
def MergeFrom(self, msg):
+  if not isinstance(msg, cls):
+    raise TypeError(
+        'Parameter to MergeFrom() must be instance of same class: '
+        'expected %s got %s.' % (cls.__name__, msg.__class__.__name__))
+
+  assert msg is not self
+  self._Modified()
+
+  fields = self._fields
+
+  for field, value in msg._fields.items():
+    if field.label == LABEL_REPEATED:
+      field_value = fields.get(field)
+      if field_value is None:
+        # Construct a new object to represent this field.
+        field_value = field._default_constructor(self)
+        fields[field] = field_value
+      field_value.MergeFrom(value)
+    elif field.cpp_type == CPPTYPE_MESSAGE:
+      if value._is_present_in_parent:
+        field_value = fields.get(field)
+        if field_value is None:
+          # Construct a new object to represent this field.
+          field_value = field._default_constructor(self)
+          fields[field] = field_value
+        field_value.MergeFrom(value)
+    else:
+      self._fields[field] = value
+      if field.containing_oneof:
+        self._UpdateOneofState(field)
+
+  if msg._unknown_fields:
+    if not self._unknown_fields:
+      self._unknown_fields = []
+    self._unknown_fields.extend(msg._unknown_fields)
+    # pylint: disable=protected-access
+    if self._unknown_field_set is None:
+      self._unknown_field_set = containers.UnknownFieldSet()
+    self._unknown_field_set._extend(msg._unknown_field_set)
+
+
+
+def MergeFromString(self, serialized) +
+
+
+
+ +Expand source code + +
def MergeFromString(self, serialized):
+  if isinstance(serialized, memoryview) and six.PY2:
+    raise TypeError(
+        'memoryview not supported in Python 2 with the pure Python proto '
+        'implementation: this is to maintain compatibility with the C++ '
+        'implementation')
+
+  serialized = memoryview(serialized)
+  length = len(serialized)
+  try:
+    if self._InternalParse(serialized, 0, length) != length:
+      # The only reason _InternalParse would return early is if it
+      # encountered an end-group tag.
+      raise message_mod.DecodeError('Unexpected end-group tag.')
+  except (IndexError, TypeError):
+    # Now ord(buf[p:p+1]) == ord('') gets TypeError.
+    raise message_mod.DecodeError('Truncated message.')
+  except struct.error as e:
+    raise message_mod.DecodeError(e)
+  return length   # Return this for legacy reasons.
+
+
+
+def SerializePartialToString(self, **kwargs) +
+
+
+
+ +Expand source code + +
def SerializePartialToString(self, **kwargs):
+  out = BytesIO()
+  self._InternalSerialize(out.write, **kwargs)
+  return out.getvalue()
+
+
+
+def SerializeToString(self, **kwargs) +
+
+
+
+ +Expand source code + +
def SerializeToString(self, **kwargs):
+  # Check if the message has all of its required fields set.
+  if not self.IsInitialized():
+    raise message_mod.EncodeError(
+        'Message %s is missing required fields: %s' % (
+        self.DESCRIPTOR.full_name, ','.join(self.FindInitializationErrors())))
+  return self.SerializePartialToString(**kwargs)
+
+
+
+def SetInParent(self) +
+
+

Sets the _cached_byte_size_dirty bit to true, +and propagates this to our listener iff this was a state change.

+
+ +Expand source code + +
def Modified(self):
+  """Sets the _cached_byte_size_dirty bit to true,
+  and propagates this to our listener iff this was a state change.
+  """
+
+  # Note:  Some callers check _cached_byte_size_dirty before calling
+  #   _Modified() as an extra optimization.  So, if this method is ever
+  #   changed such that it does stuff even when _cached_byte_size_dirty is
+  #   already true, the callers need to be updated.
+  if not self._cached_byte_size_dirty:
+    self._cached_byte_size_dirty = True
+    self._listener_for_children.dirty = True
+    self._is_present_in_parent = True
+    self._listener.Modified()
+
+
+
+def UnknownFields(self) +
+
+
+
+ +Expand source code + +
def _UnknownFields(self):
+  if self._unknown_field_set is None:  # pylint: disable=protected-access
+    # pylint: disable=protected-access
+    self._unknown_field_set = containers.UnknownFieldSet()
+  return self._unknown_field_set    # pylint: disable=protected-access
+
+
+
+def WhichOneof(self, oneof_name) +
+
+

Returns the name of the currently set field inside a oneof, or None.

+
+ +Expand source code + +
def WhichOneof(self, oneof_name):
+  """Returns the name of the currently set field inside a oneof, or None."""
+  try:
+    field = message_descriptor.oneofs_by_name[oneof_name]
+  except KeyError:
+    raise ValueError(
+        'Protocol message has no oneof "%s" field.' % oneof_name)
+
+  nested_field = self._oneofs.get(field, None)
+  if nested_field is not None and self.HasField(nested_field.name):
+    return nested_field.name
+  else:
+    return None
+
class MyNodeInfo -(*args, **kwargs) +(**kwargs)
-

A ProtocolMessage

+

Abstract base class for protocol messages.

+

Protocol message classes are almost always generated by the protocol +compiler. +These generated types subclass Message and implement the methods +shown below.

Ancestors

Class variables

+
var CURRENT_PACKET_ID_FIELD_NUMBER
+
+
+
var DESCRIPTOR
+
var ERROR_ADDRESS_FIELD_NUMBER
+
+
+
+
var ERROR_CODE_FIELD_NUMBER
+
+
+
+
var ERROR_COUNT_FIELD_NUMBER
+
+
+
+
var FIRMWARE_VERSION_FIELD_NUMBER
+
+
+
+
var HAS_GPS_FIELD_NUMBER
+
+
+
+
var HW_MODEL_FIELD_NUMBER
+
+
+
+
var MESSAGE_TIMEOUT_MSEC_FIELD_NUMBER
+
+
+
+
var MIN_APP_VERSION_FIELD_NUMBER
+
+
+
+
var MY_NODE_NUM_FIELD_NUMBER
+
+
+
+
var NODE_NUM_BITS_FIELD_NUMBER
+
+
+
+
var NUM_CHANNELS_FIELD_NUMBER
+
+
+
+
var PACKET_ID_BITS_FIELD_NUMBER
+
+
+
+
var REGION_FIELD_NUMBER
+
+
+
+
+

Static methods

+
+
+def FromString(s) +
+
+
+
+ +Expand source code + +
def FromString(s):
+  message = cls()
+  message.MergeFromString(s)
+  return message
+
+
+
+def RegisterExtension(extension_handle) +
+
+
+
+ +Expand source code + +
def RegisterExtension(extension_handle):
+  extension_handle.containing_type = cls.DESCRIPTOR
+  # TODO(amauryfa): Use cls.MESSAGE_FACTORY.pool when available.
+  # pylint: disable=protected-access
+  cls.DESCRIPTOR.file.pool._AddExtensionDescriptor(extension_handle)
+  _AttachFieldHelpers(cls, extension_handle)
+
+

Instance variables

var current_packet_id
-

Field MyNodeInfo.current_packet_id

+

Getter for current_packet_id.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var error_address
-

Field MyNodeInfo.error_address

+

Getter for error_address.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var error_code
-

Field MyNodeInfo.error_code

+

Getter for error_code.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var error_count
-

Field MyNodeInfo.error_count

+

Getter for error_count.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var firmware_version
-

Field MyNodeInfo.firmware_version

+

Getter for firmware_version.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var has_gps
-

Field MyNodeInfo.has_gps

+

Getter for has_gps.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var hw_model
-

Field MyNodeInfo.hw_model

+

Getter for hw_model.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var message_timeout_msec
-

Field MyNodeInfo.message_timeout_msec

+

Getter for message_timeout_msec.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var min_app_version
-

Field MyNodeInfo.min_app_version

+

Getter for min_app_version.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var my_node_num
-

Field MyNodeInfo.my_node_num

+

Getter for my_node_num.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var node_num_bits
-

Field MyNodeInfo.node_num_bits

+

Getter for node_num_bits.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var num_channels
-

Field MyNodeInfo.num_channels

+

Getter for num_channels.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var packet_id_bits
-

Field MyNodeInfo.packet_id_bits

+

Getter for packet_id_bits.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var region
-

Field MyNodeInfo.region

+

Getter for region.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
+
+
+

Methods

+
+
+def ByteSize(self) +
+
+
+
+ +Expand source code + +
def ByteSize(self):
+  if not self._cached_byte_size_dirty:
+    return self._cached_byte_size
+
+  size = 0
+  descriptor = self.DESCRIPTOR
+  if descriptor.GetOptions().map_entry:
+    # Fields of map entry should always be serialized.
+    size = descriptor.fields_by_name['key']._sizer(self.key)
+    size += descriptor.fields_by_name['value']._sizer(self.value)
+  else:
+    for field_descriptor, field_value in self.ListFields():
+      size += field_descriptor._sizer(field_value)
+    for tag_bytes, value_bytes in self._unknown_fields:
+      size += len(tag_bytes) + len(value_bytes)
+
+  self._cached_byte_size = size
+  self._cached_byte_size_dirty = False
+  self._listener_for_children.dirty = False
+  return size
+
+
+
+def Clear(self) +
+
+
+
+ +Expand source code + +
def _Clear(self):
+  # Clear fields.
+  self._fields = {}
+  self._unknown_fields = ()
+  # pylint: disable=protected-access
+  if self._unknown_field_set is not None:
+    self._unknown_field_set._clear()
+    self._unknown_field_set = None
+
+  self._oneofs = {}
+  self._Modified()
+
+
+
+def ClearField(self, field_name) +
+
+
+
+ +Expand source code + +
def ClearField(self, field_name):
+  try:
+    field = message_descriptor.fields_by_name[field_name]
+  except KeyError:
+    try:
+      field = message_descriptor.oneofs_by_name[field_name]
+      if field in self._oneofs:
+        field = self._oneofs[field]
+      else:
+        return
+    except KeyError:
+      raise ValueError('Protocol message %s has no "%s" field.' %
+                       (message_descriptor.name, field_name))
+
+  if field in self._fields:
+    # To match the C++ implementation, we need to invalidate iterators
+    # for map fields when ClearField() happens.
+    if hasattr(self._fields[field], 'InvalidateIterators'):
+      self._fields[field].InvalidateIterators()
+
+    # Note:  If the field is a sub-message, its listener will still point
+    #   at us.  That's fine, because the worst than can happen is that it
+    #   will call _Modified() and invalidate our byte size.  Big deal.
+    del self._fields[field]
+
+    if self._oneofs.get(field.containing_oneof, None) is field:
+      del self._oneofs[field.containing_oneof]
+
+  # Always call _Modified() -- even if nothing was changed, this is
+  # a mutating method, and thus calling it should cause the field to become
+  # present in the parent message.
+  self._Modified()
+
+
+
+def DiscardUnknownFields(self) +
+
+
+
+ +Expand source code + +
def _DiscardUnknownFields(self):
+  self._unknown_fields = []
+  self._unknown_field_set = None      # pylint: disable=protected-access
+  for field, value in self.ListFields():
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if _IsMapField(field):
+        if _IsMessageMapField(field):
+          for key in value:
+            value[key].DiscardUnknownFields()
+      elif field.label == _FieldDescriptor.LABEL_REPEATED:
+        for sub_message in value:
+          sub_message.DiscardUnknownFields()
+      else:
+        value.DiscardUnknownFields()
+
+
+
+def FindInitializationErrors(self) +
+
+

Finds required fields which are not initialized.

+

Returns

+

A list of strings. +Each string is a path to an uninitialized field from +the top-level message, e.g. "foo.bar[5].baz".

+
+ +Expand source code + +
def FindInitializationErrors(self):
+  """Finds required fields which are not initialized.
+
+  Returns:
+    A list of strings.  Each string is a path to an uninitialized field from
+    the top-level message, e.g. "foo.bar[5].baz".
+  """
+
+  errors = []  # simplify things
+
+  for field in required_fields:
+    if not self.HasField(field.name):
+      errors.append(field.name)
+
+  for field, value in self.ListFields():
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if field.is_extension:
+        name = '(%s)' % field.full_name
+      else:
+        name = field.name
+
+      if _IsMapField(field):
+        if _IsMessageMapField(field):
+          for key in value:
+            element = value[key]
+            prefix = '%s[%s].' % (name, key)
+            sub_errors = element.FindInitializationErrors()
+            errors += [prefix + error for error in sub_errors]
+        else:
+          # ScalarMaps can't have any initialization errors.
+          pass
+      elif field.label == _FieldDescriptor.LABEL_REPEATED:
+        for i in range(len(value)):
+          element = value[i]
+          prefix = '%s[%d].' % (name, i)
+          sub_errors = element.FindInitializationErrors()
+          errors += [prefix + error for error in sub_errors]
+      else:
+        prefix = name + '.'
+        sub_errors = value.FindInitializationErrors()
+        errors += [prefix + error for error in sub_errors]
+
+  return errors
+
+
+
+def HasField(self, field_name) +
+
+
+
+ +Expand source code + +
def HasField(self, field_name):
+  try:
+    field = hassable_fields[field_name]
+  except KeyError:
+    raise ValueError(error_msg % (message_descriptor.full_name, field_name))
+
+  if isinstance(field, descriptor_mod.OneofDescriptor):
+    try:
+      return HasField(self, self._oneofs[field].name)
+    except KeyError:
+      return False
+  else:
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      value = self._fields.get(field)
+      return value is not None and value._is_present_in_parent
+    else:
+      return field in self._fields
+
+
+
+def IsInitialized(self, errors=None) +
+
+

Checks if all required fields of a message are set.

+

Args

+
+
errors
+
A list which, if provided, will be populated with the field +paths of all missing required fields.
+
+

Returns

+

True iff the specified message has all required fields set.

+
+ +Expand source code + +
def IsInitialized(self, errors=None):
+  """Checks if all required fields of a message are set.
+
+  Args:
+    errors:  A list which, if provided, will be populated with the field
+             paths of all missing required fields.
+
+  Returns:
+    True iff the specified message has all required fields set.
+  """
+
+  # Performance is critical so we avoid HasField() and ListFields().
+
+  for field in required_fields:
+    if (field not in self._fields or
+        (field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE and
+         not self._fields[field]._is_present_in_parent)):
+      if errors is not None:
+        errors.extend(self.FindInitializationErrors())
+      return False
+
+  for field, value in list(self._fields.items()):  # dict can change size!
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if field.label == _FieldDescriptor.LABEL_REPEATED:
+        if (field.message_type.has_options and
+            field.message_type.GetOptions().map_entry):
+          continue
+        for element in value:
+          if not element.IsInitialized():
+            if errors is not None:
+              errors.extend(self.FindInitializationErrors())
+            return False
+      elif value._is_present_in_parent and not value.IsInitialized():
+        if errors is not None:
+          errors.extend(self.FindInitializationErrors())
+        return False
+
+  return True
+
+
+
+def ListFields(self) +
+
+
+
+ +Expand source code + +
def ListFields(self):
+  all_fields = [item for item in self._fields.items() if _IsPresent(item)]
+  all_fields.sort(key = lambda item: item[0].number)
+  return all_fields
+
+
+
+def MergeFrom(self, msg) +
+
+
+
+ +Expand source code + +
def MergeFrom(self, msg):
+  if not isinstance(msg, cls):
+    raise TypeError(
+        'Parameter to MergeFrom() must be instance of same class: '
+        'expected %s got %s.' % (cls.__name__, msg.__class__.__name__))
+
+  assert msg is not self
+  self._Modified()
+
+  fields = self._fields
+
+  for field, value in msg._fields.items():
+    if field.label == LABEL_REPEATED:
+      field_value = fields.get(field)
+      if field_value is None:
+        # Construct a new object to represent this field.
+        field_value = field._default_constructor(self)
+        fields[field] = field_value
+      field_value.MergeFrom(value)
+    elif field.cpp_type == CPPTYPE_MESSAGE:
+      if value._is_present_in_parent:
+        field_value = fields.get(field)
+        if field_value is None:
+          # Construct a new object to represent this field.
+          field_value = field._default_constructor(self)
+          fields[field] = field_value
+        field_value.MergeFrom(value)
+    else:
+      self._fields[field] = value
+      if field.containing_oneof:
+        self._UpdateOneofState(field)
+
+  if msg._unknown_fields:
+    if not self._unknown_fields:
+      self._unknown_fields = []
+    self._unknown_fields.extend(msg._unknown_fields)
+    # pylint: disable=protected-access
+    if self._unknown_field_set is None:
+      self._unknown_field_set = containers.UnknownFieldSet()
+    self._unknown_field_set._extend(msg._unknown_field_set)
+
+
+
+def MergeFromString(self, serialized) +
+
+
+
+ +Expand source code + +
def MergeFromString(self, serialized):
+  if isinstance(serialized, memoryview) and six.PY2:
+    raise TypeError(
+        'memoryview not supported in Python 2 with the pure Python proto '
+        'implementation: this is to maintain compatibility with the C++ '
+        'implementation')
+
+  serialized = memoryview(serialized)
+  length = len(serialized)
+  try:
+    if self._InternalParse(serialized, 0, length) != length:
+      # The only reason _InternalParse would return early is if it
+      # encountered an end-group tag.
+      raise message_mod.DecodeError('Unexpected end-group tag.')
+  except (IndexError, TypeError):
+    # Now ord(buf[p:p+1]) == ord('') gets TypeError.
+    raise message_mod.DecodeError('Truncated message.')
+  except struct.error as e:
+    raise message_mod.DecodeError(e)
+  return length   # Return this for legacy reasons.
+
+
+
+def SerializePartialToString(self, **kwargs) +
+
+
+
+ +Expand source code + +
def SerializePartialToString(self, **kwargs):
+  out = BytesIO()
+  self._InternalSerialize(out.write, **kwargs)
+  return out.getvalue()
+
+
+
+def SerializeToString(self, **kwargs) +
+
+
+
+ +Expand source code + +
def SerializeToString(self, **kwargs):
+  # Check if the message has all of its required fields set.
+  if not self.IsInitialized():
+    raise message_mod.EncodeError(
+        'Message %s is missing required fields: %s' % (
+        self.DESCRIPTOR.full_name, ','.join(self.FindInitializationErrors())))
+  return self.SerializePartialToString(**kwargs)
+
+
+
+def SetInParent(self) +
+
+

Sets the _cached_byte_size_dirty bit to true, +and propagates this to our listener iff this was a state change.

+
+ +Expand source code + +
def Modified(self):
+  """Sets the _cached_byte_size_dirty bit to true,
+  and propagates this to our listener iff this was a state change.
+  """
+
+  # Note:  Some callers check _cached_byte_size_dirty before calling
+  #   _Modified() as an extra optimization.  So, if this method is ever
+  #   changed such that it does stuff even when _cached_byte_size_dirty is
+  #   already true, the callers need to be updated.
+  if not self._cached_byte_size_dirty:
+    self._cached_byte_size_dirty = True
+    self._listener_for_children.dirty = True
+    self._is_present_in_parent = True
+    self._listener.Modified()
+
+
+
+def UnknownFields(self) +
+
+
+
+ +Expand source code + +
def _UnknownFields(self):
+  if self._unknown_field_set is None:  # pylint: disable=protected-access
+    # pylint: disable=protected-access
+    self._unknown_field_set = containers.UnknownFieldSet()
+  return self._unknown_field_set    # pylint: disable=protected-access
+
+
+
+def WhichOneof(self, oneof_name) +
+
+

Returns the name of the currently set field inside a oneof, or None.

+
+ +Expand source code + +
def WhichOneof(self, oneof_name):
+  """Returns the name of the currently set field inside a oneof, or None."""
+  try:
+    field = message_descriptor.oneofs_by_name[oneof_name]
+  except KeyError:
+    raise ValueError(
+        'Protocol message has no oneof "%s" field.' % oneof_name)
+
+  nested_field = self._oneofs.get(field, None)
+  if nested_field is not None and self.HasField(nested_field.name):
+    return nested_field.name
+  else:
+    return None
+
class NodeInfo -(*args, **kwargs) +(**kwargs)
-

A ProtocolMessage

+

Abstract base class for protocol messages.

+

Protocol message classes are almost always generated by the protocol +compiler. +These generated types subclass Message and implement the methods +shown below.

Ancestors

Class variables

@@ -2222,116 +7068,1819 @@ DESCRIPTOR._options = None
+
var NEXT_HOP_FIELD_NUMBER
+
+
+
+
var NUM_FIELD_NUMBER
+
+
+
+
var POSITION_FIELD_NUMBER
+
+
+
+
var SNR_FIELD_NUMBER
+
+
+
+
var USER_FIELD_NUMBER
+
+
+
+ +

Static methods

+
+
+def FromString(s) +
+
+
+
+ +Expand source code + +
def FromString(s):
+  message = cls()
+  message.MergeFromString(s)
+  return message
+
+
+
+def RegisterExtension(extension_handle) +
+
+
+
+ +Expand source code + +
def RegisterExtension(extension_handle):
+  extension_handle.containing_type = cls.DESCRIPTOR
+  # TODO(amauryfa): Use cls.MESSAGE_FACTORY.pool when available.
+  # pylint: disable=protected-access
+  cls.DESCRIPTOR.file.pool._AddExtensionDescriptor(extension_handle)
+  _AttachFieldHelpers(cls, extension_handle)
+
+

Instance variables

var next_hop
-

Field NodeInfo.next_hop

+

Getter for next_hop.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var num
-

Field NodeInfo.num

+

Getter for num.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var position
-

Field NodeInfo.position

+

Getter for position.

+
+ +Expand source code + +
def getter(self):
+  field_value = self._fields.get(field)
+  if field_value is None:
+    # Construct a new object to represent this field.
+    field_value = field._default_constructor(self)
+
+    # Atomically check if another thread has preempted us and, if not, swap
+    # in the new object we just created.  If someone has preempted us, we
+    # take that object and discard ours.
+    # WARNING:  We are relying on setdefault() being atomic.  This is true
+    #   in CPython but we haven't investigated others.  This warning appears
+    #   in several other locations in this file.
+    field_value = self._fields.setdefault(field, field_value)
+  return field_value
+
var snr
-

Field NodeInfo.snr

+

Getter for snr.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var user
-

Field NodeInfo.user

+

Getter for user.

+
+ +Expand source code + +
def getter(self):
+  field_value = self._fields.get(field)
+  if field_value is None:
+    # Construct a new object to represent this field.
+    field_value = field._default_constructor(self)
+
+    # Atomically check if another thread has preempted us and, if not, swap
+    # in the new object we just created.  If someone has preempted us, we
+    # take that object and discard ours.
+    # WARNING:  We are relying on setdefault() being atomic.  This is true
+    #   in CPython but we haven't investigated others.  This warning appears
+    #   in several other locations in this file.
+    field_value = self._fields.setdefault(field, field_value)
+  return field_value
+
+
+
+

Methods

+
+
+def ByteSize(self) +
+
+
+
+ +Expand source code + +
def ByteSize(self):
+  if not self._cached_byte_size_dirty:
+    return self._cached_byte_size
+
+  size = 0
+  descriptor = self.DESCRIPTOR
+  if descriptor.GetOptions().map_entry:
+    # Fields of map entry should always be serialized.
+    size = descriptor.fields_by_name['key']._sizer(self.key)
+    size += descriptor.fields_by_name['value']._sizer(self.value)
+  else:
+    for field_descriptor, field_value in self.ListFields():
+      size += field_descriptor._sizer(field_value)
+    for tag_bytes, value_bytes in self._unknown_fields:
+      size += len(tag_bytes) + len(value_bytes)
+
+  self._cached_byte_size = size
+  self._cached_byte_size_dirty = False
+  self._listener_for_children.dirty = False
+  return size
+
+
+
+def Clear(self) +
+
+
+
+ +Expand source code + +
def _Clear(self):
+  # Clear fields.
+  self._fields = {}
+  self._unknown_fields = ()
+  # pylint: disable=protected-access
+  if self._unknown_field_set is not None:
+    self._unknown_field_set._clear()
+    self._unknown_field_set = None
+
+  self._oneofs = {}
+  self._Modified()
+
+
+
+def ClearField(self, field_name) +
+
+
+
+ +Expand source code + +
def ClearField(self, field_name):
+  try:
+    field = message_descriptor.fields_by_name[field_name]
+  except KeyError:
+    try:
+      field = message_descriptor.oneofs_by_name[field_name]
+      if field in self._oneofs:
+        field = self._oneofs[field]
+      else:
+        return
+    except KeyError:
+      raise ValueError('Protocol message %s has no "%s" field.' %
+                       (message_descriptor.name, field_name))
+
+  if field in self._fields:
+    # To match the C++ implementation, we need to invalidate iterators
+    # for map fields when ClearField() happens.
+    if hasattr(self._fields[field], 'InvalidateIterators'):
+      self._fields[field].InvalidateIterators()
+
+    # Note:  If the field is a sub-message, its listener will still point
+    #   at us.  That's fine, because the worst than can happen is that it
+    #   will call _Modified() and invalidate our byte size.  Big deal.
+    del self._fields[field]
+
+    if self._oneofs.get(field.containing_oneof, None) is field:
+      del self._oneofs[field.containing_oneof]
+
+  # Always call _Modified() -- even if nothing was changed, this is
+  # a mutating method, and thus calling it should cause the field to become
+  # present in the parent message.
+  self._Modified()
+
+
+
+def DiscardUnknownFields(self) +
+
+
+
+ +Expand source code + +
def _DiscardUnknownFields(self):
+  self._unknown_fields = []
+  self._unknown_field_set = None      # pylint: disable=protected-access
+  for field, value in self.ListFields():
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if _IsMapField(field):
+        if _IsMessageMapField(field):
+          for key in value:
+            value[key].DiscardUnknownFields()
+      elif field.label == _FieldDescriptor.LABEL_REPEATED:
+        for sub_message in value:
+          sub_message.DiscardUnknownFields()
+      else:
+        value.DiscardUnknownFields()
+
+
+
+def FindInitializationErrors(self) +
+
+

Finds required fields which are not initialized.

+

Returns

+

A list of strings. +Each string is a path to an uninitialized field from +the top-level message, e.g. "foo.bar[5].baz".

+
+ +Expand source code + +
def FindInitializationErrors(self):
+  """Finds required fields which are not initialized.
+
+  Returns:
+    A list of strings.  Each string is a path to an uninitialized field from
+    the top-level message, e.g. "foo.bar[5].baz".
+  """
+
+  errors = []  # simplify things
+
+  for field in required_fields:
+    if not self.HasField(field.name):
+      errors.append(field.name)
+
+  for field, value in self.ListFields():
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if field.is_extension:
+        name = '(%s)' % field.full_name
+      else:
+        name = field.name
+
+      if _IsMapField(field):
+        if _IsMessageMapField(field):
+          for key in value:
+            element = value[key]
+            prefix = '%s[%s].' % (name, key)
+            sub_errors = element.FindInitializationErrors()
+            errors += [prefix + error for error in sub_errors]
+        else:
+          # ScalarMaps can't have any initialization errors.
+          pass
+      elif field.label == _FieldDescriptor.LABEL_REPEATED:
+        for i in range(len(value)):
+          element = value[i]
+          prefix = '%s[%d].' % (name, i)
+          sub_errors = element.FindInitializationErrors()
+          errors += [prefix + error for error in sub_errors]
+      else:
+        prefix = name + '.'
+        sub_errors = value.FindInitializationErrors()
+        errors += [prefix + error for error in sub_errors]
+
+  return errors
+
+
+
+def HasField(self, field_name) +
+
+
+
+ +Expand source code + +
def HasField(self, field_name):
+  try:
+    field = hassable_fields[field_name]
+  except KeyError:
+    raise ValueError(error_msg % (message_descriptor.full_name, field_name))
+
+  if isinstance(field, descriptor_mod.OneofDescriptor):
+    try:
+      return HasField(self, self._oneofs[field].name)
+    except KeyError:
+      return False
+  else:
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      value = self._fields.get(field)
+      return value is not None and value._is_present_in_parent
+    else:
+      return field in self._fields
+
+
+
+def IsInitialized(self, errors=None) +
+
+

Checks if all required fields of a message are set.

+

Args

+
+
errors
+
A list which, if provided, will be populated with the field +paths of all missing required fields.
+
+

Returns

+

True iff the specified message has all required fields set.

+
+ +Expand source code + +
def IsInitialized(self, errors=None):
+  """Checks if all required fields of a message are set.
+
+  Args:
+    errors:  A list which, if provided, will be populated with the field
+             paths of all missing required fields.
+
+  Returns:
+    True iff the specified message has all required fields set.
+  """
+
+  # Performance is critical so we avoid HasField() and ListFields().
+
+  for field in required_fields:
+    if (field not in self._fields or
+        (field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE and
+         not self._fields[field]._is_present_in_parent)):
+      if errors is not None:
+        errors.extend(self.FindInitializationErrors())
+      return False
+
+  for field, value in list(self._fields.items()):  # dict can change size!
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if field.label == _FieldDescriptor.LABEL_REPEATED:
+        if (field.message_type.has_options and
+            field.message_type.GetOptions().map_entry):
+          continue
+        for element in value:
+          if not element.IsInitialized():
+            if errors is not None:
+              errors.extend(self.FindInitializationErrors())
+            return False
+      elif value._is_present_in_parent and not value.IsInitialized():
+        if errors is not None:
+          errors.extend(self.FindInitializationErrors())
+        return False
+
+  return True
+
+
+
+def ListFields(self) +
+
+
+
+ +Expand source code + +
def ListFields(self):
+  all_fields = [item for item in self._fields.items() if _IsPresent(item)]
+  all_fields.sort(key = lambda item: item[0].number)
+  return all_fields
+
+
+
+def MergeFrom(self, msg) +
+
+
+
+ +Expand source code + +
def MergeFrom(self, msg):
+  if not isinstance(msg, cls):
+    raise TypeError(
+        'Parameter to MergeFrom() must be instance of same class: '
+        'expected %s got %s.' % (cls.__name__, msg.__class__.__name__))
+
+  assert msg is not self
+  self._Modified()
+
+  fields = self._fields
+
+  for field, value in msg._fields.items():
+    if field.label == LABEL_REPEATED:
+      field_value = fields.get(field)
+      if field_value is None:
+        # Construct a new object to represent this field.
+        field_value = field._default_constructor(self)
+        fields[field] = field_value
+      field_value.MergeFrom(value)
+    elif field.cpp_type == CPPTYPE_MESSAGE:
+      if value._is_present_in_parent:
+        field_value = fields.get(field)
+        if field_value is None:
+          # Construct a new object to represent this field.
+          field_value = field._default_constructor(self)
+          fields[field] = field_value
+        field_value.MergeFrom(value)
+    else:
+      self._fields[field] = value
+      if field.containing_oneof:
+        self._UpdateOneofState(field)
+
+  if msg._unknown_fields:
+    if not self._unknown_fields:
+      self._unknown_fields = []
+    self._unknown_fields.extend(msg._unknown_fields)
+    # pylint: disable=protected-access
+    if self._unknown_field_set is None:
+      self._unknown_field_set = containers.UnknownFieldSet()
+    self._unknown_field_set._extend(msg._unknown_field_set)
+
+
+
+def MergeFromString(self, serialized) +
+
+
+
+ +Expand source code + +
def MergeFromString(self, serialized):
+  if isinstance(serialized, memoryview) and six.PY2:
+    raise TypeError(
+        'memoryview not supported in Python 2 with the pure Python proto '
+        'implementation: this is to maintain compatibility with the C++ '
+        'implementation')
+
+  serialized = memoryview(serialized)
+  length = len(serialized)
+  try:
+    if self._InternalParse(serialized, 0, length) != length:
+      # The only reason _InternalParse would return early is if it
+      # encountered an end-group tag.
+      raise message_mod.DecodeError('Unexpected end-group tag.')
+  except (IndexError, TypeError):
+    # Now ord(buf[p:p+1]) == ord('') gets TypeError.
+    raise message_mod.DecodeError('Truncated message.')
+  except struct.error as e:
+    raise message_mod.DecodeError(e)
+  return length   # Return this for legacy reasons.
+
+
+
+def SerializePartialToString(self, **kwargs) +
+
+
+
+ +Expand source code + +
def SerializePartialToString(self, **kwargs):
+  out = BytesIO()
+  self._InternalSerialize(out.write, **kwargs)
+  return out.getvalue()
+
+
+
+def SerializeToString(self, **kwargs) +
+
+
+
+ +Expand source code + +
def SerializeToString(self, **kwargs):
+  # Check if the message has all of its required fields set.
+  if not self.IsInitialized():
+    raise message_mod.EncodeError(
+        'Message %s is missing required fields: %s' % (
+        self.DESCRIPTOR.full_name, ','.join(self.FindInitializationErrors())))
+  return self.SerializePartialToString(**kwargs)
+
+
+
+def SetInParent(self) +
+
+

Sets the _cached_byte_size_dirty bit to true, +and propagates this to our listener iff this was a state change.

+
+ +Expand source code + +
def Modified(self):
+  """Sets the _cached_byte_size_dirty bit to true,
+  and propagates this to our listener iff this was a state change.
+  """
+
+  # Note:  Some callers check _cached_byte_size_dirty before calling
+  #   _Modified() as an extra optimization.  So, if this method is ever
+  #   changed such that it does stuff even when _cached_byte_size_dirty is
+  #   already true, the callers need to be updated.
+  if not self._cached_byte_size_dirty:
+    self._cached_byte_size_dirty = True
+    self._listener_for_children.dirty = True
+    self._is_present_in_parent = True
+    self._listener.Modified()
+
+
+
+def UnknownFields(self) +
+
+
+
+ +Expand source code + +
def _UnknownFields(self):
+  if self._unknown_field_set is None:  # pylint: disable=protected-access
+    # pylint: disable=protected-access
+    self._unknown_field_set = containers.UnknownFieldSet()
+  return self._unknown_field_set    # pylint: disable=protected-access
+
+
+
+def WhichOneof(self, oneof_name) +
+
+

Returns the name of the currently set field inside a oneof, or None.

+
+ +Expand source code + +
def WhichOneof(self, oneof_name):
+  """Returns the name of the currently set field inside a oneof, or None."""
+  try:
+    field = message_descriptor.oneofs_by_name[oneof_name]
+  except KeyError:
+    raise ValueError(
+        'Protocol message has no oneof "%s" field.' % oneof_name)
+
+  nested_field = self._oneofs.get(field, None)
+  if nested_field is not None and self.HasField(nested_field.name):
+    return nested_field.name
+  else:
+    return None
+
class Position -(*args, **kwargs) +(**kwargs)
-

A ProtocolMessage

+

Abstract base class for protocol messages.

+

Protocol message classes are almost always generated by the protocol +compiler. +These generated types subclass Message and implement the methods +shown below.

Ancestors

Class variables

+
var ALTITUDE_FIELD_NUMBER
+
+
+
+
var BATTERY_LEVEL_FIELD_NUMBER
+
+
+
var DESCRIPTOR
+
var LATITUDE_I_FIELD_NUMBER
+
+
+
+
var LONGITUDE_I_FIELD_NUMBER
+
+
+
+
var TIME_FIELD_NUMBER
+
+
+
+
+

Static methods

+
+
+def FromString(s) +
+
+
+
+ +Expand source code + +
def FromString(s):
+  message = cls()
+  message.MergeFromString(s)
+  return message
+
+
+
+def RegisterExtension(extension_handle) +
+
+
+
+ +Expand source code + +
def RegisterExtension(extension_handle):
+  extension_handle.containing_type = cls.DESCRIPTOR
+  # TODO(amauryfa): Use cls.MESSAGE_FACTORY.pool when available.
+  # pylint: disable=protected-access
+  cls.DESCRIPTOR.file.pool._AddExtensionDescriptor(extension_handle)
+  _AttachFieldHelpers(cls, extension_handle)
+
+

Instance variables

var altitude
-

Field Position.altitude

+

Getter for altitude.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var battery_level
-

Field Position.battery_level

+

Getter for battery_level.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var latitude_i
-

Field Position.latitude_i

+

Getter for latitude_i.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var longitude_i
-

Field Position.longitude_i

+

Getter for longitude_i.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var time
-

Field Position.time

+

Getter for time.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
+
+
+

Methods

+
+
+def ByteSize(self) +
+
+
+
+ +Expand source code + +
def ByteSize(self):
+  if not self._cached_byte_size_dirty:
+    return self._cached_byte_size
+
+  size = 0
+  descriptor = self.DESCRIPTOR
+  if descriptor.GetOptions().map_entry:
+    # Fields of map entry should always be serialized.
+    size = descriptor.fields_by_name['key']._sizer(self.key)
+    size += descriptor.fields_by_name['value']._sizer(self.value)
+  else:
+    for field_descriptor, field_value in self.ListFields():
+      size += field_descriptor._sizer(field_value)
+    for tag_bytes, value_bytes in self._unknown_fields:
+      size += len(tag_bytes) + len(value_bytes)
+
+  self._cached_byte_size = size
+  self._cached_byte_size_dirty = False
+  self._listener_for_children.dirty = False
+  return size
+
+
+
+def Clear(self) +
+
+
+
+ +Expand source code + +
def _Clear(self):
+  # Clear fields.
+  self._fields = {}
+  self._unknown_fields = ()
+  # pylint: disable=protected-access
+  if self._unknown_field_set is not None:
+    self._unknown_field_set._clear()
+    self._unknown_field_set = None
+
+  self._oneofs = {}
+  self._Modified()
+
+
+
+def ClearField(self, field_name) +
+
+
+
+ +Expand source code + +
def ClearField(self, field_name):
+  try:
+    field = message_descriptor.fields_by_name[field_name]
+  except KeyError:
+    try:
+      field = message_descriptor.oneofs_by_name[field_name]
+      if field in self._oneofs:
+        field = self._oneofs[field]
+      else:
+        return
+    except KeyError:
+      raise ValueError('Protocol message %s has no "%s" field.' %
+                       (message_descriptor.name, field_name))
+
+  if field in self._fields:
+    # To match the C++ implementation, we need to invalidate iterators
+    # for map fields when ClearField() happens.
+    if hasattr(self._fields[field], 'InvalidateIterators'):
+      self._fields[field].InvalidateIterators()
+
+    # Note:  If the field is a sub-message, its listener will still point
+    #   at us.  That's fine, because the worst than can happen is that it
+    #   will call _Modified() and invalidate our byte size.  Big deal.
+    del self._fields[field]
+
+    if self._oneofs.get(field.containing_oneof, None) is field:
+      del self._oneofs[field.containing_oneof]
+
+  # Always call _Modified() -- even if nothing was changed, this is
+  # a mutating method, and thus calling it should cause the field to become
+  # present in the parent message.
+  self._Modified()
+
+
+
+def DiscardUnknownFields(self) +
+
+
+
+ +Expand source code + +
def _DiscardUnknownFields(self):
+  self._unknown_fields = []
+  self._unknown_field_set = None      # pylint: disable=protected-access
+  for field, value in self.ListFields():
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if _IsMapField(field):
+        if _IsMessageMapField(field):
+          for key in value:
+            value[key].DiscardUnknownFields()
+      elif field.label == _FieldDescriptor.LABEL_REPEATED:
+        for sub_message in value:
+          sub_message.DiscardUnknownFields()
+      else:
+        value.DiscardUnknownFields()
+
+
+
+def FindInitializationErrors(self) +
+
+

Finds required fields which are not initialized.

+

Returns

+

A list of strings. +Each string is a path to an uninitialized field from +the top-level message, e.g. "foo.bar[5].baz".

+
+ +Expand source code + +
def FindInitializationErrors(self):
+  """Finds required fields which are not initialized.
+
+  Returns:
+    A list of strings.  Each string is a path to an uninitialized field from
+    the top-level message, e.g. "foo.bar[5].baz".
+  """
+
+  errors = []  # simplify things
+
+  for field in required_fields:
+    if not self.HasField(field.name):
+      errors.append(field.name)
+
+  for field, value in self.ListFields():
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if field.is_extension:
+        name = '(%s)' % field.full_name
+      else:
+        name = field.name
+
+      if _IsMapField(field):
+        if _IsMessageMapField(field):
+          for key in value:
+            element = value[key]
+            prefix = '%s[%s].' % (name, key)
+            sub_errors = element.FindInitializationErrors()
+            errors += [prefix + error for error in sub_errors]
+        else:
+          # ScalarMaps can't have any initialization errors.
+          pass
+      elif field.label == _FieldDescriptor.LABEL_REPEATED:
+        for i in range(len(value)):
+          element = value[i]
+          prefix = '%s[%d].' % (name, i)
+          sub_errors = element.FindInitializationErrors()
+          errors += [prefix + error for error in sub_errors]
+      else:
+        prefix = name + '.'
+        sub_errors = value.FindInitializationErrors()
+        errors += [prefix + error for error in sub_errors]
+
+  return errors
+
+
+
+def HasField(self, field_name) +
+
+
+
+ +Expand source code + +
def HasField(self, field_name):
+  try:
+    field = hassable_fields[field_name]
+  except KeyError:
+    raise ValueError(error_msg % (message_descriptor.full_name, field_name))
+
+  if isinstance(field, descriptor_mod.OneofDescriptor):
+    try:
+      return HasField(self, self._oneofs[field].name)
+    except KeyError:
+      return False
+  else:
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      value = self._fields.get(field)
+      return value is not None and value._is_present_in_parent
+    else:
+      return field in self._fields
+
+
+
+def IsInitialized(self, errors=None) +
+
+

Checks if all required fields of a message are set.

+

Args

+
+
errors
+
A list which, if provided, will be populated with the field +paths of all missing required fields.
+
+

Returns

+

True iff the specified message has all required fields set.

+
+ +Expand source code + +
def IsInitialized(self, errors=None):
+  """Checks if all required fields of a message are set.
+
+  Args:
+    errors:  A list which, if provided, will be populated with the field
+             paths of all missing required fields.
+
+  Returns:
+    True iff the specified message has all required fields set.
+  """
+
+  # Performance is critical so we avoid HasField() and ListFields().
+
+  for field in required_fields:
+    if (field not in self._fields or
+        (field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE and
+         not self._fields[field]._is_present_in_parent)):
+      if errors is not None:
+        errors.extend(self.FindInitializationErrors())
+      return False
+
+  for field, value in list(self._fields.items()):  # dict can change size!
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if field.label == _FieldDescriptor.LABEL_REPEATED:
+        if (field.message_type.has_options and
+            field.message_type.GetOptions().map_entry):
+          continue
+        for element in value:
+          if not element.IsInitialized():
+            if errors is not None:
+              errors.extend(self.FindInitializationErrors())
+            return False
+      elif value._is_present_in_parent and not value.IsInitialized():
+        if errors is not None:
+          errors.extend(self.FindInitializationErrors())
+        return False
+
+  return True
+
+
+
+def ListFields(self) +
+
+
+
+ +Expand source code + +
def ListFields(self):
+  all_fields = [item for item in self._fields.items() if _IsPresent(item)]
+  all_fields.sort(key = lambda item: item[0].number)
+  return all_fields
+
+
+
+def MergeFrom(self, msg) +
+
+
+
+ +Expand source code + +
def MergeFrom(self, msg):
+  if not isinstance(msg, cls):
+    raise TypeError(
+        'Parameter to MergeFrom() must be instance of same class: '
+        'expected %s got %s.' % (cls.__name__, msg.__class__.__name__))
+
+  assert msg is not self
+  self._Modified()
+
+  fields = self._fields
+
+  for field, value in msg._fields.items():
+    if field.label == LABEL_REPEATED:
+      field_value = fields.get(field)
+      if field_value is None:
+        # Construct a new object to represent this field.
+        field_value = field._default_constructor(self)
+        fields[field] = field_value
+      field_value.MergeFrom(value)
+    elif field.cpp_type == CPPTYPE_MESSAGE:
+      if value._is_present_in_parent:
+        field_value = fields.get(field)
+        if field_value is None:
+          # Construct a new object to represent this field.
+          field_value = field._default_constructor(self)
+          fields[field] = field_value
+        field_value.MergeFrom(value)
+    else:
+      self._fields[field] = value
+      if field.containing_oneof:
+        self._UpdateOneofState(field)
+
+  if msg._unknown_fields:
+    if not self._unknown_fields:
+      self._unknown_fields = []
+    self._unknown_fields.extend(msg._unknown_fields)
+    # pylint: disable=protected-access
+    if self._unknown_field_set is None:
+      self._unknown_field_set = containers.UnknownFieldSet()
+    self._unknown_field_set._extend(msg._unknown_field_set)
+
+
+
+def MergeFromString(self, serialized) +
+
+
+
+ +Expand source code + +
def MergeFromString(self, serialized):
+  if isinstance(serialized, memoryview) and six.PY2:
+    raise TypeError(
+        'memoryview not supported in Python 2 with the pure Python proto '
+        'implementation: this is to maintain compatibility with the C++ '
+        'implementation')
+
+  serialized = memoryview(serialized)
+  length = len(serialized)
+  try:
+    if self._InternalParse(serialized, 0, length) != length:
+      # The only reason _InternalParse would return early is if it
+      # encountered an end-group tag.
+      raise message_mod.DecodeError('Unexpected end-group tag.')
+  except (IndexError, TypeError):
+    # Now ord(buf[p:p+1]) == ord('') gets TypeError.
+    raise message_mod.DecodeError('Truncated message.')
+  except struct.error as e:
+    raise message_mod.DecodeError(e)
+  return length   # Return this for legacy reasons.
+
+
+
+def SerializePartialToString(self, **kwargs) +
+
+
+
+ +Expand source code + +
def SerializePartialToString(self, **kwargs):
+  out = BytesIO()
+  self._InternalSerialize(out.write, **kwargs)
+  return out.getvalue()
+
+
+
+def SerializeToString(self, **kwargs) +
+
+
+
+ +Expand source code + +
def SerializeToString(self, **kwargs):
+  # Check if the message has all of its required fields set.
+  if not self.IsInitialized():
+    raise message_mod.EncodeError(
+        'Message %s is missing required fields: %s' % (
+        self.DESCRIPTOR.full_name, ','.join(self.FindInitializationErrors())))
+  return self.SerializePartialToString(**kwargs)
+
+
+
+def SetInParent(self) +
+
+

Sets the _cached_byte_size_dirty bit to true, +and propagates this to our listener iff this was a state change.

+
+ +Expand source code + +
def Modified(self):
+  """Sets the _cached_byte_size_dirty bit to true,
+  and propagates this to our listener iff this was a state change.
+  """
+
+  # Note:  Some callers check _cached_byte_size_dirty before calling
+  #   _Modified() as an extra optimization.  So, if this method is ever
+  #   changed such that it does stuff even when _cached_byte_size_dirty is
+  #   already true, the callers need to be updated.
+  if not self._cached_byte_size_dirty:
+    self._cached_byte_size_dirty = True
+    self._listener_for_children.dirty = True
+    self._is_present_in_parent = True
+    self._listener.Modified()
+
+
+
+def UnknownFields(self) +
+
+
+
+ +Expand source code + +
def _UnknownFields(self):
+  if self._unknown_field_set is None:  # pylint: disable=protected-access
+    # pylint: disable=protected-access
+    self._unknown_field_set = containers.UnknownFieldSet()
+  return self._unknown_field_set    # pylint: disable=protected-access
+
+
+
+def WhichOneof(self, oneof_name) +
+
+

Returns the name of the currently set field inside a oneof, or None.

+
+ +Expand source code + +
def WhichOneof(self, oneof_name):
+  """Returns the name of the currently set field inside a oneof, or None."""
+  try:
+    field = message_descriptor.oneofs_by_name[oneof_name]
+  except KeyError:
+    raise ValueError(
+        'Protocol message has no oneof "%s" field.' % oneof_name)
+
+  nested_field = self._oneofs.get(field, None)
+  if nested_field is not None and self.HasField(nested_field.name):
+    return nested_field.name
+  else:
+    return None
+
class RadioConfig -(*args, **kwargs) +(**kwargs)
-

A ProtocolMessage

+

Abstract base class for protocol messages.

+

Protocol message classes are almost always generated by the protocol +compiler. +These generated types subclass Message and implement the methods +shown below.

Ancestors

Class variables

+
var CHANNEL_SETTINGS_FIELD_NUMBER
+
+
+
var DESCRIPTOR
+
var PREFERENCES_FIELD_NUMBER
+
+
+
var UserPreferences
-

A ProtocolMessage

+

Abstract base class for protocol messages.

+

Protocol message classes are almost always generated by the protocol +compiler. +These generated types subclass Message and implement the methods +shown below.

+
+
+

Static methods

+
+
+def FromString(s) +
+
+
+
+ +Expand source code + +
def FromString(s):
+  message = cls()
+  message.MergeFromString(s)
+  return message
+
+
+
+def RegisterExtension(extension_handle) +
+
+
+
+ +Expand source code + +
def RegisterExtension(extension_handle):
+  extension_handle.containing_type = cls.DESCRIPTOR
+  # TODO(amauryfa): Use cls.MESSAGE_FACTORY.pool when available.
+  # pylint: disable=protected-access
+  cls.DESCRIPTOR.file.pool._AddExtensionDescriptor(extension_handle)
+  _AttachFieldHelpers(cls, extension_handle)
+

Instance variables

var channel_settings
-

Field RadioConfig.channel_settings

+

Getter for channel_settings.

+
+ +Expand source code + +
def getter(self):
+  field_value = self._fields.get(field)
+  if field_value is None:
+    # Construct a new object to represent this field.
+    field_value = field._default_constructor(self)
+
+    # Atomically check if another thread has preempted us and, if not, swap
+    # in the new object we just created.  If someone has preempted us, we
+    # take that object and discard ours.
+    # WARNING:  We are relying on setdefault() being atomic.  This is true
+    #   in CPython but we haven't investigated others.  This warning appears
+    #   in several other locations in this file.
+    field_value = self._fields.setdefault(field, field_value)
+  return field_value
+
var preferences
-

Field RadioConfig.preferences

+

Getter for preferences.

+
+ +Expand source code + +
def getter(self):
+  field_value = self._fields.get(field)
+  if field_value is None:
+    # Construct a new object to represent this field.
+    field_value = field._default_constructor(self)
+
+    # Atomically check if another thread has preempted us and, if not, swap
+    # in the new object we just created.  If someone has preempted us, we
+    # take that object and discard ours.
+    # WARNING:  We are relying on setdefault() being atomic.  This is true
+    #   in CPython but we haven't investigated others.  This warning appears
+    #   in several other locations in this file.
+    field_value = self._fields.setdefault(field, field_value)
+  return field_value
+
+
+
+

Methods

+
+
+def ByteSize(self) +
+
+
+
+ +Expand source code + +
def ByteSize(self):
+  if not self._cached_byte_size_dirty:
+    return self._cached_byte_size
+
+  size = 0
+  descriptor = self.DESCRIPTOR
+  if descriptor.GetOptions().map_entry:
+    # Fields of map entry should always be serialized.
+    size = descriptor.fields_by_name['key']._sizer(self.key)
+    size += descriptor.fields_by_name['value']._sizer(self.value)
+  else:
+    for field_descriptor, field_value in self.ListFields():
+      size += field_descriptor._sizer(field_value)
+    for tag_bytes, value_bytes in self._unknown_fields:
+      size += len(tag_bytes) + len(value_bytes)
+
+  self._cached_byte_size = size
+  self._cached_byte_size_dirty = False
+  self._listener_for_children.dirty = False
+  return size
+
+
+
+def Clear(self) +
+
+
+
+ +Expand source code + +
def _Clear(self):
+  # Clear fields.
+  self._fields = {}
+  self._unknown_fields = ()
+  # pylint: disable=protected-access
+  if self._unknown_field_set is not None:
+    self._unknown_field_set._clear()
+    self._unknown_field_set = None
+
+  self._oneofs = {}
+  self._Modified()
+
+
+
+def ClearField(self, field_name) +
+
+
+
+ +Expand source code + +
def ClearField(self, field_name):
+  try:
+    field = message_descriptor.fields_by_name[field_name]
+  except KeyError:
+    try:
+      field = message_descriptor.oneofs_by_name[field_name]
+      if field in self._oneofs:
+        field = self._oneofs[field]
+      else:
+        return
+    except KeyError:
+      raise ValueError('Protocol message %s has no "%s" field.' %
+                       (message_descriptor.name, field_name))
+
+  if field in self._fields:
+    # To match the C++ implementation, we need to invalidate iterators
+    # for map fields when ClearField() happens.
+    if hasattr(self._fields[field], 'InvalidateIterators'):
+      self._fields[field].InvalidateIterators()
+
+    # Note:  If the field is a sub-message, its listener will still point
+    #   at us.  That's fine, because the worst than can happen is that it
+    #   will call _Modified() and invalidate our byte size.  Big deal.
+    del self._fields[field]
+
+    if self._oneofs.get(field.containing_oneof, None) is field:
+      del self._oneofs[field.containing_oneof]
+
+  # Always call _Modified() -- even if nothing was changed, this is
+  # a mutating method, and thus calling it should cause the field to become
+  # present in the parent message.
+  self._Modified()
+
+
+
+def DiscardUnknownFields(self) +
+
+
+
+ +Expand source code + +
def _DiscardUnknownFields(self):
+  self._unknown_fields = []
+  self._unknown_field_set = None      # pylint: disable=protected-access
+  for field, value in self.ListFields():
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if _IsMapField(field):
+        if _IsMessageMapField(field):
+          for key in value:
+            value[key].DiscardUnknownFields()
+      elif field.label == _FieldDescriptor.LABEL_REPEATED:
+        for sub_message in value:
+          sub_message.DiscardUnknownFields()
+      else:
+        value.DiscardUnknownFields()
+
+
+
+def FindInitializationErrors(self) +
+
+

Finds required fields which are not initialized.

+

Returns

+

A list of strings. +Each string is a path to an uninitialized field from +the top-level message, e.g. "foo.bar[5].baz".

+
+ +Expand source code + +
def FindInitializationErrors(self):
+  """Finds required fields which are not initialized.
+
+  Returns:
+    A list of strings.  Each string is a path to an uninitialized field from
+    the top-level message, e.g. "foo.bar[5].baz".
+  """
+
+  errors = []  # simplify things
+
+  for field in required_fields:
+    if not self.HasField(field.name):
+      errors.append(field.name)
+
+  for field, value in self.ListFields():
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if field.is_extension:
+        name = '(%s)' % field.full_name
+      else:
+        name = field.name
+
+      if _IsMapField(field):
+        if _IsMessageMapField(field):
+          for key in value:
+            element = value[key]
+            prefix = '%s[%s].' % (name, key)
+            sub_errors = element.FindInitializationErrors()
+            errors += [prefix + error for error in sub_errors]
+        else:
+          # ScalarMaps can't have any initialization errors.
+          pass
+      elif field.label == _FieldDescriptor.LABEL_REPEATED:
+        for i in range(len(value)):
+          element = value[i]
+          prefix = '%s[%d].' % (name, i)
+          sub_errors = element.FindInitializationErrors()
+          errors += [prefix + error for error in sub_errors]
+      else:
+        prefix = name + '.'
+        sub_errors = value.FindInitializationErrors()
+        errors += [prefix + error for error in sub_errors]
+
+  return errors
+
+
+
+def HasField(self, field_name) +
+
+
+
+ +Expand source code + +
def HasField(self, field_name):
+  try:
+    field = hassable_fields[field_name]
+  except KeyError:
+    raise ValueError(error_msg % (message_descriptor.full_name, field_name))
+
+  if isinstance(field, descriptor_mod.OneofDescriptor):
+    try:
+      return HasField(self, self._oneofs[field].name)
+    except KeyError:
+      return False
+  else:
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      value = self._fields.get(field)
+      return value is not None and value._is_present_in_parent
+    else:
+      return field in self._fields
+
+
+
+def IsInitialized(self, errors=None) +
+
+

Checks if all required fields of a message are set.

+

Args

+
+
errors
+
A list which, if provided, will be populated with the field +paths of all missing required fields.
+
+

Returns

+

True iff the specified message has all required fields set.

+
+ +Expand source code + +
def IsInitialized(self, errors=None):
+  """Checks if all required fields of a message are set.
+
+  Args:
+    errors:  A list which, if provided, will be populated with the field
+             paths of all missing required fields.
+
+  Returns:
+    True iff the specified message has all required fields set.
+  """
+
+  # Performance is critical so we avoid HasField() and ListFields().
+
+  for field in required_fields:
+    if (field not in self._fields or
+        (field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE and
+         not self._fields[field]._is_present_in_parent)):
+      if errors is not None:
+        errors.extend(self.FindInitializationErrors())
+      return False
+
+  for field, value in list(self._fields.items()):  # dict can change size!
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if field.label == _FieldDescriptor.LABEL_REPEATED:
+        if (field.message_type.has_options and
+            field.message_type.GetOptions().map_entry):
+          continue
+        for element in value:
+          if not element.IsInitialized():
+            if errors is not None:
+              errors.extend(self.FindInitializationErrors())
+            return False
+      elif value._is_present_in_parent and not value.IsInitialized():
+        if errors is not None:
+          errors.extend(self.FindInitializationErrors())
+        return False
+
+  return True
+
+
+
+def ListFields(self) +
+
+
+
+ +Expand source code + +
def ListFields(self):
+  all_fields = [item for item in self._fields.items() if _IsPresent(item)]
+  all_fields.sort(key = lambda item: item[0].number)
+  return all_fields
+
+
+
+def MergeFrom(self, msg) +
+
+
+
+ +Expand source code + +
def MergeFrom(self, msg):
+  if not isinstance(msg, cls):
+    raise TypeError(
+        'Parameter to MergeFrom() must be instance of same class: '
+        'expected %s got %s.' % (cls.__name__, msg.__class__.__name__))
+
+  assert msg is not self
+  self._Modified()
+
+  fields = self._fields
+
+  for field, value in msg._fields.items():
+    if field.label == LABEL_REPEATED:
+      field_value = fields.get(field)
+      if field_value is None:
+        # Construct a new object to represent this field.
+        field_value = field._default_constructor(self)
+        fields[field] = field_value
+      field_value.MergeFrom(value)
+    elif field.cpp_type == CPPTYPE_MESSAGE:
+      if value._is_present_in_parent:
+        field_value = fields.get(field)
+        if field_value is None:
+          # Construct a new object to represent this field.
+          field_value = field._default_constructor(self)
+          fields[field] = field_value
+        field_value.MergeFrom(value)
+    else:
+      self._fields[field] = value
+      if field.containing_oneof:
+        self._UpdateOneofState(field)
+
+  if msg._unknown_fields:
+    if not self._unknown_fields:
+      self._unknown_fields = []
+    self._unknown_fields.extend(msg._unknown_fields)
+    # pylint: disable=protected-access
+    if self._unknown_field_set is None:
+      self._unknown_field_set = containers.UnknownFieldSet()
+    self._unknown_field_set._extend(msg._unknown_field_set)
+
+
+
+def MergeFromString(self, serialized) +
+
+
+
+ +Expand source code + +
def MergeFromString(self, serialized):
+  if isinstance(serialized, memoryview) and six.PY2:
+    raise TypeError(
+        'memoryview not supported in Python 2 with the pure Python proto '
+        'implementation: this is to maintain compatibility with the C++ '
+        'implementation')
+
+  serialized = memoryview(serialized)
+  length = len(serialized)
+  try:
+    if self._InternalParse(serialized, 0, length) != length:
+      # The only reason _InternalParse would return early is if it
+      # encountered an end-group tag.
+      raise message_mod.DecodeError('Unexpected end-group tag.')
+  except (IndexError, TypeError):
+    # Now ord(buf[p:p+1]) == ord('') gets TypeError.
+    raise message_mod.DecodeError('Truncated message.')
+  except struct.error as e:
+    raise message_mod.DecodeError(e)
+  return length   # Return this for legacy reasons.
+
+
+
+def SerializePartialToString(self, **kwargs) +
+
+
+
+ +Expand source code + +
def SerializePartialToString(self, **kwargs):
+  out = BytesIO()
+  self._InternalSerialize(out.write, **kwargs)
+  return out.getvalue()
+
+
+
+def SerializeToString(self, **kwargs) +
+
+
+
+ +Expand source code + +
def SerializeToString(self, **kwargs):
+  # Check if the message has all of its required fields set.
+  if not self.IsInitialized():
+    raise message_mod.EncodeError(
+        'Message %s is missing required fields: %s' % (
+        self.DESCRIPTOR.full_name, ','.join(self.FindInitializationErrors())))
+  return self.SerializePartialToString(**kwargs)
+
+
+
+def SetInParent(self) +
+
+

Sets the _cached_byte_size_dirty bit to true, +and propagates this to our listener iff this was a state change.

+
+ +Expand source code + +
def Modified(self):
+  """Sets the _cached_byte_size_dirty bit to true,
+  and propagates this to our listener iff this was a state change.
+  """
+
+  # Note:  Some callers check _cached_byte_size_dirty before calling
+  #   _Modified() as an extra optimization.  So, if this method is ever
+  #   changed such that it does stuff even when _cached_byte_size_dirty is
+  #   already true, the callers need to be updated.
+  if not self._cached_byte_size_dirty:
+    self._cached_byte_size_dirty = True
+    self._listener_for_children.dirty = True
+    self._is_present_in_parent = True
+    self._listener.Modified()
+
+
+
+def UnknownFields(self) +
+
+
+
+ +Expand source code + +
def _UnknownFields(self):
+  if self._unknown_field_set is None:  # pylint: disable=protected-access
+    # pylint: disable=protected-access
+    self._unknown_field_set = containers.UnknownFieldSet()
+  return self._unknown_field_set    # pylint: disable=protected-access
+
+
+
+def WhichOneof(self, oneof_name) +
+
+

Returns the name of the currently set field inside a oneof, or None.

+
+ +Expand source code + +
def WhichOneof(self, oneof_name):
+  """Returns the name of the currently set field inside a oneof, or None."""
+  try:
+    field = message_descriptor.oneofs_by_name[oneof_name]
+  except KeyError:
+    raise ValueError(
+        'Protocol message has no oneof "%s" field.' % oneof_name)
+
+  nested_field = self._oneofs.get(field, None)
+  if nested_field is not None and self.HasField(nested_field.name):
+    return nested_field.name
+  else:
+    return None
+
class RouteDiscovery -(*args, **kwargs) +(**kwargs)
-

A ProtocolMessage

+

Abstract base class for protocol messages.

+

Protocol message classes are almost always generated by the protocol +compiler. +These generated types subclass Message and implement the methods +shown below.

Ancestors

Class variables

@@ -2340,94 +8889,1325 @@ DESCRIPTOR._options = None
+
var ROUTE_FIELD_NUMBER
+
+
+
+ +

Static methods

+
+
+def FromString(s) +
+
+
+
+ +Expand source code + +
def FromString(s):
+  message = cls()
+  message.MergeFromString(s)
+  return message
+
+
+
+def RegisterExtension(extension_handle) +
+
+
+
+ +Expand source code + +
def RegisterExtension(extension_handle):
+  extension_handle.containing_type = cls.DESCRIPTOR
+  # TODO(amauryfa): Use cls.MESSAGE_FACTORY.pool when available.
+  # pylint: disable=protected-access
+  cls.DESCRIPTOR.file.pool._AddExtensionDescriptor(extension_handle)
+  _AttachFieldHelpers(cls, extension_handle)
+
+

Instance variables

var route
-

Field RouteDiscovery.route

+

Getter for route.

+
+ +Expand source code + +
def getter(self):
+  field_value = self._fields.get(field)
+  if field_value is None:
+    # Construct a new object to represent this field.
+    field_value = field._default_constructor(self)
+
+    # Atomically check if another thread has preempted us and, if not, swap
+    # in the new object we just created.  If someone has preempted us, we
+    # take that object and discard ours.
+    # WARNING:  We are relying on setdefault() being atomic.  This is true
+    #   in CPython but we haven't investigated others.  This warning appears
+    #   in several other locations in this file.
+    field_value = self._fields.setdefault(field, field_value)
+  return field_value
+
+
+
+

Methods

+
+
+def ByteSize(self) +
+
+
+
+ +Expand source code + +
def ByteSize(self):
+  if not self._cached_byte_size_dirty:
+    return self._cached_byte_size
+
+  size = 0
+  descriptor = self.DESCRIPTOR
+  if descriptor.GetOptions().map_entry:
+    # Fields of map entry should always be serialized.
+    size = descriptor.fields_by_name['key']._sizer(self.key)
+    size += descriptor.fields_by_name['value']._sizer(self.value)
+  else:
+    for field_descriptor, field_value in self.ListFields():
+      size += field_descriptor._sizer(field_value)
+    for tag_bytes, value_bytes in self._unknown_fields:
+      size += len(tag_bytes) + len(value_bytes)
+
+  self._cached_byte_size = size
+  self._cached_byte_size_dirty = False
+  self._listener_for_children.dirty = False
+  return size
+
+
+
+def Clear(self) +
+
+
+
+ +Expand source code + +
def _Clear(self):
+  # Clear fields.
+  self._fields = {}
+  self._unknown_fields = ()
+  # pylint: disable=protected-access
+  if self._unknown_field_set is not None:
+    self._unknown_field_set._clear()
+    self._unknown_field_set = None
+
+  self._oneofs = {}
+  self._Modified()
+
+
+
+def ClearField(self, field_name) +
+
+
+
+ +Expand source code + +
def ClearField(self, field_name):
+  try:
+    field = message_descriptor.fields_by_name[field_name]
+  except KeyError:
+    try:
+      field = message_descriptor.oneofs_by_name[field_name]
+      if field in self._oneofs:
+        field = self._oneofs[field]
+      else:
+        return
+    except KeyError:
+      raise ValueError('Protocol message %s has no "%s" field.' %
+                       (message_descriptor.name, field_name))
+
+  if field in self._fields:
+    # To match the C++ implementation, we need to invalidate iterators
+    # for map fields when ClearField() happens.
+    if hasattr(self._fields[field], 'InvalidateIterators'):
+      self._fields[field].InvalidateIterators()
+
+    # Note:  If the field is a sub-message, its listener will still point
+    #   at us.  That's fine, because the worst than can happen is that it
+    #   will call _Modified() and invalidate our byte size.  Big deal.
+    del self._fields[field]
+
+    if self._oneofs.get(field.containing_oneof, None) is field:
+      del self._oneofs[field.containing_oneof]
+
+  # Always call _Modified() -- even if nothing was changed, this is
+  # a mutating method, and thus calling it should cause the field to become
+  # present in the parent message.
+  self._Modified()
+
+
+
+def DiscardUnknownFields(self) +
+
+
+
+ +Expand source code + +
def _DiscardUnknownFields(self):
+  self._unknown_fields = []
+  self._unknown_field_set = None      # pylint: disable=protected-access
+  for field, value in self.ListFields():
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if _IsMapField(field):
+        if _IsMessageMapField(field):
+          for key in value:
+            value[key].DiscardUnknownFields()
+      elif field.label == _FieldDescriptor.LABEL_REPEATED:
+        for sub_message in value:
+          sub_message.DiscardUnknownFields()
+      else:
+        value.DiscardUnknownFields()
+
+
+
+def FindInitializationErrors(self) +
+
+

Finds required fields which are not initialized.

+

Returns

+

A list of strings. +Each string is a path to an uninitialized field from +the top-level message, e.g. "foo.bar[5].baz".

+
+ +Expand source code + +
def FindInitializationErrors(self):
+  """Finds required fields which are not initialized.
+
+  Returns:
+    A list of strings.  Each string is a path to an uninitialized field from
+    the top-level message, e.g. "foo.bar[5].baz".
+  """
+
+  errors = []  # simplify things
+
+  for field in required_fields:
+    if not self.HasField(field.name):
+      errors.append(field.name)
+
+  for field, value in self.ListFields():
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if field.is_extension:
+        name = '(%s)' % field.full_name
+      else:
+        name = field.name
+
+      if _IsMapField(field):
+        if _IsMessageMapField(field):
+          for key in value:
+            element = value[key]
+            prefix = '%s[%s].' % (name, key)
+            sub_errors = element.FindInitializationErrors()
+            errors += [prefix + error for error in sub_errors]
+        else:
+          # ScalarMaps can't have any initialization errors.
+          pass
+      elif field.label == _FieldDescriptor.LABEL_REPEATED:
+        for i in range(len(value)):
+          element = value[i]
+          prefix = '%s[%d].' % (name, i)
+          sub_errors = element.FindInitializationErrors()
+          errors += [prefix + error for error in sub_errors]
+      else:
+        prefix = name + '.'
+        sub_errors = value.FindInitializationErrors()
+        errors += [prefix + error for error in sub_errors]
+
+  return errors
+
+
+
+def HasField(self, field_name) +
+
+
+
+ +Expand source code + +
def HasField(self, field_name):
+  try:
+    field = hassable_fields[field_name]
+  except KeyError:
+    raise ValueError(error_msg % (message_descriptor.full_name, field_name))
+
+  if isinstance(field, descriptor_mod.OneofDescriptor):
+    try:
+      return HasField(self, self._oneofs[field].name)
+    except KeyError:
+      return False
+  else:
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      value = self._fields.get(field)
+      return value is not None and value._is_present_in_parent
+    else:
+      return field in self._fields
+
+
+
+def IsInitialized(self, errors=None) +
+
+

Checks if all required fields of a message are set.

+

Args

+
+
errors
+
A list which, if provided, will be populated with the field +paths of all missing required fields.
+
+

Returns

+

True iff the specified message has all required fields set.

+
+ +Expand source code + +
def IsInitialized(self, errors=None):
+  """Checks if all required fields of a message are set.
+
+  Args:
+    errors:  A list which, if provided, will be populated with the field
+             paths of all missing required fields.
+
+  Returns:
+    True iff the specified message has all required fields set.
+  """
+
+  # Performance is critical so we avoid HasField() and ListFields().
+
+  for field in required_fields:
+    if (field not in self._fields or
+        (field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE and
+         not self._fields[field]._is_present_in_parent)):
+      if errors is not None:
+        errors.extend(self.FindInitializationErrors())
+      return False
+
+  for field, value in list(self._fields.items()):  # dict can change size!
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if field.label == _FieldDescriptor.LABEL_REPEATED:
+        if (field.message_type.has_options and
+            field.message_type.GetOptions().map_entry):
+          continue
+        for element in value:
+          if not element.IsInitialized():
+            if errors is not None:
+              errors.extend(self.FindInitializationErrors())
+            return False
+      elif value._is_present_in_parent and not value.IsInitialized():
+        if errors is not None:
+          errors.extend(self.FindInitializationErrors())
+        return False
+
+  return True
+
+
+
+def ListFields(self) +
+
+
+
+ +Expand source code + +
def ListFields(self):
+  all_fields = [item for item in self._fields.items() if _IsPresent(item)]
+  all_fields.sort(key = lambda item: item[0].number)
+  return all_fields
+
+
+
+def MergeFrom(self, msg) +
+
+
+
+ +Expand source code + +
def MergeFrom(self, msg):
+  if not isinstance(msg, cls):
+    raise TypeError(
+        'Parameter to MergeFrom() must be instance of same class: '
+        'expected %s got %s.' % (cls.__name__, msg.__class__.__name__))
+
+  assert msg is not self
+  self._Modified()
+
+  fields = self._fields
+
+  for field, value in msg._fields.items():
+    if field.label == LABEL_REPEATED:
+      field_value = fields.get(field)
+      if field_value is None:
+        # Construct a new object to represent this field.
+        field_value = field._default_constructor(self)
+        fields[field] = field_value
+      field_value.MergeFrom(value)
+    elif field.cpp_type == CPPTYPE_MESSAGE:
+      if value._is_present_in_parent:
+        field_value = fields.get(field)
+        if field_value is None:
+          # Construct a new object to represent this field.
+          field_value = field._default_constructor(self)
+          fields[field] = field_value
+        field_value.MergeFrom(value)
+    else:
+      self._fields[field] = value
+      if field.containing_oneof:
+        self._UpdateOneofState(field)
+
+  if msg._unknown_fields:
+    if not self._unknown_fields:
+      self._unknown_fields = []
+    self._unknown_fields.extend(msg._unknown_fields)
+    # pylint: disable=protected-access
+    if self._unknown_field_set is None:
+      self._unknown_field_set = containers.UnknownFieldSet()
+    self._unknown_field_set._extend(msg._unknown_field_set)
+
+
+
+def MergeFromString(self, serialized) +
+
+
+
+ +Expand source code + +
def MergeFromString(self, serialized):
+  if isinstance(serialized, memoryview) and six.PY2:
+    raise TypeError(
+        'memoryview not supported in Python 2 with the pure Python proto '
+        'implementation: this is to maintain compatibility with the C++ '
+        'implementation')
+
+  serialized = memoryview(serialized)
+  length = len(serialized)
+  try:
+    if self._InternalParse(serialized, 0, length) != length:
+      # The only reason _InternalParse would return early is if it
+      # encountered an end-group tag.
+      raise message_mod.DecodeError('Unexpected end-group tag.')
+  except (IndexError, TypeError):
+    # Now ord(buf[p:p+1]) == ord('') gets TypeError.
+    raise message_mod.DecodeError('Truncated message.')
+  except struct.error as e:
+    raise message_mod.DecodeError(e)
+  return length   # Return this for legacy reasons.
+
+
+
+def SerializePartialToString(self, **kwargs) +
+
+
+
+ +Expand source code + +
def SerializePartialToString(self, **kwargs):
+  out = BytesIO()
+  self._InternalSerialize(out.write, **kwargs)
+  return out.getvalue()
+
+
+
+def SerializeToString(self, **kwargs) +
+
+
+
+ +Expand source code + +
def SerializeToString(self, **kwargs):
+  # Check if the message has all of its required fields set.
+  if not self.IsInitialized():
+    raise message_mod.EncodeError(
+        'Message %s is missing required fields: %s' % (
+        self.DESCRIPTOR.full_name, ','.join(self.FindInitializationErrors())))
+  return self.SerializePartialToString(**kwargs)
+
+
+
+def SetInParent(self) +
+
+

Sets the _cached_byte_size_dirty bit to true, +and propagates this to our listener iff this was a state change.

+
+ +Expand source code + +
def Modified(self):
+  """Sets the _cached_byte_size_dirty bit to true,
+  and propagates this to our listener iff this was a state change.
+  """
+
+  # Note:  Some callers check _cached_byte_size_dirty before calling
+  #   _Modified() as an extra optimization.  So, if this method is ever
+  #   changed such that it does stuff even when _cached_byte_size_dirty is
+  #   already true, the callers need to be updated.
+  if not self._cached_byte_size_dirty:
+    self._cached_byte_size_dirty = True
+    self._listener_for_children.dirty = True
+    self._is_present_in_parent = True
+    self._listener.Modified()
+
+
+
+def UnknownFields(self) +
+
+
+
+ +Expand source code + +
def _UnknownFields(self):
+  if self._unknown_field_set is None:  # pylint: disable=protected-access
+    # pylint: disable=protected-access
+    self._unknown_field_set = containers.UnknownFieldSet()
+  return self._unknown_field_set    # pylint: disable=protected-access
+
+
+
+def WhichOneof(self, oneof_name) +
+
+

Returns the name of the currently set field inside a oneof, or None.

+
+ +Expand source code + +
def WhichOneof(self, oneof_name):
+  """Returns the name of the currently set field inside a oneof, or None."""
+  try:
+    field = message_descriptor.oneofs_by_name[oneof_name]
+  except KeyError:
+    raise ValueError(
+        'Protocol message has no oneof "%s" field.' % oneof_name)
+
+  nested_field = self._oneofs.get(field, None)
+  if nested_field is not None and self.HasField(nested_field.name):
+    return nested_field.name
+  else:
+    return None
+
class SubPacket -(*args, **kwargs) +(**kwargs)
-

A ProtocolMessage

+

Abstract base class for protocol messages.

+

Protocol message classes are almost always generated by the protocol +compiler. +These generated types subclass Message and implement the methods +shown below.

Ancestors

Class variables

+
var DATA_FIELD_NUMBER
+
+
+
var DESCRIPTOR
+
var DEST_FIELD_NUMBER
+
+
+
+
var FAIL_ID_FIELD_NUMBER
+
+
+
+
var ORIGINAL_ID_FIELD_NUMBER
+
+
+
+
var POSITION_FIELD_NUMBER
+
+
+
+
var ROUTE_ERROR_FIELD_NUMBER
+
+
+
+
var ROUTE_REPLY_FIELD_NUMBER
+
+
+
+
var ROUTE_REQUEST_FIELD_NUMBER
+
+
+
+
var SOURCE_FIELD_NUMBER
+
+
+
+
var SUCCESS_ID_FIELD_NUMBER
+
+
+
+
var USER_FIELD_NUMBER
+
+
+
+
var WANT_RESPONSE_FIELD_NUMBER
+
+
+
+
+

Static methods

+
+
+def FromString(s) +
+
+
+
+ +Expand source code + +
def FromString(s):
+  message = cls()
+  message.MergeFromString(s)
+  return message
+
+
+
+def RegisterExtension(extension_handle) +
+
+
+
+ +Expand source code + +
def RegisterExtension(extension_handle):
+  extension_handle.containing_type = cls.DESCRIPTOR
+  # TODO(amauryfa): Use cls.MESSAGE_FACTORY.pool when available.
+  # pylint: disable=protected-access
+  cls.DESCRIPTOR.file.pool._AddExtensionDescriptor(extension_handle)
+  _AttachFieldHelpers(cls, extension_handle)
+
+

Instance variables

var data
-

Field SubPacket.data

+

Getter for data.

+
+ +Expand source code + +
def getter(self):
+  field_value = self._fields.get(field)
+  if field_value is None:
+    # Construct a new object to represent this field.
+    field_value = field._default_constructor(self)
+
+    # Atomically check if another thread has preempted us and, if not, swap
+    # in the new object we just created.  If someone has preempted us, we
+    # take that object and discard ours.
+    # WARNING:  We are relying on setdefault() being atomic.  This is true
+    #   in CPython but we haven't investigated others.  This warning appears
+    #   in several other locations in this file.
+    field_value = self._fields.setdefault(field, field_value)
+  return field_value
+
var dest
-

Field SubPacket.dest

+

Getter for dest.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var fail_id
-

Field SubPacket.fail_id

+

Getter for fail_id.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var original_id
-

Field SubPacket.original_id

+

Getter for original_id.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var position
-

Field SubPacket.position

+

Getter for position.

+
+ +Expand source code + +
def getter(self):
+  field_value = self._fields.get(field)
+  if field_value is None:
+    # Construct a new object to represent this field.
+    field_value = field._default_constructor(self)
+
+    # Atomically check if another thread has preempted us and, if not, swap
+    # in the new object we just created.  If someone has preempted us, we
+    # take that object and discard ours.
+    # WARNING:  We are relying on setdefault() being atomic.  This is true
+    #   in CPython but we haven't investigated others.  This warning appears
+    #   in several other locations in this file.
+    field_value = self._fields.setdefault(field, field_value)
+  return field_value
+
var route_error
-

Field SubPacket.route_error

+

Getter for route_error.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var route_reply
-

Field SubPacket.route_reply

+

Getter for route_reply.

+
+ +Expand source code + +
def getter(self):
+  field_value = self._fields.get(field)
+  if field_value is None:
+    # Construct a new object to represent this field.
+    field_value = field._default_constructor(self)
+
+    # Atomically check if another thread has preempted us and, if not, swap
+    # in the new object we just created.  If someone has preempted us, we
+    # take that object and discard ours.
+    # WARNING:  We are relying on setdefault() being atomic.  This is true
+    #   in CPython but we haven't investigated others.  This warning appears
+    #   in several other locations in this file.
+    field_value = self._fields.setdefault(field, field_value)
+  return field_value
+
var route_request
-

Field SubPacket.route_request

+

Getter for route_request.

+
+ +Expand source code + +
def getter(self):
+  field_value = self._fields.get(field)
+  if field_value is None:
+    # Construct a new object to represent this field.
+    field_value = field._default_constructor(self)
+
+    # Atomically check if another thread has preempted us and, if not, swap
+    # in the new object we just created.  If someone has preempted us, we
+    # take that object and discard ours.
+    # WARNING:  We are relying on setdefault() being atomic.  This is true
+    #   in CPython but we haven't investigated others.  This warning appears
+    #   in several other locations in this file.
+    field_value = self._fields.setdefault(field, field_value)
+  return field_value
+
var source
-

Field SubPacket.source

+

Getter for source.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var success_id
-

Field SubPacket.success_id

+

Getter for success_id.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var user
-

Field SubPacket.user

+

Getter for user.

+
+ +Expand source code + +
def getter(self):
+  field_value = self._fields.get(field)
+  if field_value is None:
+    # Construct a new object to represent this field.
+    field_value = field._default_constructor(self)
+
+    # Atomically check if another thread has preempted us and, if not, swap
+    # in the new object we just created.  If someone has preempted us, we
+    # take that object and discard ours.
+    # WARNING:  We are relying on setdefault() being atomic.  This is true
+    #   in CPython but we haven't investigated others.  This warning appears
+    #   in several other locations in this file.
+    field_value = self._fields.setdefault(field, field_value)
+  return field_value
+
var want_response
-

Field SubPacket.want_response

+

Getter for want_response.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
+
+
+

Methods

+
+
+def ByteSize(self) +
+
+
+
+ +Expand source code + +
def ByteSize(self):
+  if not self._cached_byte_size_dirty:
+    return self._cached_byte_size
+
+  size = 0
+  descriptor = self.DESCRIPTOR
+  if descriptor.GetOptions().map_entry:
+    # Fields of map entry should always be serialized.
+    size = descriptor.fields_by_name['key']._sizer(self.key)
+    size += descriptor.fields_by_name['value']._sizer(self.value)
+  else:
+    for field_descriptor, field_value in self.ListFields():
+      size += field_descriptor._sizer(field_value)
+    for tag_bytes, value_bytes in self._unknown_fields:
+      size += len(tag_bytes) + len(value_bytes)
+
+  self._cached_byte_size = size
+  self._cached_byte_size_dirty = False
+  self._listener_for_children.dirty = False
+  return size
+
+
+
+def Clear(self) +
+
+
+
+ +Expand source code + +
def _Clear(self):
+  # Clear fields.
+  self._fields = {}
+  self._unknown_fields = ()
+  # pylint: disable=protected-access
+  if self._unknown_field_set is not None:
+    self._unknown_field_set._clear()
+    self._unknown_field_set = None
+
+  self._oneofs = {}
+  self._Modified()
+
+
+
+def ClearField(self, field_name) +
+
+
+
+ +Expand source code + +
def ClearField(self, field_name):
+  try:
+    field = message_descriptor.fields_by_name[field_name]
+  except KeyError:
+    try:
+      field = message_descriptor.oneofs_by_name[field_name]
+      if field in self._oneofs:
+        field = self._oneofs[field]
+      else:
+        return
+    except KeyError:
+      raise ValueError('Protocol message %s has no "%s" field.' %
+                       (message_descriptor.name, field_name))
+
+  if field in self._fields:
+    # To match the C++ implementation, we need to invalidate iterators
+    # for map fields when ClearField() happens.
+    if hasattr(self._fields[field], 'InvalidateIterators'):
+      self._fields[field].InvalidateIterators()
+
+    # Note:  If the field is a sub-message, its listener will still point
+    #   at us.  That's fine, because the worst than can happen is that it
+    #   will call _Modified() and invalidate our byte size.  Big deal.
+    del self._fields[field]
+
+    if self._oneofs.get(field.containing_oneof, None) is field:
+      del self._oneofs[field.containing_oneof]
+
+  # Always call _Modified() -- even if nothing was changed, this is
+  # a mutating method, and thus calling it should cause the field to become
+  # present in the parent message.
+  self._Modified()
+
+
+
+def DiscardUnknownFields(self) +
+
+
+
+ +Expand source code + +
def _DiscardUnknownFields(self):
+  self._unknown_fields = []
+  self._unknown_field_set = None      # pylint: disable=protected-access
+  for field, value in self.ListFields():
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if _IsMapField(field):
+        if _IsMessageMapField(field):
+          for key in value:
+            value[key].DiscardUnknownFields()
+      elif field.label == _FieldDescriptor.LABEL_REPEATED:
+        for sub_message in value:
+          sub_message.DiscardUnknownFields()
+      else:
+        value.DiscardUnknownFields()
+
+
+
+def FindInitializationErrors(self) +
+
+

Finds required fields which are not initialized.

+

Returns

+

A list of strings. +Each string is a path to an uninitialized field from +the top-level message, e.g. "foo.bar[5].baz".

+
+ +Expand source code + +
def FindInitializationErrors(self):
+  """Finds required fields which are not initialized.
+
+  Returns:
+    A list of strings.  Each string is a path to an uninitialized field from
+    the top-level message, e.g. "foo.bar[5].baz".
+  """
+
+  errors = []  # simplify things
+
+  for field in required_fields:
+    if not self.HasField(field.name):
+      errors.append(field.name)
+
+  for field, value in self.ListFields():
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if field.is_extension:
+        name = '(%s)' % field.full_name
+      else:
+        name = field.name
+
+      if _IsMapField(field):
+        if _IsMessageMapField(field):
+          for key in value:
+            element = value[key]
+            prefix = '%s[%s].' % (name, key)
+            sub_errors = element.FindInitializationErrors()
+            errors += [prefix + error for error in sub_errors]
+        else:
+          # ScalarMaps can't have any initialization errors.
+          pass
+      elif field.label == _FieldDescriptor.LABEL_REPEATED:
+        for i in range(len(value)):
+          element = value[i]
+          prefix = '%s[%d].' % (name, i)
+          sub_errors = element.FindInitializationErrors()
+          errors += [prefix + error for error in sub_errors]
+      else:
+        prefix = name + '.'
+        sub_errors = value.FindInitializationErrors()
+        errors += [prefix + error for error in sub_errors]
+
+  return errors
+
+
+
+def HasField(self, field_name) +
+
+
+
+ +Expand source code + +
def HasField(self, field_name):
+  try:
+    field = hassable_fields[field_name]
+  except KeyError:
+    raise ValueError(error_msg % (message_descriptor.full_name, field_name))
+
+  if isinstance(field, descriptor_mod.OneofDescriptor):
+    try:
+      return HasField(self, self._oneofs[field].name)
+    except KeyError:
+      return False
+  else:
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      value = self._fields.get(field)
+      return value is not None and value._is_present_in_parent
+    else:
+      return field in self._fields
+
+
+
+def IsInitialized(self, errors=None) +
+
+

Checks if all required fields of a message are set.

+

Args

+
+
errors
+
A list which, if provided, will be populated with the field +paths of all missing required fields.
+
+

Returns

+

True iff the specified message has all required fields set.

+
+ +Expand source code + +
def IsInitialized(self, errors=None):
+  """Checks if all required fields of a message are set.
+
+  Args:
+    errors:  A list which, if provided, will be populated with the field
+             paths of all missing required fields.
+
+  Returns:
+    True iff the specified message has all required fields set.
+  """
+
+  # Performance is critical so we avoid HasField() and ListFields().
+
+  for field in required_fields:
+    if (field not in self._fields or
+        (field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE and
+         not self._fields[field]._is_present_in_parent)):
+      if errors is not None:
+        errors.extend(self.FindInitializationErrors())
+      return False
+
+  for field, value in list(self._fields.items()):  # dict can change size!
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if field.label == _FieldDescriptor.LABEL_REPEATED:
+        if (field.message_type.has_options and
+            field.message_type.GetOptions().map_entry):
+          continue
+        for element in value:
+          if not element.IsInitialized():
+            if errors is not None:
+              errors.extend(self.FindInitializationErrors())
+            return False
+      elif value._is_present_in_parent and not value.IsInitialized():
+        if errors is not None:
+          errors.extend(self.FindInitializationErrors())
+        return False
+
+  return True
+
+
+
+def ListFields(self) +
+
+
+
+ +Expand source code + +
def ListFields(self):
+  all_fields = [item for item in self._fields.items() if _IsPresent(item)]
+  all_fields.sort(key = lambda item: item[0].number)
+  return all_fields
+
+
+
+def MergeFrom(self, msg) +
+
+
+
+ +Expand source code + +
def MergeFrom(self, msg):
+  if not isinstance(msg, cls):
+    raise TypeError(
+        'Parameter to MergeFrom() must be instance of same class: '
+        'expected %s got %s.' % (cls.__name__, msg.__class__.__name__))
+
+  assert msg is not self
+  self._Modified()
+
+  fields = self._fields
+
+  for field, value in msg._fields.items():
+    if field.label == LABEL_REPEATED:
+      field_value = fields.get(field)
+      if field_value is None:
+        # Construct a new object to represent this field.
+        field_value = field._default_constructor(self)
+        fields[field] = field_value
+      field_value.MergeFrom(value)
+    elif field.cpp_type == CPPTYPE_MESSAGE:
+      if value._is_present_in_parent:
+        field_value = fields.get(field)
+        if field_value is None:
+          # Construct a new object to represent this field.
+          field_value = field._default_constructor(self)
+          fields[field] = field_value
+        field_value.MergeFrom(value)
+    else:
+      self._fields[field] = value
+      if field.containing_oneof:
+        self._UpdateOneofState(field)
+
+  if msg._unknown_fields:
+    if not self._unknown_fields:
+      self._unknown_fields = []
+    self._unknown_fields.extend(msg._unknown_fields)
+    # pylint: disable=protected-access
+    if self._unknown_field_set is None:
+      self._unknown_field_set = containers.UnknownFieldSet()
+    self._unknown_field_set._extend(msg._unknown_field_set)
+
+
+
+def MergeFromString(self, serialized) +
+
+
+
+ +Expand source code + +
def MergeFromString(self, serialized):
+  if isinstance(serialized, memoryview) and six.PY2:
+    raise TypeError(
+        'memoryview not supported in Python 2 with the pure Python proto '
+        'implementation: this is to maintain compatibility with the C++ '
+        'implementation')
+
+  serialized = memoryview(serialized)
+  length = len(serialized)
+  try:
+    if self._InternalParse(serialized, 0, length) != length:
+      # The only reason _InternalParse would return early is if it
+      # encountered an end-group tag.
+      raise message_mod.DecodeError('Unexpected end-group tag.')
+  except (IndexError, TypeError):
+    # Now ord(buf[p:p+1]) == ord('') gets TypeError.
+    raise message_mod.DecodeError('Truncated message.')
+  except struct.error as e:
+    raise message_mod.DecodeError(e)
+  return length   # Return this for legacy reasons.
+
+
+
+def SerializePartialToString(self, **kwargs) +
+
+
+
+ +Expand source code + +
def SerializePartialToString(self, **kwargs):
+  out = BytesIO()
+  self._InternalSerialize(out.write, **kwargs)
+  return out.getvalue()
+
+
+
+def SerializeToString(self, **kwargs) +
+
+
+
+ +Expand source code + +
def SerializeToString(self, **kwargs):
+  # Check if the message has all of its required fields set.
+  if not self.IsInitialized():
+    raise message_mod.EncodeError(
+        'Message %s is missing required fields: %s' % (
+        self.DESCRIPTOR.full_name, ','.join(self.FindInitializationErrors())))
+  return self.SerializePartialToString(**kwargs)
+
+
+
+def SetInParent(self) +
+
+

Sets the _cached_byte_size_dirty bit to true, +and propagates this to our listener iff this was a state change.

+
+ +Expand source code + +
def Modified(self):
+  """Sets the _cached_byte_size_dirty bit to true,
+  and propagates this to our listener iff this was a state change.
+  """
+
+  # Note:  Some callers check _cached_byte_size_dirty before calling
+  #   _Modified() as an extra optimization.  So, if this method is ever
+  #   changed such that it does stuff even when _cached_byte_size_dirty is
+  #   already true, the callers need to be updated.
+  if not self._cached_byte_size_dirty:
+    self._cached_byte_size_dirty = True
+    self._listener_for_children.dirty = True
+    self._is_present_in_parent = True
+    self._listener.Modified()
+
+
+
+def UnknownFields(self) +
+
+
+
+ +Expand source code + +
def _UnknownFields(self):
+  if self._unknown_field_set is None:  # pylint: disable=protected-access
+    # pylint: disable=protected-access
+    self._unknown_field_set = containers.UnknownFieldSet()
+  return self._unknown_field_set    # pylint: disable=protected-access
+
+
+
+def WhichOneof(self, oneof_name) +
+
+

Returns the name of the currently set field inside a oneof, or None.

+
+ +Expand source code + +
def WhichOneof(self, oneof_name):
+  """Returns the name of the currently set field inside a oneof, or None."""
+  try:
+    field = message_descriptor.oneofs_by_name[oneof_name]
+  except KeyError:
+    raise ValueError(
+        'Protocol message has no oneof "%s" field.' % oneof_name)
+
+  nested_field = self._oneofs.get(field, None)
+  if nested_field is not None and self.HasField(nested_field.name):
+    return nested_field.name
+  else:
+    return None
+
class ToRadio -(*args, **kwargs) +(**kwargs)
-

A ProtocolMessage

+

Abstract base class for protocol messages.

+

Protocol message classes are almost always generated by the protocol +compiler. +These generated types subclass Message and implement the methods +shown below.

Ancestors

Class variables

@@ -2436,36 +10216,619 @@ DESCRIPTOR._options = None
+
var PACKET_FIELD_NUMBER
+
+
+
+
var SET_OWNER_FIELD_NUMBER
+
+
+
+
var SET_RADIO_FIELD_NUMBER
+
+
+
+
var WANT_CONFIG_ID_FIELD_NUMBER
+
+
+
+ +

Static methods

+
+
+def FromString(s) +
+
+
+
+ +Expand source code + +
def FromString(s):
+  message = cls()
+  message.MergeFromString(s)
+  return message
+
+
+
+def RegisterExtension(extension_handle) +
+
+
+
+ +Expand source code + +
def RegisterExtension(extension_handle):
+  extension_handle.containing_type = cls.DESCRIPTOR
+  # TODO(amauryfa): Use cls.MESSAGE_FACTORY.pool when available.
+  # pylint: disable=protected-access
+  cls.DESCRIPTOR.file.pool._AddExtensionDescriptor(extension_handle)
+  _AttachFieldHelpers(cls, extension_handle)
+
+

Instance variables

var packet
-

Field ToRadio.packet

+

Getter for packet.

+
+ +Expand source code + +
def getter(self):
+  field_value = self._fields.get(field)
+  if field_value is None:
+    # Construct a new object to represent this field.
+    field_value = field._default_constructor(self)
+
+    # Atomically check if another thread has preempted us and, if not, swap
+    # in the new object we just created.  If someone has preempted us, we
+    # take that object and discard ours.
+    # WARNING:  We are relying on setdefault() being atomic.  This is true
+    #   in CPython but we haven't investigated others.  This warning appears
+    #   in several other locations in this file.
+    field_value = self._fields.setdefault(field, field_value)
+  return field_value
+
var set_owner
-

Field ToRadio.set_owner

+

Getter for set_owner.

+
+ +Expand source code + +
def getter(self):
+  field_value = self._fields.get(field)
+  if field_value is None:
+    # Construct a new object to represent this field.
+    field_value = field._default_constructor(self)
+
+    # Atomically check if another thread has preempted us and, if not, swap
+    # in the new object we just created.  If someone has preempted us, we
+    # take that object and discard ours.
+    # WARNING:  We are relying on setdefault() being atomic.  This is true
+    #   in CPython but we haven't investigated others.  This warning appears
+    #   in several other locations in this file.
+    field_value = self._fields.setdefault(field, field_value)
+  return field_value
+
var set_radio
-

Field ToRadio.set_radio

+

Getter for set_radio.

+
+ +Expand source code + +
def getter(self):
+  field_value = self._fields.get(field)
+  if field_value is None:
+    # Construct a new object to represent this field.
+    field_value = field._default_constructor(self)
+
+    # Atomically check if another thread has preempted us and, if not, swap
+    # in the new object we just created.  If someone has preempted us, we
+    # take that object and discard ours.
+    # WARNING:  We are relying on setdefault() being atomic.  This is true
+    #   in CPython but we haven't investigated others.  This warning appears
+    #   in several other locations in this file.
+    field_value = self._fields.setdefault(field, field_value)
+  return field_value
+
var want_config_id
-

Field ToRadio.want_config_id

+

Getter for want_config_id.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
+
+
+

Methods

+
+
+def ByteSize(self) +
+
+
+
+ +Expand source code + +
def ByteSize(self):
+  if not self._cached_byte_size_dirty:
+    return self._cached_byte_size
+
+  size = 0
+  descriptor = self.DESCRIPTOR
+  if descriptor.GetOptions().map_entry:
+    # Fields of map entry should always be serialized.
+    size = descriptor.fields_by_name['key']._sizer(self.key)
+    size += descriptor.fields_by_name['value']._sizer(self.value)
+  else:
+    for field_descriptor, field_value in self.ListFields():
+      size += field_descriptor._sizer(field_value)
+    for tag_bytes, value_bytes in self._unknown_fields:
+      size += len(tag_bytes) + len(value_bytes)
+
+  self._cached_byte_size = size
+  self._cached_byte_size_dirty = False
+  self._listener_for_children.dirty = False
+  return size
+
+
+
+def Clear(self) +
+
+
+
+ +Expand source code + +
def _Clear(self):
+  # Clear fields.
+  self._fields = {}
+  self._unknown_fields = ()
+  # pylint: disable=protected-access
+  if self._unknown_field_set is not None:
+    self._unknown_field_set._clear()
+    self._unknown_field_set = None
+
+  self._oneofs = {}
+  self._Modified()
+
+
+
+def ClearField(self, field_name) +
+
+
+
+ +Expand source code + +
def ClearField(self, field_name):
+  try:
+    field = message_descriptor.fields_by_name[field_name]
+  except KeyError:
+    try:
+      field = message_descriptor.oneofs_by_name[field_name]
+      if field in self._oneofs:
+        field = self._oneofs[field]
+      else:
+        return
+    except KeyError:
+      raise ValueError('Protocol message %s has no "%s" field.' %
+                       (message_descriptor.name, field_name))
+
+  if field in self._fields:
+    # To match the C++ implementation, we need to invalidate iterators
+    # for map fields when ClearField() happens.
+    if hasattr(self._fields[field], 'InvalidateIterators'):
+      self._fields[field].InvalidateIterators()
+
+    # Note:  If the field is a sub-message, its listener will still point
+    #   at us.  That's fine, because the worst than can happen is that it
+    #   will call _Modified() and invalidate our byte size.  Big deal.
+    del self._fields[field]
+
+    if self._oneofs.get(field.containing_oneof, None) is field:
+      del self._oneofs[field.containing_oneof]
+
+  # Always call _Modified() -- even if nothing was changed, this is
+  # a mutating method, and thus calling it should cause the field to become
+  # present in the parent message.
+  self._Modified()
+
+
+
+def DiscardUnknownFields(self) +
+
+
+
+ +Expand source code + +
def _DiscardUnknownFields(self):
+  self._unknown_fields = []
+  self._unknown_field_set = None      # pylint: disable=protected-access
+  for field, value in self.ListFields():
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if _IsMapField(field):
+        if _IsMessageMapField(field):
+          for key in value:
+            value[key].DiscardUnknownFields()
+      elif field.label == _FieldDescriptor.LABEL_REPEATED:
+        for sub_message in value:
+          sub_message.DiscardUnknownFields()
+      else:
+        value.DiscardUnknownFields()
+
+
+
+def FindInitializationErrors(self) +
+
+

Finds required fields which are not initialized.

+

Returns

+

A list of strings. +Each string is a path to an uninitialized field from +the top-level message, e.g. "foo.bar[5].baz".

+
+ +Expand source code + +
def FindInitializationErrors(self):
+  """Finds required fields which are not initialized.
+
+  Returns:
+    A list of strings.  Each string is a path to an uninitialized field from
+    the top-level message, e.g. "foo.bar[5].baz".
+  """
+
+  errors = []  # simplify things
+
+  for field in required_fields:
+    if not self.HasField(field.name):
+      errors.append(field.name)
+
+  for field, value in self.ListFields():
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if field.is_extension:
+        name = '(%s)' % field.full_name
+      else:
+        name = field.name
+
+      if _IsMapField(field):
+        if _IsMessageMapField(field):
+          for key in value:
+            element = value[key]
+            prefix = '%s[%s].' % (name, key)
+            sub_errors = element.FindInitializationErrors()
+            errors += [prefix + error for error in sub_errors]
+        else:
+          # ScalarMaps can't have any initialization errors.
+          pass
+      elif field.label == _FieldDescriptor.LABEL_REPEATED:
+        for i in range(len(value)):
+          element = value[i]
+          prefix = '%s[%d].' % (name, i)
+          sub_errors = element.FindInitializationErrors()
+          errors += [prefix + error for error in sub_errors]
+      else:
+        prefix = name + '.'
+        sub_errors = value.FindInitializationErrors()
+        errors += [prefix + error for error in sub_errors]
+
+  return errors
+
+
+
+def HasField(self, field_name) +
+
+
+
+ +Expand source code + +
def HasField(self, field_name):
+  try:
+    field = hassable_fields[field_name]
+  except KeyError:
+    raise ValueError(error_msg % (message_descriptor.full_name, field_name))
+
+  if isinstance(field, descriptor_mod.OneofDescriptor):
+    try:
+      return HasField(self, self._oneofs[field].name)
+    except KeyError:
+      return False
+  else:
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      value = self._fields.get(field)
+      return value is not None and value._is_present_in_parent
+    else:
+      return field in self._fields
+
+
+
+def IsInitialized(self, errors=None) +
+
+

Checks if all required fields of a message are set.

+

Args

+
+
errors
+
A list which, if provided, will be populated with the field +paths of all missing required fields.
+
+

Returns

+

True iff the specified message has all required fields set.

+
+ +Expand source code + +
def IsInitialized(self, errors=None):
+  """Checks if all required fields of a message are set.
+
+  Args:
+    errors:  A list which, if provided, will be populated with the field
+             paths of all missing required fields.
+
+  Returns:
+    True iff the specified message has all required fields set.
+  """
+
+  # Performance is critical so we avoid HasField() and ListFields().
+
+  for field in required_fields:
+    if (field not in self._fields or
+        (field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE and
+         not self._fields[field]._is_present_in_parent)):
+      if errors is not None:
+        errors.extend(self.FindInitializationErrors())
+      return False
+
+  for field, value in list(self._fields.items()):  # dict can change size!
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if field.label == _FieldDescriptor.LABEL_REPEATED:
+        if (field.message_type.has_options and
+            field.message_type.GetOptions().map_entry):
+          continue
+        for element in value:
+          if not element.IsInitialized():
+            if errors is not None:
+              errors.extend(self.FindInitializationErrors())
+            return False
+      elif value._is_present_in_parent and not value.IsInitialized():
+        if errors is not None:
+          errors.extend(self.FindInitializationErrors())
+        return False
+
+  return True
+
+
+
+def ListFields(self) +
+
+
+
+ +Expand source code + +
def ListFields(self):
+  all_fields = [item for item in self._fields.items() if _IsPresent(item)]
+  all_fields.sort(key = lambda item: item[0].number)
+  return all_fields
+
+
+
+def MergeFrom(self, msg) +
+
+
+
+ +Expand source code + +
def MergeFrom(self, msg):
+  if not isinstance(msg, cls):
+    raise TypeError(
+        'Parameter to MergeFrom() must be instance of same class: '
+        'expected %s got %s.' % (cls.__name__, msg.__class__.__name__))
+
+  assert msg is not self
+  self._Modified()
+
+  fields = self._fields
+
+  for field, value in msg._fields.items():
+    if field.label == LABEL_REPEATED:
+      field_value = fields.get(field)
+      if field_value is None:
+        # Construct a new object to represent this field.
+        field_value = field._default_constructor(self)
+        fields[field] = field_value
+      field_value.MergeFrom(value)
+    elif field.cpp_type == CPPTYPE_MESSAGE:
+      if value._is_present_in_parent:
+        field_value = fields.get(field)
+        if field_value is None:
+          # Construct a new object to represent this field.
+          field_value = field._default_constructor(self)
+          fields[field] = field_value
+        field_value.MergeFrom(value)
+    else:
+      self._fields[field] = value
+      if field.containing_oneof:
+        self._UpdateOneofState(field)
+
+  if msg._unknown_fields:
+    if not self._unknown_fields:
+      self._unknown_fields = []
+    self._unknown_fields.extend(msg._unknown_fields)
+    # pylint: disable=protected-access
+    if self._unknown_field_set is None:
+      self._unknown_field_set = containers.UnknownFieldSet()
+    self._unknown_field_set._extend(msg._unknown_field_set)
+
+
+
+def MergeFromString(self, serialized) +
+
+
+
+ +Expand source code + +
def MergeFromString(self, serialized):
+  if isinstance(serialized, memoryview) and six.PY2:
+    raise TypeError(
+        'memoryview not supported in Python 2 with the pure Python proto '
+        'implementation: this is to maintain compatibility with the C++ '
+        'implementation')
+
+  serialized = memoryview(serialized)
+  length = len(serialized)
+  try:
+    if self._InternalParse(serialized, 0, length) != length:
+      # The only reason _InternalParse would return early is if it
+      # encountered an end-group tag.
+      raise message_mod.DecodeError('Unexpected end-group tag.')
+  except (IndexError, TypeError):
+    # Now ord(buf[p:p+1]) == ord('') gets TypeError.
+    raise message_mod.DecodeError('Truncated message.')
+  except struct.error as e:
+    raise message_mod.DecodeError(e)
+  return length   # Return this for legacy reasons.
+
+
+
+def SerializePartialToString(self, **kwargs) +
+
+
+
+ +Expand source code + +
def SerializePartialToString(self, **kwargs):
+  out = BytesIO()
+  self._InternalSerialize(out.write, **kwargs)
+  return out.getvalue()
+
+
+
+def SerializeToString(self, **kwargs) +
+
+
+
+ +Expand source code + +
def SerializeToString(self, **kwargs):
+  # Check if the message has all of its required fields set.
+  if not self.IsInitialized():
+    raise message_mod.EncodeError(
+        'Message %s is missing required fields: %s' % (
+        self.DESCRIPTOR.full_name, ','.join(self.FindInitializationErrors())))
+  return self.SerializePartialToString(**kwargs)
+
+
+
+def SetInParent(self) +
+
+

Sets the _cached_byte_size_dirty bit to true, +and propagates this to our listener iff this was a state change.

+
+ +Expand source code + +
def Modified(self):
+  """Sets the _cached_byte_size_dirty bit to true,
+  and propagates this to our listener iff this was a state change.
+  """
+
+  # Note:  Some callers check _cached_byte_size_dirty before calling
+  #   _Modified() as an extra optimization.  So, if this method is ever
+  #   changed such that it does stuff even when _cached_byte_size_dirty is
+  #   already true, the callers need to be updated.
+  if not self._cached_byte_size_dirty:
+    self._cached_byte_size_dirty = True
+    self._listener_for_children.dirty = True
+    self._is_present_in_parent = True
+    self._listener.Modified()
+
+
+
+def UnknownFields(self) +
+
+
+
+ +Expand source code + +
def _UnknownFields(self):
+  if self._unknown_field_set is None:  # pylint: disable=protected-access
+    # pylint: disable=protected-access
+    self._unknown_field_set = containers.UnknownFieldSet()
+  return self._unknown_field_set    # pylint: disable=protected-access
+
+
+
+def WhichOneof(self, oneof_name) +
+
+

Returns the name of the currently set field inside a oneof, or None.

+
+ +Expand source code + +
def WhichOneof(self, oneof_name):
+  """Returns the name of the currently set field inside a oneof, or None."""
+  try:
+    field = message_descriptor.oneofs_by_name[oneof_name]
+  except KeyError:
+    raise ValueError(
+        'Protocol message has no oneof "%s" field.' % oneof_name)
+
+  nested_field = self._oneofs.get(field, None)
+  if nested_field is not None and self.HasField(nested_field.name):
+    return nested_field.name
+  else:
+    return None
+
class User -(*args, **kwargs) +(**kwargs)
-

A ProtocolMessage

+

Abstract base class for protocol messages.

+

Protocol message classes are almost always generated by the protocol +compiler. +These generated types subclass Message and implement the methods +shown below.

Ancestors

Class variables

@@ -2474,24 +10837,574 @@ DESCRIPTOR._options = None
+
var ID_FIELD_NUMBER
+
+
+
+
var LONG_NAME_FIELD_NUMBER
+
+
+
+
var MACADDR_FIELD_NUMBER
+
+
+
+
var SHORT_NAME_FIELD_NUMBER
+
+
+
+ +

Static methods

+
+
+def FromString(s) +
+
+
+
+ +Expand source code + +
def FromString(s):
+  message = cls()
+  message.MergeFromString(s)
+  return message
+
+
+
+def RegisterExtension(extension_handle) +
+
+
+
+ +Expand source code + +
def RegisterExtension(extension_handle):
+  extension_handle.containing_type = cls.DESCRIPTOR
+  # TODO(amauryfa): Use cls.MESSAGE_FACTORY.pool when available.
+  # pylint: disable=protected-access
+  cls.DESCRIPTOR.file.pool._AddExtensionDescriptor(extension_handle)
+  _AttachFieldHelpers(cls, extension_handle)
+
+

Instance variables

var id
-

Field User.id

+

Getter for id.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var long_name
-

Field User.long_name

+

Getter for long_name.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var macaddr
-

Field User.macaddr

+

Getter for macaddr.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
var short_name
-

Field User.short_name

+

Getter for short_name.

+
+ +Expand source code + +
def getter(self):
+  # TODO(protobuf-team): This may be broken since there may not be
+  # default_value.  Combine with has_default_value somehow.
+  return self._fields.get(field, default_value)
+
+
+
+

Methods

+
+
+def ByteSize(self) +
+
+
+
+ +Expand source code + +
def ByteSize(self):
+  if not self._cached_byte_size_dirty:
+    return self._cached_byte_size
+
+  size = 0
+  descriptor = self.DESCRIPTOR
+  if descriptor.GetOptions().map_entry:
+    # Fields of map entry should always be serialized.
+    size = descriptor.fields_by_name['key']._sizer(self.key)
+    size += descriptor.fields_by_name['value']._sizer(self.value)
+  else:
+    for field_descriptor, field_value in self.ListFields():
+      size += field_descriptor._sizer(field_value)
+    for tag_bytes, value_bytes in self._unknown_fields:
+      size += len(tag_bytes) + len(value_bytes)
+
+  self._cached_byte_size = size
+  self._cached_byte_size_dirty = False
+  self._listener_for_children.dirty = False
+  return size
+
+
+
+def Clear(self) +
+
+
+
+ +Expand source code + +
def _Clear(self):
+  # Clear fields.
+  self._fields = {}
+  self._unknown_fields = ()
+  # pylint: disable=protected-access
+  if self._unknown_field_set is not None:
+    self._unknown_field_set._clear()
+    self._unknown_field_set = None
+
+  self._oneofs = {}
+  self._Modified()
+
+
+
+def ClearField(self, field_name) +
+
+
+
+ +Expand source code + +
def ClearField(self, field_name):
+  try:
+    field = message_descriptor.fields_by_name[field_name]
+  except KeyError:
+    try:
+      field = message_descriptor.oneofs_by_name[field_name]
+      if field in self._oneofs:
+        field = self._oneofs[field]
+      else:
+        return
+    except KeyError:
+      raise ValueError('Protocol message %s has no "%s" field.' %
+                       (message_descriptor.name, field_name))
+
+  if field in self._fields:
+    # To match the C++ implementation, we need to invalidate iterators
+    # for map fields when ClearField() happens.
+    if hasattr(self._fields[field], 'InvalidateIterators'):
+      self._fields[field].InvalidateIterators()
+
+    # Note:  If the field is a sub-message, its listener will still point
+    #   at us.  That's fine, because the worst than can happen is that it
+    #   will call _Modified() and invalidate our byte size.  Big deal.
+    del self._fields[field]
+
+    if self._oneofs.get(field.containing_oneof, None) is field:
+      del self._oneofs[field.containing_oneof]
+
+  # Always call _Modified() -- even if nothing was changed, this is
+  # a mutating method, and thus calling it should cause the field to become
+  # present in the parent message.
+  self._Modified()
+
+
+
+def DiscardUnknownFields(self) +
+
+
+
+ +Expand source code + +
def _DiscardUnknownFields(self):
+  self._unknown_fields = []
+  self._unknown_field_set = None      # pylint: disable=protected-access
+  for field, value in self.ListFields():
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if _IsMapField(field):
+        if _IsMessageMapField(field):
+          for key in value:
+            value[key].DiscardUnknownFields()
+      elif field.label == _FieldDescriptor.LABEL_REPEATED:
+        for sub_message in value:
+          sub_message.DiscardUnknownFields()
+      else:
+        value.DiscardUnknownFields()
+
+
+
+def FindInitializationErrors(self) +
+
+

Finds required fields which are not initialized.

+

Returns

+

A list of strings. +Each string is a path to an uninitialized field from +the top-level message, e.g. "foo.bar[5].baz".

+
+ +Expand source code + +
def FindInitializationErrors(self):
+  """Finds required fields which are not initialized.
+
+  Returns:
+    A list of strings.  Each string is a path to an uninitialized field from
+    the top-level message, e.g. "foo.bar[5].baz".
+  """
+
+  errors = []  # simplify things
+
+  for field in required_fields:
+    if not self.HasField(field.name):
+      errors.append(field.name)
+
+  for field, value in self.ListFields():
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if field.is_extension:
+        name = '(%s)' % field.full_name
+      else:
+        name = field.name
+
+      if _IsMapField(field):
+        if _IsMessageMapField(field):
+          for key in value:
+            element = value[key]
+            prefix = '%s[%s].' % (name, key)
+            sub_errors = element.FindInitializationErrors()
+            errors += [prefix + error for error in sub_errors]
+        else:
+          # ScalarMaps can't have any initialization errors.
+          pass
+      elif field.label == _FieldDescriptor.LABEL_REPEATED:
+        for i in range(len(value)):
+          element = value[i]
+          prefix = '%s[%d].' % (name, i)
+          sub_errors = element.FindInitializationErrors()
+          errors += [prefix + error for error in sub_errors]
+      else:
+        prefix = name + '.'
+        sub_errors = value.FindInitializationErrors()
+        errors += [prefix + error for error in sub_errors]
+
+  return errors
+
+
+
+def HasField(self, field_name) +
+
+
+
+ +Expand source code + +
def HasField(self, field_name):
+  try:
+    field = hassable_fields[field_name]
+  except KeyError:
+    raise ValueError(error_msg % (message_descriptor.full_name, field_name))
+
+  if isinstance(field, descriptor_mod.OneofDescriptor):
+    try:
+      return HasField(self, self._oneofs[field].name)
+    except KeyError:
+      return False
+  else:
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      value = self._fields.get(field)
+      return value is not None and value._is_present_in_parent
+    else:
+      return field in self._fields
+
+
+
+def IsInitialized(self, errors=None) +
+
+

Checks if all required fields of a message are set.

+

Args

+
+
errors
+
A list which, if provided, will be populated with the field +paths of all missing required fields.
+
+

Returns

+

True iff the specified message has all required fields set.

+
+ +Expand source code + +
def IsInitialized(self, errors=None):
+  """Checks if all required fields of a message are set.
+
+  Args:
+    errors:  A list which, if provided, will be populated with the field
+             paths of all missing required fields.
+
+  Returns:
+    True iff the specified message has all required fields set.
+  """
+
+  # Performance is critical so we avoid HasField() and ListFields().
+
+  for field in required_fields:
+    if (field not in self._fields or
+        (field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE and
+         not self._fields[field]._is_present_in_parent)):
+      if errors is not None:
+        errors.extend(self.FindInitializationErrors())
+      return False
+
+  for field, value in list(self._fields.items()):  # dict can change size!
+    if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
+      if field.label == _FieldDescriptor.LABEL_REPEATED:
+        if (field.message_type.has_options and
+            field.message_type.GetOptions().map_entry):
+          continue
+        for element in value:
+          if not element.IsInitialized():
+            if errors is not None:
+              errors.extend(self.FindInitializationErrors())
+            return False
+      elif value._is_present_in_parent and not value.IsInitialized():
+        if errors is not None:
+          errors.extend(self.FindInitializationErrors())
+        return False
+
+  return True
+
+
+
+def ListFields(self) +
+
+
+
+ +Expand source code + +
def ListFields(self):
+  all_fields = [item for item in self._fields.items() if _IsPresent(item)]
+  all_fields.sort(key = lambda item: item[0].number)
+  return all_fields
+
+
+
+def MergeFrom(self, msg) +
+
+
+
+ +Expand source code + +
def MergeFrom(self, msg):
+  if not isinstance(msg, cls):
+    raise TypeError(
+        'Parameter to MergeFrom() must be instance of same class: '
+        'expected %s got %s.' % (cls.__name__, msg.__class__.__name__))
+
+  assert msg is not self
+  self._Modified()
+
+  fields = self._fields
+
+  for field, value in msg._fields.items():
+    if field.label == LABEL_REPEATED:
+      field_value = fields.get(field)
+      if field_value is None:
+        # Construct a new object to represent this field.
+        field_value = field._default_constructor(self)
+        fields[field] = field_value
+      field_value.MergeFrom(value)
+    elif field.cpp_type == CPPTYPE_MESSAGE:
+      if value._is_present_in_parent:
+        field_value = fields.get(field)
+        if field_value is None:
+          # Construct a new object to represent this field.
+          field_value = field._default_constructor(self)
+          fields[field] = field_value
+        field_value.MergeFrom(value)
+    else:
+      self._fields[field] = value
+      if field.containing_oneof:
+        self._UpdateOneofState(field)
+
+  if msg._unknown_fields:
+    if not self._unknown_fields:
+      self._unknown_fields = []
+    self._unknown_fields.extend(msg._unknown_fields)
+    # pylint: disable=protected-access
+    if self._unknown_field_set is None:
+      self._unknown_field_set = containers.UnknownFieldSet()
+    self._unknown_field_set._extend(msg._unknown_field_set)
+
+
+
+def MergeFromString(self, serialized) +
+
+
+
+ +Expand source code + +
def MergeFromString(self, serialized):
+  if isinstance(serialized, memoryview) and six.PY2:
+    raise TypeError(
+        'memoryview not supported in Python 2 with the pure Python proto '
+        'implementation: this is to maintain compatibility with the C++ '
+        'implementation')
+
+  serialized = memoryview(serialized)
+  length = len(serialized)
+  try:
+    if self._InternalParse(serialized, 0, length) != length:
+      # The only reason _InternalParse would return early is if it
+      # encountered an end-group tag.
+      raise message_mod.DecodeError('Unexpected end-group tag.')
+  except (IndexError, TypeError):
+    # Now ord(buf[p:p+1]) == ord('') gets TypeError.
+    raise message_mod.DecodeError('Truncated message.')
+  except struct.error as e:
+    raise message_mod.DecodeError(e)
+  return length   # Return this for legacy reasons.
+
+
+
+def SerializePartialToString(self, **kwargs) +
+
+
+
+ +Expand source code + +
def SerializePartialToString(self, **kwargs):
+  out = BytesIO()
+  self._InternalSerialize(out.write, **kwargs)
+  return out.getvalue()
+
+
+
+def SerializeToString(self, **kwargs) +
+
+
+
+ +Expand source code + +
def SerializeToString(self, **kwargs):
+  # Check if the message has all of its required fields set.
+  if not self.IsInitialized():
+    raise message_mod.EncodeError(
+        'Message %s is missing required fields: %s' % (
+        self.DESCRIPTOR.full_name, ','.join(self.FindInitializationErrors())))
+  return self.SerializePartialToString(**kwargs)
+
+
+
+def SetInParent(self) +
+
+

Sets the _cached_byte_size_dirty bit to true, +and propagates this to our listener iff this was a state change.

+
+ +Expand source code + +
def Modified(self):
+  """Sets the _cached_byte_size_dirty bit to true,
+  and propagates this to our listener iff this was a state change.
+  """
+
+  # Note:  Some callers check _cached_byte_size_dirty before calling
+  #   _Modified() as an extra optimization.  So, if this method is ever
+  #   changed such that it does stuff even when _cached_byte_size_dirty is
+  #   already true, the callers need to be updated.
+  if not self._cached_byte_size_dirty:
+    self._cached_byte_size_dirty = True
+    self._listener_for_children.dirty = True
+    self._is_present_in_parent = True
+    self._listener.Modified()
+
+
+
+def UnknownFields(self) +
+
+
+
+ +Expand source code + +
def _UnknownFields(self):
+  if self._unknown_field_set is None:  # pylint: disable=protected-access
+    # pylint: disable=protected-access
+    self._unknown_field_set = containers.UnknownFieldSet()
+  return self._unknown_field_set    # pylint: disable=protected-access
+
+
+
+def WhichOneof(self, oneof_name) +
+
+

Returns the name of the currently set field inside a oneof, or None.

+
+ +Expand source code + +
def WhichOneof(self, oneof_name):
+  """Returns the name of the currently set field inside a oneof, or None."""
+  try:
+    field = message_descriptor.oneofs_by_name[oneof_name]
+  except KeyError:
+    raise ValueError(
+        'Protocol message has no oneof "%s" field.' % oneof_name)
+
+  nested_field = self._oneofs.get(field, None)
+  if nested_field is not None and self.HasField(nested_field.name):
+    return nested_field.name
+  else:
+    return None
+
@@ -2513,13 +11426,38 @@ DESCRIPTOR._options = None