Cuberite
A lightweight, fast and extensible game server for Minecraft
TransferEncodingParser.h
Go to the documentation of this file.
1 
2 // TransferEncodingParser.h
3 
4 // Declares the cTransferEncodingParser class representing the parser for the various transfer encodings (chunked etc.)
5 
6 #pragma once
7 
8 
9 
10 
11 
12 // fwd:
14 typedef std::shared_ptr<cTransferEncodingParser> cTransferEncodingParserPtr;
15 
16 
17 
18 
19 
22 {
23 public:
24  class cCallbacks
25  {
26  public:
27  // Force a virtual destructor in descendants
28  virtual ~cCallbacks() {}
29 
31  virtual void OnError(const AString & a_ErrorDescription) = 0;
32 
34  virtual void OnBodyData(const void * a_Data, size_t a_Size) = 0;
35 
37  virtual void OnBodyFinished(void) = 0;
38  };
39 
40 
41  // Force a virtual destructor in all descendants
43 
47  virtual size_t Parse(const char * a_Data, size_t a_Size) = 0;
48 
51  virtual void Finish(void) = 0;
52 
58  cCallbacks & a_Callbacks,
59  const AString & a_TransferEncoding,
60  size_t a_ContentLength
61  );
62 
63 protected:
66 
67 
69  m_Callbacks(a_Callbacks)
70  {
71  }
72 };
73 
74 
75 
76 
std::shared_ptr< cTransferEncodingParser > cTransferEncodingParserPtr
std::string AString
Definition: StringUtils.h:11
Used as both the interface that all the parsers share and the (static) factory creating such parsers.
virtual size_t Parse(const char *a_Data, size_t a_Size)=0
Parses the incoming data and calls the appropriate callbacks.
cCallbacks & m_Callbacks
The callbacks used to report progress.
virtual void Finish(void)=0
To be called when the stream is terminated from the source (connection closed).
cTransferEncodingParser(cCallbacks &a_Callbacks)
static cTransferEncodingParserPtr Create(cCallbacks &a_Callbacks, const AString &a_TransferEncoding, size_t a_ContentLength)
Creates a new parser for the specified encoding.
virtual void OnError(const AString &a_ErrorDescription)=0
Called when an error has occured while parsing.
virtual void OnBodyData(const void *a_Data, size_t a_Size)=0
Called for each chunk of the incoming body data.
virtual void OnBodyFinished(void)=0
Called when the entire body has been reported by OnBodyData().