facebook / wangle

Wangle is a framework providing a set of common client/server abstractions for building services in a consistent, modular, and composable way.
Apache License 2.0
3.04k stars 536 forks source link

LengthFieldBasedFrameDecoder decoder Example. Not able to Read Content Length #61

Closed sureshbalakundi closed 7 years ago

sureshbalakundi commented 7 years ago

Im decoding LengthFieldBasedFrameDecoder format. when I'm Decoding Length is not coming. Please Suggest me How i need to decode. please find the below program

class EchoHandler : public HandlerAdapterstd::string { public: virtual void read(Context* ctx, std::string msg) override { LOG(INFO) << "Recieving Time"; /* Here Im Decoding the Buffer but Content Length is Not able to Read *//

std::cout << "handling " << msg << std::endl;
write(ctx, msg + "\r\n");

} }; class EchoPipelineFactory : public PipelineFactory { public: EchoPipeline::Ptr newPipeline(std::shared_ptr sock) { auto pipeline = EchoPipeline::create(); pipeline->addBack(AsyncSocketHandler(sock)); pipeline->addBack(LengthFieldBasedFrameDecoder()); pipeline->addBack(LengthFieldPrepender()); pipeline->addBack(StringCodec()); pipeline->addBack(EchoHandler()); pipeline->finalize(); return pipeline; } };

int main(int argc, char\ argv) { google::ParseCommandLineFlags(&argc, &argv, true);

ServerBootstrap server; server.childPipeline(std::make_shared()); server.bind(FLAGS_port); server.waitForStop();

return 0; }

djwatson commented 7 years ago

Set the "initialbytestostrip" to 0:

LengthFieldBasedFrameDecoder(uint32_t lengthFieldLength = 4, uint32_t maxFrameLength = UINT_MAX, uint32_t lengthFieldOffset = 0, int32_t lengthAdjustment = 0, uint32_t initialBytesToStrip = 0, bool networkByteOrder = true);