Telnet++  3.1.0.2
A C++ library for interacting with Telnet streams
codec.hpp
1 #pragma once
2 
3 #include "telnetpp/core.hpp"
4 
5 #include <boost/exception/all.hpp>
6 
7 #include <stdexcept>
8 
9 namespace telnetpp::options::mccp {
10 
11 //* =========================================================================
15 //* =========================================================================
16 class TELNETPP_EXPORT codec
17 {
18 public:
19  using continuation =
20  std::function<void(telnetpp::bytes data, bool continuation_ended)>;
21 
22  //* =====================================================================
24  //* =====================================================================
25  virtual ~codec() = default;
26 
27  //* =====================================================================
30  //* =====================================================================
31  void start();
32 
33  //* =====================================================================
36  //* =====================================================================
37  void finish(continuation const &cont);
38 
39  //* =====================================================================
45  //* =====================================================================
46  void operator()(telnetpp::bytes data, continuation const &cont);
47 
48 private:
49  //* =====================================================================
51  //* =====================================================================
52  virtual void do_start(){};
53 
54  //* =====================================================================
56  //* =====================================================================
57  virtual void do_finish(continuation const & /*cont*/){};
58 
59  //* =====================================================================
70  //* =====================================================================
71  virtual telnetpp::bytes transform_chunk(
72  telnetpp::bytes data, continuation const &continuation) = 0;
73 
74  bool engaged_{false};
75 };
76 
77 //* =========================================================================
80 //* =========================================================================
81 class TELNETPP_EXPORT corrupted_stream_error : virtual std::domain_error,
82  virtual boost::exception
83 {
84 public:
85  //* =====================================================================
87  //* =====================================================================
88  explicit corrupted_stream_error(char const *what_arg);
89 };
90 
91 } // namespace telnetpp::options::mccp
Represents an object that can transform (encode or decode) arbitrary byte sequences....
Definition: codec.hpp:17
virtual ~codec()=default
Destructor.
An exception that is thrown in the case that a stream of data cannot be decompressed.
Definition: codec.hpp:83
An implementation of the Mud Client Compression Protocol.
Definition: client.hpp:5