proxygen
wangle::FixedLengthFrameDecoder Class Reference

#include <FixedLengthFrameDecoder.h>

Inheritance diagram for wangle::FixedLengthFrameDecoder:
wangle::ByteToMessageDecoder< M > wangle::InboundHandler< folly::IOBufQueue &, M > wangle::HandlerBase< InboundHandlerContext< M > >

Public Member Functions

 FixedLengthFrameDecoder (size_t length)
 
bool decode (Context *, folly::IOBufQueue &q, std::unique_ptr< folly::IOBuf > &result, size_t &needed) override
 
- Public Member Functions inherited from wangle::ByteToMessageDecoder< M >
virtual bool decode (Context *ctx, folly::IOBufQueue &buf, M &result, size_t &)=0
 
void transportActive (Context *ctx) override
 
void transportInactive (Context *ctx) override
 
void read (Context *ctx, folly::IOBufQueue &q) override
 
- Public Member Functions inherited from wangle::InboundHandler< folly::IOBufQueue &, M >
 ~InboundHandler () override=default
 
virtual void read (Context *ctx, folly::IOBufQueue &msg)=0
 
virtual void readEOF (Context *ctx)
 
virtual void readException (Context *ctx, folly::exception_wrapper e)
 
virtual void transportActive (Context *ctx)
 
virtual void transportInactive (Context *ctx)
 
- Public Member Functions inherited from wangle::HandlerBase< InboundHandlerContext< M > >
virtual ~HandlerBase ()=default
 
virtual void attachPipeline (InboundHandlerContext< M > *)
 
virtual void detachPipeline (InboundHandlerContext< M > *)
 
InboundHandlerContext< M > * getContext ()
 

Private Attributes

size_t length_
 

Additional Inherited Members

- Public Types inherited from wangle::ByteToMessageDecoder< M >
typedef InboundHandler< folly::IOBufQueue &, M >::Context Context
 
- Public Types inherited from wangle::InboundHandler< folly::IOBufQueue &, M >
typedef folly::IOBufQueuerin
 
typedef M rout
 
typedef folly::Unit win
 
typedef folly::Unit wout
 
typedef InboundHandlerContext< MContext
 
- Static Public Attributes inherited from wangle::InboundHandler< folly::IOBufQueue &, M >
static const HandlerDir dir
 

Detailed Description

A decoder that splits the received IOBufs by the fixed number of bytes. For example, if you received the following four fragmented packets:

+—+-—+---—+-—+ | A | BC | DEFG | HI | +—+-—+---—+-—+

A FixedLengthFrameDecoder will decode them into the following three packets with the fixed length:

+--—+--—+--—+ | ABC | DEF | GHI | +--—+--—+--—+

Definition at line 40 of file FixedLengthFrameDecoder.h.

Constructor & Destructor Documentation

wangle::FixedLengthFrameDecoder::FixedLengthFrameDecoder ( size_t  length)
inlineexplicit

Definition at line 42 of file FixedLengthFrameDecoder.h.

Member Function Documentation

bool wangle::FixedLengthFrameDecoder::decode ( Context ,
folly::IOBufQueue q,
std::unique_ptr< folly::IOBuf > &  result,
size_t &  needed 
)
inlineoverride

Definition at line 44 of file FixedLengthFrameDecoder.h.

References folly::IOBufQueue::chainLength(), length_, and folly::IOBufQueue::split().

47  {
48  if (q.chainLength() < length_) {
49  needed = length_ - q.chainLength();
50  return false;
51  }
52 
53  result = q.split(length_);
54  return true;
55  }
std::unique_ptr< folly::IOBuf > split(size_t n)
Definition: IOBufQueue.h:420
size_t chainLength() const
Definition: IOBufQueue.h:492

Member Data Documentation

size_t wangle::FixedLengthFrameDecoder::length_
private

Definition at line 58 of file FixedLengthFrameDecoder.h.

Referenced by decode().


The documentation for this class was generated from the following file: