Shaka Packager SDK
buffer_writer.h
1 // Copyright 2014 Google LLC. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file or at
5 // https://developers.google.com/open-source/licenses/bsd
6 
7 #ifndef PACKAGER_MEDIA_BASE_BUFFER_WRITER_H_
8 #define PACKAGER_MEDIA_BASE_BUFFER_WRITER_H_
9 
10 #include <cstdint>
11 #include <vector>
12 
13 #include <packager/macros/classes.h>
14 #include <packager/status.h>
15 
16 namespace shaka {
17 
18 class File;
19 
20 namespace media {
21 
24 class BufferWriter {
25  public:
26  BufferWriter();
31  explicit BufferWriter(size_t reserved_size_in_bytes);
32  ~BufferWriter();
33 
37  void AppendInt(uint8_t v);
38  void AppendInt(uint16_t v);
39  void AppendInt(uint32_t v);
40  void AppendInt(uint64_t v);
41  void AppendInt(int16_t v);
42  void AppendInt(int32_t v);
43  void AppendInt(int64_t v);
45 
49  void AppendNBytes(uint64_t v, size_t num_bytes);
50 
51  void AppendVector(const std::vector<uint8_t>& v);
52  void AppendString(const std::string& s);
53  void AppendArray(const uint8_t* buf, size_t size);
54  void AppendBuffer(const BufferWriter& buffer);
55 
56  void Swap(BufferWriter* buffer) { buf_.swap(buffer->buf_); }
57  void SwapBuffer(std::vector<uint8_t>* buffer) { buf_.swap(*buffer); }
58 
59  void Clear() { buf_.clear(); }
60  size_t Size() const { return buf_.size(); }
62  const uint8_t* Buffer() const { return buf_.data(); }
63 
68  Status WriteToFile(File* file);
69 
70  private:
71  // Internal implementation of multi-byte write.
72  template <typename T>
73  void AppendInternal(T v);
74 
75  std::vector<uint8_t> buf_;
76 
77  DISALLOW_COPY_AND_ASSIGN(BufferWriter);
78 };
79 
80 } // namespace media
81 } // namespace shaka
82 
83 #endif // PACKAGER_MEDIA_BASE_BUFFER_WRITER_H_
Status WriteToFile(File *file)
const uint8_t * Buffer() const
Definition: buffer_writer.h:62
void AppendNBytes(uint64_t v, size_t num_bytes)
All the methods that are virtual are virtual for mocking.
Definition: crypto_flags.cc:66