7 #include <packager/media/base/buffer_reader.h>
9 #include <absl/log/check.h>
10 #include <absl/log/log.h>
23 bool BufferReader::Read2(uint16_t* v) {
26 bool BufferReader::Read2s(int16_t* v) {
29 bool BufferReader::Read4(uint32_t* v) {
32 bool BufferReader::Read4s(int32_t* v) {
35 bool BufferReader::Read8(uint64_t* v) {
38 bool BufferReader::Read8s(int64_t* v) {
42 return ReadNBytes(v, num_bytes);
44 bool BufferReader::ReadNBytesInto8s(int64_t* v,
size_t num_bytes) {
45 return ReadNBytes(v, num_bytes);
48 bool BufferReader::ReadToVector(std::vector<uint8_t>* vec,
size_t count) {
52 vec->assign(buf_ + pos_, buf_ + pos_ + count);
57 bool BufferReader::ReadToString(std::string* str,
size_t size) {
61 str->assign(buf_ + pos_, buf_ + pos_ + size);
68 for (
size_t count = 0; pos_ + count < size_; count++) {
69 if (buf_[pos_ + count] == 0) {
70 str->assign(buf_ + pos_, buf_ + pos_ + count);
86 bool BufferReader::Read(T* v) {
87 return ReadNBytes(v,
sizeof(*v));
91 bool BufferReader::ReadNBytes(T* v,
size_t num_bytes) {
93 DCHECK_LE(num_bytes,
sizeof(*v));
100 const bool sign_extension_required =
101 num_bytes < sizeof(*v) && static_cast<T>(-1) < 0;
104 T tmp = sign_extension_required ?
static_cast<int8_t
>(buf_[pos_++])
106 for (
size_t i = 1; i < num_bytes; ++i) {
All the methods that are virtual are virtual for mocking.