proxygen
wangle::ByteToMessageDecoder< M > Class Template Referenceabstract

#include <ByteToMessageDecoder.h>

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

Public Types

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
 

Public Member Functions

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

bool transportActive_ = true
 

Additional Inherited Members

- Static Public Attributes inherited from wangle::InboundHandler< folly::IOBufQueue &, M >
static const HandlerDir dir
 

Detailed Description

template<typename M>
class wangle::ByteToMessageDecoder< M >

A Handler which decodes bytes in a stream-like fashion from IOBufQueue to a Message type.

Frame detection

Generally frame detection should be handled earlier in the pipeline by adding a DelimiterBasedFrameDecoder, FixedLengthFrameDecoder, LengthFieldBasedFrameDecoder, LineBasedFrameDecoder.

If a custom frame decoder is required, then one needs to be careful when implementing one with ByteToMessageDecoder. Ensure there are enough bytes in the buffer for a complete frame by checking ByteBuf#readableBytes(). If there are not enough bytes for a complete frame, return without modify the reader index to allow more bytes to arrive.

To check for complete frames without modify the reader index, use IOBufQueue.front(), without split() or pop_front().

Definition at line 44 of file ByteToMessageDecoder.h.

Member Typedef Documentation

Definition at line 46 of file ByteToMessageDecoder.h.

Member Function Documentation

template<typename M>
virtual bool wangle::ByteToMessageDecoder< M >::decode ( Context ctx,
folly::IOBufQueue buf,
M result,
size_t &   
)
pure virtual

Decode bytes from buf into result.

Returns
bool - Return true if decoding is successful, false if buf has insufficient bytes.

Implemented in ByteToStringDecoder.

Referenced by wangle::ByteToMessageDecoder< T >::read().

template<typename M>
void wangle::ByteToMessageDecoder< M >::read ( Context ctx,
folly::IOBufQueue q 
)
inlineoverride

Definition at line 66 of file ByteToMessageDecoder.h.

66  {
67  bool success = true;
68  while (success && transportActive_) {
69  M result;
70  size_t needed = 0;
71  success = decode(ctx, q, result, needed);
72  if (success) {
73  ctx->fireRead(std::move(result));
74  }
75  }
76  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
virtual bool decode(Context *ctx, folly::IOBufQueue &buf, M &result, size_t &)=0
**Optimized Holders **The template hazptr_array< M > provides most of the functionality *of M hazptr_holder s but with faster construction destruction *for M
Definition: Hazptr.h:104
template<typename M>
void wangle::ByteToMessageDecoder< M >::transportActive ( Context ctx)
inlineoverride

Definition at line 56 of file ByteToMessageDecoder.h.

56  {
57  transportActive_ = true;
58  ctx->fireTransportActive();
59  }
template<typename M>
void wangle::ByteToMessageDecoder< M >::transportInactive ( Context ctx)
inlineoverride

Definition at line 61 of file ByteToMessageDecoder.h.

61  {
62  transportActive_ = false;
63  ctx->fireTransportInactive();
64  }

Member Data Documentation


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