bool Bank::nextChunk() { bool CF = rcr(false); if (_unpCtx.chk == 0) { assert(_iBuf >= _startBuf); _unpCtx.chk = READ_BE_UINT32(_iBuf); _iBuf -= 4; _unpCtx.crc ^= _unpCtx.chk; CF = rcr(true); } return CF; }
unsigned int CineUnpacker::nextBit() { unsigned int carry = rcr(false); // Normally if the chunk becomes zero then the carry is one as // the end of chunk marker is always the last to be shifted out. if (_chunk32b == 0) { _chunk32b = readSource(); _crc ^= _chunk32b; carry = rcr(true); // Put the end of chunk marker in the most significant bit } return carry; }
void AsyncMockStreamFactory::MockStream::simulateServer( rpc::Protocol proto, const stdx::function<RemoteCommandResponse(RemoteCommandRequest)> replyFunc) { std::exception_ptr ex; uint32_t messageId = 0; RemoteCommandResponse resp; { WriteEvent write{this}; std::vector<uint8_t> messageData = popWrite(); Message msg(messageData.data(), false); auto parsedRequest = rpc::makeRequest(&msg); ASSERT(parsedRequest->getProtocol() == proto); RemoteCommandRequest rcr(target(), *parsedRequest); messageId = msg.header().getId(); // So we can allow ASSERTs in replyFunc, we capture any exceptions, but rethrow // them later to prevent deadlock try { resp = replyFunc(std::move(rcr)); } catch (...) { ex = std::current_exception(); } } auto replyBuilder = rpc::makeReplyBuilder(proto); replyBuilder->setMetadata(resp.metadata); replyBuilder->setCommandReply(resp.data); auto replyMsg = replyBuilder->done(); replyMsg->header().setResponseTo(messageId); { // The first read will be for the header. ReadEvent read{this}; auto hdrBytes = reinterpret_cast<const uint8_t*>(replyMsg->header().view2ptr()); pushRead({hdrBytes, hdrBytes + sizeof(MSGHEADER::Value)}); } { // The second read will be for the message data. ReadEvent read{this}; auto dataBytes = reinterpret_cast<const uint8_t*>(replyMsg->buf()); auto pastHeader = dataBytes; std::advance(pastHeader, sizeof(MSGHEADER::Value)); pushRead({pastHeader, dataBytes + static_cast<std::size_t>(replyMsg->size())}); } if (ex) { // Rethrow ASSERTS after the NIA completes it's Write-Read-Read sequence. std::rethrow_exception(ex); } }
/* **************************************************************************** * * restErrorReplyGet - * * This function renders an error reply depending on the 'request' type. * Many responses have different syntax and especially the tag in the reply * differs (registerContextResponse, discoverContextAvailabilityResponse etc). * * Also, the function is called from more than one place, especially from * restErrorReply, but also from where the payload type is matched against the request URL. * Where the payload type is matched against the request URL, the incoming 'request' is a * request and not a response. */ std::string restErrorReplyGet(ConnectionInfo* ciP, Format format, std::string indent, std::string request, HttpStatusCode code, std::string details) { std::string tag = tagGet(request); StatusCode errorCode(code, details, "errorCode"); std::string reply; ciP->httpStatusCode = SccOk; if (tag == "registerContextResponse") { RegisterContextResponse rcr("000000000000000000000000", errorCode); reply = rcr.render(RegisterContext, format, indent); } else if (tag == "discoverContextAvailabilityResponse") { DiscoverContextAvailabilityResponse dcar(errorCode); reply = dcar.render(DiscoverContextAvailability, format, indent); } else if (tag == "subscribeContextAvailabilityResponse") { SubscribeContextAvailabilityResponse scar("000000000000000000000000", errorCode); reply = scar.render(SubscribeContextAvailability, format, indent); } else if (tag == "updateContextAvailabilitySubscriptionResponse") { UpdateContextAvailabilitySubscriptionResponse ucas(errorCode); reply = ucas.render(UpdateContextAvailabilitySubscription, format, indent, 0); } else if (tag == "unsubscribeContextAvailabilityResponse") { UnsubscribeContextAvailabilityResponse ucar(errorCode); reply = ucar.render(UnsubscribeContextAvailability, format, indent); } else if (tag == "notifyContextAvailabilityResponse") { NotifyContextAvailabilityResponse ncar(errorCode); reply = ncar.render(NotifyContextAvailability, format, indent); } else if (tag == "queryContextResponse") { QueryContextResponse qcr(errorCode); reply = qcr.render(QueryContext, format, indent); } else if (tag == "subscribeContextResponse") { SubscribeContextResponse scr(errorCode); reply = scr.render(SubscribeContext, format, indent); } else if (tag == "updateContextSubscriptionResponse") { UpdateContextSubscriptionResponse ucsr(errorCode); reply = ucsr.render(UpdateContextSubscription, format, indent); } else if (tag == "unsubscribeContextResponse") { UnsubscribeContextResponse uncr(errorCode); reply = uncr.render(UnsubscribeContext, format, indent); } else if (tag == "updateContextResponse") { UpdateContextResponse ucr(errorCode); reply = ucr.render(UpdateContext, format, indent); } else if (tag == "notifyContextResponse") { NotifyContextResponse ncr(errorCode); reply = ncr.render(NotifyContext, format, indent); } else if (tag == "StatusCode") { StatusCode sc(code, details); reply = sc.render(format, indent); } else { OrionError orionError(errorCode); LM_E(("Unknown tag: '%s', request == '%s'", tag.c_str(), request.c_str())); reply = orionError.render(format, indent); } return reply; }