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 
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 AppendArray(const uint8_t* buf, size_t size);
52  void AppendBuffer(const BufferWriter& buffer);
53 
54  void Swap(BufferWriter* buffer) { buf_.swap(buffer->buf_); }
55  void SwapBuffer(std::vector<uint8_t>* buffer) { buf_.swap(*buffer); }
56 
57  void Clear() { buf_.clear(); }
58  size_t Size() const { return buf_.size(); }
60  const uint8_t* Buffer() const { return buf_.data(); }
61 
66  Status WriteToFile(File* file);
67 
68  private:
69  // Internal implementation of multi-byte write.
70  template <typename T>
71  void AppendInternal(T v);
72 
73  std::vector<uint8_t> buf_;
74 
75  DISALLOW_COPY_AND_ASSIGN(BufferWriter);
76 };
77 
78 } // namespace media
79 } // namespace shaka
80 
81 #endif // MEDIA_BASE_BUFFER_WRITER_H_
void AppendNBytes(uint64_t v, size_t num_bytes)
const uint8_t * Buffer() const
Definition: buffer_writer.h:60
Status WriteToFile(File *file)