DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
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 MEDIA_BASE_BUFFER_WRITER_H_
8 #define 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 namespace media {
17 
18 class File;
19 
22 class BufferWriter {
23  public:
24  BufferWriter();
29  explicit BufferWriter(size_t reserved_size_in_bytes);
30  ~BufferWriter();
31 
35  void AppendInt(uint8_t v);
36  void AppendInt(uint16_t v);
37  void AppendInt(uint32_t v);
38  void AppendInt(uint64_t v);
39  void AppendInt(int16_t v);
40  void AppendInt(int32_t v);
41  void AppendInt(int64_t v);
43 
47  void AppendNBytes(uint64_t v, size_t num_bytes);
48 
49  void AppendVector(const std::vector<uint8_t>& v);
50  void AppendArray(const uint8_t* buf, size_t size);
51  void AppendBuffer(const BufferWriter& buffer);
52 
53  void Swap(BufferWriter* buffer) { buf_.swap(buffer->buf_); }
54  void SwapBuffer(std::vector<uint8_t>* buffer) { buf_.swap(*buffer); }
55 
56  void Clear() { buf_.clear(); }
57  size_t Size() const { return buf_.size(); }
59  const uint8_t* Buffer() const { return buf_.data(); }
60 
65  Status WriteToFile(File* file);
66 
67  private:
68  // Internal implementation of multi-byte write.
69  template <typename T>
70  void AppendInternal(T v);
71 
72  std::vector<uint8_t> buf_;
73 
74  DISALLOW_COPY_AND_ASSIGN(BufferWriter);
75 };
76 
77 } // namespace media
78 } // namespace shaka
79 
80 #endif // MEDIA_BASE_BUFFER_WRITER_H_
Define an abstract file interface.
Definition: file.h:24
void AppendNBytes(uint64_t v, size_t num_bytes)
const uint8_t * Buffer() const
Definition: buffer_writer.h:59
Status WriteToFile(File *file)