summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/rtc_base/byte_buffer.cc
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/libwebrtc/rtc_base/byte_buffer.cc')
-rw-r--r--third_party/libwebrtc/rtc_base/byte_buffer.cc54
1 files changed, 34 insertions, 20 deletions
diff --git a/third_party/libwebrtc/rtc_base/byte_buffer.cc b/third_party/libwebrtc/rtc_base/byte_buffer.cc
index e1278337a4..a076f46ecb 100644
--- a/third_party/libwebrtc/rtc_base/byte_buffer.cc
+++ b/third_party/libwebrtc/rtc_base/byte_buffer.cc
@@ -19,23 +19,23 @@ ByteBufferWriter::ByteBufferWriter() : ByteBufferWriterT() {}
ByteBufferWriter::ByteBufferWriter(const char* bytes, size_t len)
: ByteBufferWriterT(bytes, len) {}
-ByteBufferReader::ByteBufferReader(const char* bytes, size_t len) {
- Construct(bytes, len);
+ByteBufferReader::ByteBufferReader(rtc::ArrayView<const uint8_t> bytes) {
+ Construct(bytes.data(), bytes.size());
}
-ByteBufferReader::ByteBufferReader(const char* bytes) {
- Construct(bytes, strlen(bytes));
+ByteBufferReader::ByteBufferReader(const char* bytes, size_t len) {
+ Construct(reinterpret_cast<const uint8_t*>(bytes), len);
}
-ByteBufferReader::ByteBufferReader(const Buffer& buf) {
- Construct(buf.data<char>(), buf.size());
+ByteBufferReader::ByteBufferReader(const char* bytes) {
+ Construct(reinterpret_cast<const uint8_t*>(bytes), strlen(bytes));
}
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;
@@ -46,7 +46,7 @@ bool ByteBufferReader::ReadUInt8(uint8_t* val) {
if (!val)
return false;
- return ReadBytes(reinterpret_cast<char*>(val), 1);
+ return ReadBytes(val, 1);
}
bool ByteBufferReader::ReadUInt16(uint16_t* val) {
@@ -54,7 +54,7 @@ bool ByteBufferReader::ReadUInt16(uint16_t* val) {
return false;
uint16_t v;
- if (!ReadBytes(reinterpret_cast<char*>(&v), 2)) {
+ if (!ReadBytes(reinterpret_cast<uint8_t*>(&v), 2)) {
return false;
} else {
*val = NetworkToHost16(v);
@@ -67,7 +67,7 @@ bool ByteBufferReader::ReadUInt24(uint32_t* val) {
return false;
uint32_t v = 0;
- char* read_into = reinterpret_cast<char*>(&v);
+ uint8_t* read_into = reinterpret_cast<uint8_t*>(&v);
++read_into;
if (!ReadBytes(read_into, 3)) {
@@ -83,7 +83,7 @@ bool ByteBufferReader::ReadUInt32(uint32_t* val) {
return false;
uint32_t v;
- if (!ReadBytes(reinterpret_cast<char*>(&v), 4)) {
+ if (!ReadBytes(reinterpret_cast<uint8_t*>(&v), 4)) {
return false;
} else {
*val = NetworkToHost32(v);
@@ -96,7 +96,7 @@ bool ByteBufferReader::ReadUInt64(uint64_t* val) {
return false;
uint64_t v;
- if (!ReadBytes(reinterpret_cast<char*>(&v), 8)) {
+ if (!ReadBytes(reinterpret_cast<uint8_t*>(&v), 8)) {
return false;
} else {
*val = NetworkToHost64(v);
@@ -112,14 +112,14 @@ bool ByteBufferReader::ReadUVarint(uint64_t* val) {
// continuation byte (msb=1) if there are more bytes to be read.
uint64_t v = 0;
for (int i = 0; i < 64; i += 7) {
- char byte;
+ uint8_t byte;
if (!ReadBytes(&byte, 1)) {
return false;
}
// Read the first 7 bits of the byte, then offset by bits read so far.
v |= (static_cast<uint64_t>(byte) & 0x7F) << i;
- // True if the msb is not a continuation byte.
- if (static_cast<uint64_t>(byte) < 0x80) {
+ // Return if the msb is not a continuation byte.
+ if (byte < 0x80) {
*val = v;
return true;
}
@@ -134,20 +134,34 @@ 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;
}
}
+bool ByteBufferReader::ReadBytes(rtc::ArrayView<uint8_t> val) {
+ if (val.size() == 0) {
+ return true;
+ }
+ return ReadBytes(val.data(), val.size());
+}
+
bool ByteBufferReader::ReadBytes(char* val, size_t len) {
+ return ReadBytes(reinterpret_cast<uint8_t*>(val), len);
+}
+
+// Private function supporting the other Read* functions.
+bool ByteBufferReader::ReadBytes(uint8_t* val, size_t len) {
if (len > Length()) {
return false;
- } else {
- memcpy(val, bytes_ + start_, len);
- start_ += len;
+ }
+ if (len == 0) {
return true;
}
+ memcpy(val, bytes_ + start_, len);
+ start_ += len;
+ return true;
}
bool ByteBufferReader::Consume(size_t size) {