Recursive helper for _from_base_type() to convert an entity to a message.

  Args:
    ent: A Model instance.
    message_type: A Message subclass.

  Returns:
    An instance of message_type.
489388
def _projected_entity_to_message(ent, message_type):
  
  msg = message_type()
  analyzed = _analyze_indexed_fields(ent._projection)
  for name, sublist in analyzed.iteritems():
    prop = ent._properties[name]
    val = prop._get_value(ent)
    assert isinstance(prop, model.StructuredProperty) == bool(sublist)
    if sublist:
      field = message_type.field_by_name(name)
      assert isinstance(field, messages.MessageField)
      assert prop._repeated == field.repeated
      if prop._repeated:
        assert isinstance(val, list)
        val = [_projected_entity_to_message(v, field.type) for v in val]
      else:
        assert isinstance(val, prop._modelclass)
        val = _projected_entity_to_message(val, field.type)
    setattr(msg, name, val)
  return msg
778229
def from_message(bot, message):
        
        chat = message["chat"]
        return Chat(bot, chat["id"], chat["type"], message)
1038215
def log(type, message)
      case type.to_sym
      when :info
        msg = message
      when :error
        msg = message
      end

      @messages << msg
      puts msg if verbose?
    end
857149
def update_message_type(self, message_type):
        
        self._validate_uuid(message_type.message_type_id)

        url = "/notification/v1/message-type/{}".format(
            message_type.message_type_id)
        response = NWS_DAO().putURL(
            url, self._write_headers(), self._json_body(
                message_type.json_data()))

        if response.status != 204:
            raise DataFailureException(url, response.status, response.data)
        return response.status
147894
async def load_message(self, msg_type, msg=None):
        
        msg = msg_type() if msg is None else msg
        fields = msg_type.f_specs() if msg_type else msg.__class__.f_specs()
        for field in fields:
            await self.message_field(msg, field)

        return msg
1202491
async def dump_message(obj, msg, field_archiver=None):
    
    mtype = msg.__class__
    fields = mtype.f_specs()

    obj = collections.OrderedDict() if obj is None else get_elem(obj)
    for field in fields:
        await dump_message_field(obj, msg=msg, field=field, field_archiver=field_archiver)
    return obj
898796
def decode_message(self, message, is_key=False):
        

        if message is None:
            return None

        if len(message) <= 5:
            raise SerializerError("message is too small to decode")

        with ContextStringIO(message) as payload:
            magic, schema_id = struct.unpack('>bI', payload.read(5))
            if magic != MAGIC_BYTE:
                raise SerializerError("message does not start with magic byte")
            decoder_func = self._get_decoder_func(schema_id, payload, is_key)
            return decoder_func(payload)
1213839
def create(message_type, priority=0):
    """"""
    message = protobuf.ProtocolMessage()
    message.type = message_type
    message.priority = priority
    return message
756623
def message_handler(type_, from_):
    
    import aioxmpp.dispatcher
    return aioxmpp.dispatcher.message_handler(type_, from_)
206677
async def message(self, msg, msg_type=None, obj=None):
        
        elem_type = msg_type if msg_type is not None else msg.__class__
        obj = collections.OrderedDict() if not x.has_elem(obj) else x.get_elem(obj)

        if hasattr(elem_type, 'kv_serialize'):
            msg = elem_type() if msg is None else msg
            return await msg.kv_serialize(self, obj=obj)

        fields = elem_type.f_specs()
        for field in fields:
            await self.message_field(msg=msg, field=field, obj=obj)

        return obj if self.writing else msg
359056
def from_message(cls, message):
        
        type_ = message.get_text()
        return cls(type_=type_, blob=message.asbytes())
1163401
def load(cls, bmessage):
        
        message_dict = msgpack.loads(bmessage, encoding="utf8", use_list=False)

        try:
            obj = MessageMeta._registered_messages[message_dict["type"]].__new__(MessageMeta._registered_messages[message_dict["type"]])
            object.__setattr__(obj, "__dict__", message_dict)
        except:
            raise TypeError("Unknown message type") from None

        if not obj._verify():  # pylint: disable=protected-access
            raise TypeError("Invalid message content")

        return obj
637782
def populate_instance(msg, inst):
    
    return _to_inst(msg, type(inst).__name__, type(inst).__name__, inst)
745179
def message(self, message: types.Message):
        
        setattr(self, 'from_chat_id', message.chat.id)
        setattr(self, 'message_id', message.message_id)
        return self
1368545
public BaseConvertToMessage getConvertToMessage()
    {
        if (m_convertToMessage == null)
        {
            BaseMessageHeader trxMessageHeader = this.getMessage().getMessageHeader();
            String strMessageClass = (String)trxMessageHeader.get(TrxMessageHeader.MESSAGE_MARSHALLER_CLASS);
            String strPackage = (String)trxMessageHeader.get(TrxMessageHeader.BASE_PACKAGE);
            strMessageClass = ClassServiceUtility.getFullClassName(strPackage, strMessageClass);
            m_convertToMessage = (BaseConvertToMessage)ClassServiceUtility.getClassService().makeObjectFromClassName(strMessageClass);
            if (m_convertToMessage != null)
            	m_convertToMessage.init(this);
        }
        return m_convertToMessage;
    }
260739
def type(self):
        """"""
        if self.__type is None:
            message_type = find_definition(
                self.__type_name, self.message_definition())
            if not (message_type is not Message and
                    isinstance(message_type, type) and
                    issubclass(message_type, Message)):
                raise FieldDefinitionError(
                    'Invalid message class: %s' % message_type)
            self.__type = message_type
        return self.__type
775413
def types_from_module(pb_module):
    '''
    
    '''
    types = pb_module.DESCRIPTOR.message_types_by_name
    return [getattr(pb_module, name) for name in types]