• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The Chromium 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 QUICHE_SPDY_CORE_ARRAY_OUTPUT_BUFFER_H_
6 #define QUICHE_SPDY_CORE_ARRAY_OUTPUT_BUFFER_H_
7 
8 #include <cstddef>
9 
10 #include "quiche/common/platform/api/quiche_export.h"
11 #include "quiche/spdy/core/zero_copy_output_buffer.h"
12 
13 namespace spdy {
14 
15 class QUICHE_EXPORT ArrayOutputBuffer : public ZeroCopyOutputBuffer {
16  public:
17   // |buffer| is pointed to the output to write to, and |size| is the capacity
18   // of the output.
ArrayOutputBuffer(char * buffer,int64_t size)19   ArrayOutputBuffer(char* buffer, int64_t size)
20       : current_(buffer), begin_(buffer), capacity_(size) {}
~ArrayOutputBuffer()21   ~ArrayOutputBuffer() override {}
22 
23   ArrayOutputBuffer(const ArrayOutputBuffer&) = delete;
24   ArrayOutputBuffer& operator=(const ArrayOutputBuffer&) = delete;
25 
26   void Next(char** data, int* size) override;
27   void AdvanceWritePtr(int64_t count) override;
28   uint64_t BytesFree() const override;
29 
Size()30   size_t Size() const { return current_ - begin_; }
Begin()31   char* Begin() const { return begin_; }
32 
33   // Resets the buffer to its original state.
Reset()34   void Reset() {
35     capacity_ += Size();
36     current_ = begin_;
37   }
38 
39  private:
40   char* current_ = nullptr;
41   char* begin_ = nullptr;
42   uint64_t capacity_ = 0;
43 };
44 
45 }  // namespace spdy
46 
47 #endif  // QUICHE_SPDY_CORE_ARRAY_OUTPUT_BUFFER_H_
48