Path: blob/master/Utilities/cmcppdap/src/content_stream.h
3153 views
// Copyright 2019 Google LLC1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// https://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314#ifndef dap_content_stream_h15#define dap_content_stream_h1617#include <deque>18#include <memory>19#include <string>2021#include <stdint.h>2223#include "dap/session.h"2425namespace dap {2627// Forward declarations28class Reader;29class Writer;3031class ContentReader {32public:33ContentReader() = default;34ContentReader(const std::shared_ptr<Reader>&,35const OnInvalidData on_invalid_data = kIgnore);36ContentReader& operator=(ContentReader&&) noexcept;3738bool isOpen();39void close();40std::string read();4142private:43bool scan(const uint8_t* seq, size_t len);44bool scan(const char* str);45bool match(const uint8_t* seq, size_t len);46bool match(const char* str);47char matchAny(const char* chars);48bool buffer(size_t bytes);49std::string badHeader();5051std::shared_ptr<Reader> reader;52std::deque<uint8_t> buf;53OnInvalidData on_invalid_data;54};5556class ContentWriter {57public:58ContentWriter() = default;59ContentWriter(const std::shared_ptr<Writer>&);60ContentWriter& operator=(ContentWriter&&) noexcept;6162bool isOpen();63void close();64bool write(const std::string&) const;6566private:67std::shared_ptr<Writer> writer;68};6970} // namespace dap7172#endif // dap_content_stream_h737475