code: def default(self, value):
          
          if isinstance(value, messages.Enum):
              return str(value)
  
          if six.PY3 and isinstance(value, bytes):
              return value.decode('utf8')
  
          if isinstance(value, messages.Message):
              result = {}
              for field in value.all_fields():
                  item = value.get_assigned_value(field.name)
                  if item not in (None, [], ()):
                      result[field.name] = (
                          self.__protojson_protocol.encode_field(field, item))
              # Handle unrecognized fields, so they're included when a message is
              # decoded then encoded.
              for unknown_key in value.all_unrecognized_fields():
                  unrecognized_field, _ = value.get_unrecognized_field_info(
                      unknown_key)
                  # Unknown fields are not encoded as they should have been
                  # processed before we get to here.
                  result[unknown_key] = unrecognized_field
              return result
  
          return super(MessageJSONEncoder, self).default(value)
docs: Return dictionary instance from a message object.
  
          Args:
          value: Value to get dictionary for.  If not encodable, will
            call superclasses default method.