* Add Apple MD5 support in DeviceFiles [ Merge of http://go/wvgerrit/15544 ] Patch courtesy of Spotify. * Changing vague BufferReader log message [ Merge of http://go/wvgerrit/15515 ] Amending the buffer reader log message for null parameters in the read function to say the type of parameter to help tell the difference between Read2, Read2s, Read4, Read4s, Read8, and Read8s. Bug: 23619044 * Fix HTTP socket tests [ Merge of http://go/wvgerrit/15521 ] This fixes the build on Jenkins. I missed these when I updated HTTP socket because they are not part of the CE CDM test suite. * Update HttpSocket for IPv6 [ Merge of http://go/wvgerrit/15517 ] Previously, HttpSocket made assumptions about IPv4. This CL updates this utility to be agnostic to IPv4 vs IPv6. If our servers start resolving to IPv6 addresses in future, our tests can now handle this transparently. * Removed low level warnings from PSSH [ Merge of http://go/wvgerrit/15489 ] Unneeded warnings in parsing PSSH and in buffer reader were appearing in the logs. LOGW commands were replaced with LOGV. Bug: 23419359 * BufferReader unit tests and hardening. [ Merge of http://go/wvgerrit/15449 ] Added unit tests for public-facing functions. Added protection against null or negative parameters. Bug: 23419008 Change-Id: Ia44100a2d1bafe68986ae9a0793214885b21e61e
70 lines
2.0 KiB
C++
70 lines
2.0 KiB
C++
// Copyright 2012 Google Inc. All Rights Reserved.
|
|
|
|
#ifndef WVCDM_CORE_BUFFER_READER_H_
|
|
#define WVCDM_CORE_BUFFER_READER_H_
|
|
|
|
#include <stdint.h>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "wv_cdm_types.h"
|
|
|
|
namespace wvcdm {
|
|
|
|
// Annotate a function indicating the caller must examine the return value.
|
|
// Use like:
|
|
// int foo() WARN_UNUSED_RESULT;
|
|
// To explicitly ignore a result, see |ignore_result()| in <base/basictypes.h>.
|
|
#if defined(COMPILER_GCC)
|
|
#define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
|
|
#else
|
|
#define WARN_UNUSED_RESULT
|
|
#endif
|
|
|
|
class BufferReader {
|
|
public:
|
|
BufferReader(const uint8_t* buf, size_t size)
|
|
: buf_(buf), size_(buf != NULL ? size : 0), pos_(0) {}
|
|
|
|
bool HasBytes(size_t count) { return (pos() + count <= size()); }
|
|
|
|
// Read a value from the stream, performing endian correction,
|
|
// and advance the stream pointer.
|
|
bool Read1(uint8_t* v) WARN_UNUSED_RESULT;
|
|
bool Read2(uint16_t* v) WARN_UNUSED_RESULT;
|
|
bool Read2s(int16_t* v) WARN_UNUSED_RESULT;
|
|
bool Read4(uint32_t* v) WARN_UNUSED_RESULT;
|
|
bool Read4s(int32_t* v) WARN_UNUSED_RESULT;
|
|
bool Read8(uint64_t* v) WARN_UNUSED_RESULT;
|
|
bool Read8s(int64_t* v) WARN_UNUSED_RESULT;
|
|
|
|
bool ReadString(std::string* str, size_t count) WARN_UNUSED_RESULT;
|
|
bool ReadVec(std::vector<uint8_t>* t, size_t count) WARN_UNUSED_RESULT;
|
|
|
|
// These variants read a 4-byte integer of the corresponding signedness and
|
|
// store it in the 8-byte return type.
|
|
bool Read4Into8(uint64_t* v) WARN_UNUSED_RESULT;
|
|
bool Read4sInto8s(int64_t* v) WARN_UNUSED_RESULT;
|
|
|
|
// Advance the stream by this many bytes.
|
|
bool SkipBytes(size_t nbytes) WARN_UNUSED_RESULT;
|
|
|
|
const uint8_t* data() const { return buf_; }
|
|
size_t size() const { return size_; }
|
|
size_t pos() const { return pos_; }
|
|
|
|
protected:
|
|
const uint8_t* buf_;
|
|
size_t size_;
|
|
size_t pos_;
|
|
|
|
template <typename T>
|
|
bool Read(T* t) WARN_UNUSED_RESULT;
|
|
|
|
CORE_DISALLOW_COPY_AND_ASSIGN(BufferReader);
|
|
};
|
|
|
|
} // namespace wvcdm
|
|
|
|
#endif // WVCDM_CORE_BUFFER_READER_H_
|