Shaka Packager SDK
Loading...
Searching...
No Matches
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 <cstddef>
11#include <cstdint>
12#include <string>
13#include <vector>
14
15#include <packager/macros/classes.h>
16#include <packager/status.h>
17
18namespace shaka {
19
20class File;
21
22namespace media {
23
27 public:
33 explicit BufferWriter(size_t reserved_size_in_bytes);
35
39 void AppendInt(uint8_t v);
40 void AppendInt(uint16_t v);
41 void AppendInt(uint32_t v);
42 void AppendInt(uint64_t v);
43 void AppendInt(int16_t v);
44 void AppendInt(int32_t v);
45 void AppendInt(int64_t v);
47
51 void AppendNBytes(uint64_t v, size_t num_bytes);
52
53 void AppendVector(const std::vector<uint8_t>& v);
54 void AppendString(const std::string& s);
55 void AppendArray(const uint8_t* buf, size_t size);
56 void AppendBuffer(const BufferWriter& buffer);
57
58 void Swap(BufferWriter* buffer) { buf_.swap(buffer->buf_); }
59 void SwapBuffer(std::vector<uint8_t>* buffer) { buf_.swap(*buffer); }
60
61 void Clear() { buf_.clear(); }
62 size_t Size() const { return buf_.size(); }
64 const uint8_t* Buffer() const { return buf_.data(); }
65
70 Status WriteToFile(File* file);
71
72 private:
73 // Internal implementation of multi-byte write.
74 template <typename T>
75 void AppendInternal(T v);
76
77 std::vector<uint8_t> buf_;
78
79 DISALLOW_COPY_AND_ASSIGN(BufferWriter);
80};
81
82} // namespace media
83} // namespace shaka
84
85#endif // PACKAGER_MEDIA_BASE_BUFFER_WRITER_H_
const uint8_t * Buffer() const
Status WriteToFile(File *file)
void AppendNBytes(uint64_t v, size_t num_bytes)
All the methods that are virtual are virtual for mocking.