blob: 6387c818c7ef61e2f270311536c6981adc6b8c77 [file] [log] [blame]
Bence Békybac04052022-04-07 15:44:29 -04001// 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#include "quiche/spdy/core/zero_copy_output_buffer.h"
10
11namespace spdy {
12
13class ArrayOutputBuffer : public ZeroCopyOutputBuffer {
14 public:
15 // |buffer| is pointed to the output to write to, and |size| is the capacity
16 // of the output.
17 ArrayOutputBuffer(char* buffer, int64_t size)
18 : current_(buffer), begin_(buffer), capacity_(size) {}
19 ~ArrayOutputBuffer() override {}
20
21 ArrayOutputBuffer(const ArrayOutputBuffer&) = delete;
22 ArrayOutputBuffer& operator=(const ArrayOutputBuffer&) = delete;
23
24 void Next(char** data, int* size) override;
25 void AdvanceWritePtr(int64_t count) override;
26 uint64_t BytesFree() const override;
27
28 size_t Size() const { return current_ - begin_; }
29 char* Begin() const { return begin_; }
30
31 // Resets the buffer to its original state.
32 void Reset() {
33 capacity_ += Size();
34 current_ = begin_;
35 }
36
37 private:
38 char* current_ = nullptr;
39 char* begin_ = nullptr;
40 uint64_t capacity_ = 0;
41};
42
43} // namespace spdy
44
45#endif // QUICHE_SPDY_CORE_ARRAY_OUTPUT_BUFFER_H_