void helper<ProtocolReader, ProtocolWriter>::process_exn( const char* func, const string& msg, unique_ptr<ResponseChannel::Request> req, Cpp2RequestContext* ctx, EventBase* eb, int32_t protoSeqId) { ProtocolWriter oprot; if (req) { LOG(ERROR) << msg << " in function " << func; TApplicationException x(msg); IOBufQueue queue = helper_w<ProtocolWriter>::write_exn( func, &oprot, protoSeqId, nullptr, x); queue.append(THeader::transform( queue.move(), ctx->getHeader()->getWriteTransforms(), ctx->getHeader()->getMinCompressBytes())); auto queue_mw = makeMoveWrapper(move(queue)); auto req_mw = makeMoveWrapper(move(req)); eb->runInEventBaseThread([=]() mutable { (*req_mw)->sendReply(queue_mw->move()); }); } else { LOG(ERROR) << msg << " in oneway function " << func; } }
bool decode(Context* ctx, IOBufQueue& buf, std::unique_ptr<IOBuf>& result, size_t&) override { result = buf.move(); return result != nullptr; }
bool decode(Context*, IOBufQueue& buf, std::string& result, size_t&) override { if (buf.chainLength() > 0) { result = buf.move()->moveToFbString().toStdString(); return true; } return false; }
TEST(SerializationTest, DeserializeReturningObjGivenStringPiece) { using serializer = SimpleJSONSerializer; auto s = makeTestStruct(); IOBufQueue q; serializer::serialize(s, &q); auto b = q.move(); auto out = serializer::deserialize<TestStruct>(StringPiece(b->coalesce())); EXPECT_EQ(s, out); }
bool LineBasedFrameDecoder::decode(Context* ctx, IOBufQueue& buf, std::unique_ptr<IOBuf>& result, size_t&) { int64_t eol = findEndOfLine(buf); if (!discarding_) { if (eol >= 0) { Cursor c(buf.front()); c += eol; auto delimLength = c.read<char>() == '\r' ? 2 : 1; if (eol > maxLength_) { buf.split(eol + delimLength); fail(ctx, folly::to<std::string>(eol)); return false; } std::unique_ptr<folly::IOBuf> frame; if (stripDelimiter_) { frame = buf.split(eol); buf.trimStart(delimLength); } else { frame = buf.split(eol + delimLength); } result = std::move(frame); return true; } else { auto len = buf.chainLength(); if (len > maxLength_) { discardedBytes_ = len; buf.trimStart(len); discarding_ = true; fail(ctx, "over " + folly::to<std::string>(len)); } return false; } } else { if (eol >= 0) { Cursor c(buf.front()); c += eol; auto delimLength = c.read<char>() == '\r' ? 2 : 1; buf.trimStart(eol + delimLength); discardedBytes_ = 0; discarding_ = false; } else { discardedBytes_ = buf.chainLength(); buf.move(); } return false; } }
void readBench(size_t iters) { BenchmarkSuspender susp; auto strct = create<Struct>(); IOBufQueue q; Serializer::serialize(strct, &q); auto buf = q.move(); susp.dismiss(); while (iters--) { Struct data; Serializer::deserialize(buf.get(), data); } susp.rehire(); }
int readBenchMemory(size_t iters) { auto strct = create<Struct>(); IOBufQueue q; Serializer::serialize(strct, &q); auto buf = q.move(); auto before = getMemoryRequestsCounter(); while (iters--) { Struct data; Serializer::deserialize(buf.get(), data); } auto after = getMemoryRequestsCounter(); return after - before; }
void FastCGITransport::sendImpl(const void *data, int size, int code, bool chunked) { IOBufQueue queue; if (!m_headersSent) { sendResponseHeaders(queue, code); } queue.append(IOBuf::copyBuffer(data, size)); folly::MoveWrapper<std::unique_ptr<IOBuf>> chain_wrapper(queue.move()); Callback* callback = m_callback; auto fn = [callback, chain_wrapper]() mutable { if (callback) { callback->onStdOut(std::move(*chain_wrapper)); } }; m_connection->getEventBase()->runInEventBaseThread(fn); }
void read(Context*, IOBufQueue& q) override { backendPipeline_->write(q.move()); }
void read(Context* ctx, IOBufQueue& q) override { frontendPipeline_->write(q.move()); }