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 | namespace dap { |
25 | |
26 | // Forward declarations |
27 | class Reader; |
28 | class Writer; |
29 | |
30 | class ContentReader { |
31 | public: |
32 | ContentReader() = default; |
33 | ContentReader(const std::shared_ptr<Reader>&); |
34 | ContentReader& operator=(ContentReader&&) noexcept; |
35 | |
36 | bool isOpen(); |
37 | void close(); |
38 | std::string read(); |
39 | |
40 | private: |
41 | bool scan(const uint8_t* seq, size_t len); |
42 | bool scan(const char* str); |
43 | bool match(const uint8_t* seq, size_t len); |
44 | bool match(const char* str); |
45 | char matchAny(const char* chars); |
46 | bool buffer(size_t bytes); |
47 | |
48 | std::shared_ptr<Reader> reader; |
49 | std::deque<uint8_t> buf; |
50 | uint32_t matched_idx = 0; |
51 | }; |
52 | |
53 | class ContentWriter { |
54 | public: |
55 | ContentWriter() = default; |
56 | ContentWriter(const std::shared_ptr<Writer>&); |
57 | ContentWriter& operator=(ContentWriter&&) noexcept; |
58 | |
59 | bool isOpen(); |
60 | void close(); |
61 | bool write(const std::string&) const; |
62 | |
63 | private: |
64 | std::shared_ptr<Writer> writer; |
65 | }; |
66 | |
67 | } // namespace dap |
68 | |
69 | #endif // dap_content_stream_h |
70 | |