• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CHROMIUMOS_WIDE_PROFILING_BUFFER_WRITER_H_
6 #define CHROMIUMOS_WIDE_PROFILING_BUFFER_WRITER_H_
7 
8 #include "data_writer.h"
9 
10 namespace quipper {
11 
12 // Writes data to a fixed-size memory buffer.
13 class BufferWriter : public DataWriter {
14  public:
15   // The destination buffer is indicated by |buffer| and is |size| bytes long.
BufferWriter(void * buffer,size_t size)16   BufferWriter(void* buffer, size_t size)
17       : buffer_(reinterpret_cast<char*>(buffer)), offset_(0) {
18     size_ = size;
19   }
20 
SeekSet(size_t offset)21   void SeekSet(size_t offset) override { offset_ = offset; }
22 
Tell()23   size_t Tell() const override { return offset_; }
24 
25   bool WriteData(const void* src, const size_t size) override;
26 
27   bool WriteString(const string& str, const size_t size) override;
28 
29  private:
30   bool CanWriteSize(size_t data_size) override;
31 
32   // Pointer to the data buffer. Does not own the buffer.
33   char* buffer_;
34 
35   // Current write offset, in bytes from start of buffer.
36   size_t offset_;
37 };
38 
39 }  // namespace quipper
40 
41 #endif  // CHROMIUMOS_WIDE_PROFILING_BUFFER_WRITER_H_
42