mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-12 21:30:45 +01:00
Use uint8_t as inner type for rtc::ByteBufferReader
Bug: webrtc:15661 Change-Id: Iefca01c953c4e69bebb1eb14391d0cfa6c69846e Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/327581 Reviewed-by: Per Kjellander <perkj@webrtc.org> Commit-Queue: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/main@{#41177}
This commit is contained in:
parent
0c501a1302
commit
72defe459b
2 changed files with 16 additions and 9 deletions
|
@ -20,22 +20,22 @@ ByteBufferWriter::ByteBufferWriter(const char* bytes, size_t len)
|
|||
: ByteBufferWriterT(bytes, len) {}
|
||||
|
||||
ByteBufferReader::ByteBufferReader(const char* bytes, size_t len) {
|
||||
Construct(bytes, len);
|
||||
Construct(reinterpret_cast<const uint8_t*>(bytes), len);
|
||||
}
|
||||
|
||||
ByteBufferReader::ByteBufferReader(const char* bytes) {
|
||||
Construct(bytes, strlen(bytes));
|
||||
Construct(reinterpret_cast<const uint8_t*>(bytes), strlen(bytes));
|
||||
}
|
||||
|
||||
ByteBufferReader::ByteBufferReader(const Buffer& buf) {
|
||||
Construct(buf.data<char>(), buf.size());
|
||||
Construct(buf.data(), buf.size());
|
||||
}
|
||||
|
||||
ByteBufferReader::ByteBufferReader(const ByteBufferWriter& buf) {
|
||||
Construct(buf.Data(), buf.Length());
|
||||
Construct(reinterpret_cast<const uint8_t*>(buf.Data()), buf.Length());
|
||||
}
|
||||
|
||||
void ByteBufferReader::Construct(const char* bytes, size_t len) {
|
||||
void ByteBufferReader::Construct(const uint8_t* bytes, size_t len) {
|
||||
bytes_ = bytes;
|
||||
size_ = len;
|
||||
start_ = 0;
|
||||
|
@ -134,7 +134,7 @@ bool ByteBufferReader::ReadString(std::string* val, size_t len) {
|
|||
if (len > Length()) {
|
||||
return false;
|
||||
} else {
|
||||
val->append(bytes_ + start_, len);
|
||||
val->append(reinterpret_cast<const char*>(bytes_ + start_), len);
|
||||
start_ += len;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -135,9 +135,16 @@ class ByteBufferReader {
|
|||
ByteBufferReader& operator=(const ByteBufferReader&) = delete;
|
||||
|
||||
// Returns start of unprocessed data.
|
||||
const char* Data() const { return bytes_ + start_; }
|
||||
// TODO(bugs.webrtc.org/15661): Deprecate and remove.
|
||||
const char* Data() const {
|
||||
return reinterpret_cast<const char*>(bytes_ + start_);
|
||||
}
|
||||
// Returns number of unprocessed bytes.
|
||||
size_t Length() const { return end_ - start_; }
|
||||
// Returns a view of the unprocessed data.
|
||||
rtc::ArrayView<const uint8_t> DataView() {
|
||||
return rtc::ArrayView<const uint8_t>(bytes_ + start_, end_ - start_);
|
||||
}
|
||||
|
||||
// Read a next value from the buffer. Return false if there isn't
|
||||
// enough data left for the specified type.
|
||||
|
@ -160,9 +167,9 @@ class ByteBufferReader {
|
|||
bool Consume(size_t size);
|
||||
|
||||
protected:
|
||||
void Construct(const char* bytes, size_t size);
|
||||
void Construct(const uint8_t* bytes, size_t size);
|
||||
|
||||
const char* bytes_;
|
||||
const uint8_t* bytes_;
|
||||
size_t size_;
|
||||
size_t start_;
|
||||
size_t end_;
|
||||
|
|
Loading…
Reference in a new issue