/src/CMake/Utilities/cmcppdap/src/content_stream.h
Line | Count | Source |
1 | | // Copyright 2019 Google LLC |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // https://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | #ifndef dap_content_stream_h |
16 | | #define dap_content_stream_h |
17 | | |
18 | | #include <deque> |
19 | | #include <memory> |
20 | | #include <string> |
21 | | |
22 | | #include <stdint.h> |
23 | | |
24 | | #include "dap/session.h" |
25 | | |
26 | | namespace dap { |
27 | | |
28 | | // Forward declarations |
29 | | class Reader; |
30 | | class Writer; |
31 | | |
32 | | class ContentReader { |
33 | | public: |
34 | 0 | ContentReader() = default; |
35 | | ContentReader(const std::shared_ptr<Reader>&, |
36 | | const OnInvalidData on_invalid_data = kIgnore); |
37 | | ContentReader& operator=(ContentReader&&) noexcept; |
38 | | |
39 | | bool isOpen(); |
40 | | void close(); |
41 | | std::string read(); |
42 | | |
43 | | private: |
44 | | bool scan(const uint8_t* seq, size_t len); |
45 | | bool scan(const char* str); |
46 | | bool match(const uint8_t* seq, size_t len); |
47 | | bool match(const char* str); |
48 | | char matchAny(const char* chars); |
49 | | bool buffer(size_t bytes); |
50 | | std::string badHeader(); |
51 | | |
52 | | std::shared_ptr<Reader> reader; |
53 | | std::deque<uint8_t> buf; |
54 | | OnInvalidData on_invalid_data; |
55 | | }; |
56 | | |
57 | | class ContentWriter { |
58 | | public: |
59 | 0 | ContentWriter() = default; |
60 | | ContentWriter(const std::shared_ptr<Writer>&); |
61 | | ContentWriter& operator=(ContentWriter&&) noexcept; |
62 | | |
63 | | bool isOpen(); |
64 | | void close(); |
65 | | bool write(const std::string&) const; |
66 | | |
67 | | private: |
68 | | std::shared_ptr<Writer> writer; |
69 | | }; |
70 | | |
71 | | } // namespace dap |
72 | | |
73 | | #endif // dap_content_stream_h |