summaryrefslogtreecommitdiff
path: root/src/codecs/include/source_buffer.hpp
blob: 6444dd2ce932062a557655c3b3ce6f6816980d17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
 * Copyright 2023 jacqueline <me@jacqueline.id.au>
 *
 * SPDX-License-Identifier: GPL-3.0-only
 */

#pragma once

#include <cstddef>
#include <cstdint>
#include <functional>
#include <span>

#include "codec.hpp"

namespace codecs {

class SourceBuffer {
 public:
  SourceBuffer();
  ~SourceBuffer();

  auto Refill(IStream* src) -> bool;
  auto AddBytes(std::function<size_t(std::span<std::byte>)> writer) -> void;
  auto ConsumeBytes(std::function<size_t(std::span<std::byte>)> reader) -> void;
  auto Empty() -> void;

  SourceBuffer(const SourceBuffer&) = delete;
  SourceBuffer& operator=(const SourceBuffer&) = delete;

 private:
  const std::span<std::byte> buffer_;
  size_t bytes_in_buffer_;
  size_t offset_of_bytes_;
};

}  // namespace codecs