proxygen
ByteToStringDecoder Class Reference
Inheritance diagram for ByteToStringDecoder:
wangle::ByteToMessageDecoder< std::string > wangle::InboundHandler< folly::IOBufQueue &, std::string > wangle::HandlerBase< InboundHandlerContext< std::string > >

Public Member Functions

bool decode (Context *, IOBufQueue &buf, std::string &result, size_t &) override
 
- Public Member Functions inherited from wangle::ByteToMessageDecoder< std::string >
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 &, std::string >
 ~InboundHandler () override=default
 
virtual void readEOF (Context *ctx)
 
virtual void readException (Context *ctx, folly::exception_wrapper e)
 
- Public Member Functions inherited from wangle::HandlerBase< InboundHandlerContext< std::string > >
virtual ~HandlerBase ()=default
 
virtual void attachPipeline (InboundHandlerContext< std::string > *)
 
virtual void detachPipeline (InboundHandlerContext< std::string > *)
 
InboundHandlerContext< std::string > * getContext ()
 

Additional Inherited Members

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

Detailed Description

Steps to run: 1) Run an upstream server that can broadcast messages:

nc -l localhost 8081

This starts a server on localhost:8081.

2) Start the broadcast proxy with the upstream_port set to 8081:

./broadcast_proxy –port 8080 –upstream_port 8081

This starts the proxy on localhost:8080 and sets the upstream server as localhost:8081

3) Start a new instances of telnet clients to connect to the broadcast proxy and listen to the messages broadcasted by the upstream server:

telnet localhost 8080

Send some bytes in the telnet terminals for broadcast_proxy to kick off the connection.

4) Type something in the nc terminal and notice that it is broadcasted to all the telnet clients. A simple decoder that decodes bytes in IOBufQueue to std::string. This is used in the BroadcastPipeline to convert bytes read from the upstream server's socket to strings of messages that can be broadcasted to all the clients/observers.

Definition at line 69 of file BroadcastProxy.cpp.

Member Function Documentation

bool ByteToStringDecoder::decode ( Context ctx,
IOBufQueue buf,
std::string result,
size_t &   
)
inlineoverridevirtual

Decode bytes from buf into result.

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

Implements wangle::ByteToMessageDecoder< std::string >.

Definition at line 71 of file BroadcastProxy.cpp.

References folly::IOBufQueue::chainLength(), and folly::IOBufQueue::move().

74  {
75  if (buf.chainLength() > 0) {
76  result = buf.move()->moveToFbString().toStdString();
77  return true;
78  }
79  return false;
80  }
size_t chainLength() const
Definition: IOBufQueue.h:492
std::unique_ptr< folly::IOBuf > move()
Definition: IOBufQueue.h:459

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