7 #include "packager/media/base/buffer_reader.h"
9 #include "packager/base/logging.h"
11 namespace edash_packager {
22 bool BufferReader::Read2(uint16_t* v) {
25 bool BufferReader::Read2s(int16_t* v) {
28 bool BufferReader::Read4(uint32_t* v) {
31 bool BufferReader::Read4s(int32_t* v) {
34 bool BufferReader::Read8(uint64_t* v) {
37 bool BufferReader::Read8s(int64_t* v) {
41 return ReadNBytes(v, num_bytes);
43 bool BufferReader::ReadNBytesInto8s(int64_t* v,
size_t num_bytes) {
44 return ReadNBytes(v, num_bytes);
47 bool BufferReader::ReadToVector(std::vector<uint8_t>* vec,
size_t count) {
51 vec->assign(buf_ + pos_, buf_ + pos_ + count);
64 bool BufferReader::Read(T* v) {
65 return ReadNBytes(v,
sizeof(*v));
69 bool BufferReader::ReadNBytes(T* v,
size_t num_bytes) {
71 DCHECK_LE(num_bytes,
sizeof(*v));
78 const bool sign_extension_required =
79 num_bytes < sizeof(*v) && static_cast<T>(-1) < 0;
82 T tmp = sign_extension_required ?
static_cast<int8_t
>(buf_[pos_++])
84 for (
size_t i = 1; i < num_bytes; ++i) {