def handle(self, connection_id, message_content): get_request = state_context_pb2.TpStateGetRequest() get_request.ParseFromString(message_content) try: return_values = self._context_manager.get( get_request.context_id, list(get_request.addresses)) except AuthorizationException: response = \ state_context_pb2.TpStateGetResponse( status=state_context_pb2. TpStateGetResponse.AUTHORIZATION_ERROR) return HandlerResult( HandlerStatus.RETURN, response, validator_pb2.Message.TP_STATE_GET_RESPONSE) return_list = return_values if return_values is not None else [] LOGGER.debug("GET: %s", return_list) entry_list = [state_context_pb2.Entry(address=a, data=d) for a, d in return_list] response = state_context_pb2.TpStateGetResponse( status=state_context_pb2.TpStateGetResponse.OK) response.entries.extend(entry_list) return HandlerResult( HandlerStatus.RETURN, response, validator_pb2.Message.TP_STATE_GET_RESPONSE)
def handle(self, identity, message_content): get_request = state_context_pb2.TpStateGetRequest() get_request.ParseFromString(message_content) return_values = self._context_manager.get(get_request.context_id, get_request.addresses) return_list = return_values if return_values is not None else [] LOGGER.debug("GET: %s", return_list) entry_list = [ state_context_pb2.Entry(address=a, data=d) for a, d in return_list ] response = state_context_pb2.TpStateGetResponse() response.entries.extend(entry_list) return HandlerResult(HandlerStatus.RETURN, response, validator_pb2.Message.TP_STATE_GET_RESPONSE)
def handle(self, message, responder): get_request = state_context_pb2.TpStateGetRequest() get_request.ParseFromString(message.content) return_values = self._context_manager.get(get_request.context_id, get_request.addresses) return_list = return_values if return_values is not None else [] LOGGER.debug("GET: %s", return_list) entry_list = [ state_context_pb2.Entry(address=a, data=d) for a, d in return_list ] responder.send(message=validator_pb2.Message( sender=message.sender, correlation_id=message.correlation_id, message_type=Message.TP_STATE_GET_RESPONSE, content=state_context_pb2.TpStateGetResponse( entries=entry_list).SerializeToString()))