1 //===-- StreamBuffer.h ------------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef liblldb_StreamBuffer_h_
10 #define liblldb_StreamBuffer_h_
12 #include "lldb/Utility/Stream.h"
13 #include "llvm/ADT/SmallVector.h"
17 namespace lldb_private {
19 template <unsigned N> class StreamBuffer : public Stream {
21 StreamBuffer() : Stream(0, 4, lldb::eByteOrderBig), m_packet() {}
23 StreamBuffer(uint32_t flags, uint32_t addr_size, lldb::ByteOrder byte_order)
24 : Stream(flags, addr_size, byte_order), m_packet() {}
26 ~StreamBuffer() override {}
28 void Flush() override {
29 // Nothing to do when flushing a buffer based stream...
32 void Clear() { m_packet.clear(); }
34 // Beware, this might not be NULL terminated as you can expect from
35 // StringString as there may be random bits in the llvm::SmallVector. If you
36 // are using this class to create a C string, be sure the call PutChar ('\0')
37 // after you have created your string, or use StreamString.
38 const char *GetData() const { return m_packet.data(); }
40 size_t GetSize() const { return m_packet.size(); }
43 llvm::SmallVector<char, N> m_packet;
45 size_t WriteImpl(const void *s, size_t length) override {
47 m_packet.append((const char *)s, ((const char *)s) + length);
52 } // namespace lldb_private
54 #endif // #ifndef liblldb_StreamBuffer_h_