Shaka Packager SDK
buffer_writer.h
1 // Copyright 2014 Google Inc. 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 <vector>
11 
12 #include "packager/base/macros.h"
13 #include "packager/status.h"
14 
15 namespace shaka {
16 
17 class File;
18 
19 namespace media {
20 
23 class BufferWriter {
24  public:
25  BufferWriter();
30  explicit BufferWriter(size_t reserved_size_in_bytes);
31  ~BufferWriter();
32 
36  void AppendInt(uint8_t v);
37  void AppendInt(uint16_t v);
38  void AppendInt(uint32_t v);
39  void AppendInt(uint64_t v);
40  void AppendInt(int16_t v);
41  void AppendInt(int32_t v);
42  void AppendInt(int64_t v);
44 
48  void AppendNBytes(uint64_t v, size_t num_bytes);
49 
50  void AppendVector(const std::vector<uint8_t>& v);
51  void AppendString(const std::string& s);
52  void AppendArray(const uint8_t* buf, size_t size);
53  void AppendBuffer(const BufferWriter& buffer);
54 
55  void Swap(BufferWriter* buffer) { buf_.swap(buffer->buf_); }
56  void SwapBuffer(std::vector<uint8_t>* buffer) { buf_.swap(*buffer); }
57 
58  void Clear() { buf_.clear(); }
59  size_t Size() const { return buf_.size(); }
61  const uint8_t* Buffer() const { return buf_.data(); }
62 
67  Status WriteToFile(File* file);
68 
69  private:
70  // Internal implementation of multi-byte write.
71  template <typename T>
72  void AppendInternal(T v);
73 
74  std::vector<uint8_t> buf_;
75 
76  DISALLOW_COPY_AND_ASSIGN(BufferWriter);
77 };
78 
79 } // namespace media
80 } // namespace shaka
81 
82 #endif // PACKAGER_MEDIA_BASE_BUFFER_WRITER_H_
shaka::media::BufferWriter
Definition: buffer_writer.h:23
shaka
All the methods that are virtual are virtual for mocking.
Definition: gflags_hex_bytes.cc:11
shaka::media::BufferWriter::Buffer
const uint8_t * Buffer() const
Definition: buffer_writer.h:61
shaka::media::BufferWriter::AppendInt
void AppendInt(uint8_t v)
Definition: buffer_writer.cc:25
shaka::Status
Definition: status.h:110
shaka::media::BufferWriter::WriteToFile
Status WriteToFile(File *file)
Definition: buffer_writer.cc:70
shaka::media::BufferWriter::AppendNBytes
void AppendNBytes(uint64_t v, size_t num_bytes)
Definition: buffer_writer.cc:47
shaka::File
Define an abstract file interface.
Definition: file.h:28