async def open(self, transport: asyncio.Transport) -> bool: self._transport = transport self._transport.write(frame.marshal(header.ProtocolHeader(), 0)) self._set_state(STATE_PROTOCOL_HEADER_SENT) result = await self._wait_on_state(STATE_OPENOK_RECEIVED, STATE_CLOSEOK_SENT) if self._heartbeat_interval: self._logger.debug('Checking for heartbeats every %2f seconds', self._heartbeat_interval) self._heartbeat_timer = self._loop.call_later( self._heartbeat_interval, self._heartbeat_check) return result == STATE_OPENOK_RECEIVED
def _unmarshal_protocol_header_frame(data_in: bytes) \ -> typing.Optional[header.ProtocolHeader]: """Attempt to unmarshal a protocol header frame The ProtocolHeader is abbreviated in size and functionality compared to the rest of the frame types, so return UNMARSHAL_ERROR doesn't apply as cleanly since we don't have all of the attributes to return even regardless of success or failure. :raises: ValueError """ if data_in[0:4] == constants.AMQP: # Do the first four bytes match? frame = header.ProtocolHeader() frame.unmarshal(data_in) return frame return None
def _unmarshal_protocol_header_frame(data_in): """Attempt to unmarshal a protocol header frame The ProtocolHeader is abbreviated in size and functionality compared to the rest of the frame types, so return UNMARSHAL_ERROR doesn't apply as cleanly since we don't have all of the attributes to return even regardless of success or failure. :param bytes data_in: Raw byte stream data :rtype: header.ProtocolHeader :raises: ValueError """ # Do the first four bytes match? if data_in[0:4] == AMQP: frame = header.ProtocolHeader() frame.unmarshal(data_in) return frame
def _write_protocol_header(self): """Send the protocol header to the connected server.""" self.write_frame(header.ProtocolHeader())
def test_protocol_header(self): expectation = b'AMQP\x00\x00\t\x01' response = frame.marshal(header.ProtocolHeader(), 0) self.assertEqual(response, expectation, 'ProtocolHeader did not match expectation')
def _send_handshake(self): """Send a RabbitMQ Handshake. :return: """ self._io.write_to_socket(pamqp_header.ProtocolHeader().marshal())
def protocol_header_test(self): expectation = encode('AMQP\x00\x00\t\x01') response = header.ProtocolHeader().marshal() self.assertEqual(response, expectation, "ProtocolHeader did not match expectation")