Revert "Remove deprecated ByteBufferReader and ByteBufferWriter functions"
This reverts commit e0e03ba73a0859924a55c4dfa4ce20ff80820f0b.
Reason for revert: Speculative rollback (breaks WebKit Linux Leak)
Original change's description:
> Remove deprecated ByteBufferReader and ByteBufferWriter functions
>
> This completes the conversion of ByteBufferReader and ByteBufferWriter
> to uint8_t.
>
> No-Try: True
> Bug: webrtc:15661
> Change-Id: I4152a8a4fd2462282d4107b3c2eed19acc8b29b0
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/331640
> Commit-Queue: Harald Alvestrand <hta@webrtc.org>
> Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
> Cr-Commit-Position: refs/heads/main@{#41403}
Bug: webrtc:15661, chromium:1513059
Change-Id: I3938b8209f5cc1596307deadac157a8f6c2b2253
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/331940
Owners-Override: Mirko Bonadei <mbonadei@webrtc.org>
Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#41411}
diff --git a/api/transport/stun.cc b/api/transport/stun.cc
index c359fd3..97da508 100644
--- a/api/transport/stun.cc
+++ b/api/transport/stun.cc
@@ -587,7 +587,7 @@
bool StunMessage::Read(ByteBufferReader* buf) {
// Keep a copy of the buffer data around for later verification.
- buffer_.assign(reinterpret_cast<const char*>(buf->Data()), buf->Length());
+ buffer_.assign(buf->Data(), buf->Length());
if (!buf->ReadUInt16(&type_)) {
return false;
diff --git a/p2p/base/pseudo_tcp.cc b/p2p/base/pseudo_tcp.cc
index 3aaa2ad..9dec580 100644
--- a/p2p/base/pseudo_tcp.cc
+++ b/p2p/base/pseudo_tcp.cc
@@ -1213,7 +1213,7 @@
// Content of this option.
if (opt_len <= buf.Length()) {
- applyOption(kind, reinterpret_cast<const char*>(buf.Data()), opt_len);
+ applyOption(kind, buf.Data(), opt_len);
buf.Consume(opt_len);
} else {
RTC_LOG(LS_ERROR) << "Invalid option length received.";
diff --git a/rtc_base/byte_buffer.cc b/rtc_base/byte_buffer.cc
index 121097b..8c35956 100644
--- a/rtc_base/byte_buffer.cc
+++ b/rtc_base/byte_buffer.cc
@@ -139,6 +139,10 @@
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()) {
diff --git a/rtc_base/byte_buffer.h b/rtc_base/byte_buffer.h
index 6df285a..9e169f2 100644
--- a/rtc_base/byte_buffer.h
+++ b/rtc_base/byte_buffer.h
@@ -100,6 +100,12 @@
void WriteBytes(const uint8_t* val, size_t len) {
WriteBytesInternal(reinterpret_cast<const value_type*>(val), len);
}
+ // For backwards compatibility: Write an array of char
+ // TODO(bugs.webrtc.org/15665): Remove when users converted
+ [[deprecated("Use WriteString")]] void WriteBytes(const char* val,
+ size_t len) {
+ WriteBytesInternal(reinterpret_cast<const value_type*>(val), len);
+ }
// Reserves the given number of bytes and returns a value_type* that can be
// written into. Useful for functions that require a value_type* buffer and
@@ -157,10 +163,14 @@
ByteBufferReader(const ByteBufferReader&) = delete;
ByteBufferReader& operator=(const ByteBufferReader&) = delete;
- const uint8_t* Data() const { return bytes_ + start_; }
+ // Returns start of unprocessed data.
+ // 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. Does not move current position.
+ // Returns a view of the unprocessed data.
rtc::ArrayView<const uint8_t> DataView() const {
return rtc::ArrayView<const uint8_t>(bytes_ + start_, end_ - start_);
}
@@ -173,8 +183,11 @@
bool ReadUInt32(uint32_t* val);
bool ReadUInt64(uint64_t* val);
bool ReadUVarint(uint64_t* val);
- // Copies the val.size() next bytes into val.data().
bool ReadBytes(rtc::ArrayView<uint8_t> val);
+ // For backwards compatibility.
+ // TODO(bugs.webrtc.org/15661): Deprecate and remove.
+ [[deprecated("Read using ArrayView")]] bool ReadBytes(char* val, size_t len);
+
// Appends next `len` bytes from the buffer to `val`. Returns false
// if there is less than `len` bytes left.
bool ReadString(std::string* val, size_t len);
diff --git a/rtc_base/server_socket_adapters.cc b/rtc_base/server_socket_adapters.cc
index 0bef752..47c19cb 100644
--- a/rtc_base/server_socket_adapters.cc
+++ b/rtc_base/server_socket_adapters.cc
@@ -75,9 +75,7 @@
// Consume parsed data
*len = response.Length();
- if (response.Length() > 0) {
- memmove(data, response.DataView().data(), *len);
- }
+ memmove(data, response.Data(), *len);
}
void AsyncSocksProxyServerSocket::DirectSend(const ByteBufferWriter& buf) {