From ece5cb83715dea85617114b6d4e981fdee2623ba Mon Sep 17 00:00:00 2001 From: Harald Alvestrand Date: Mon, 4 Dec 2023 19:38:16 +0000 Subject: [PATCH] Add char-based accessor functions to ByteBufferWriter These are added to ease the transition to uint8_t for downstream code. Bug: webrtc:15665 Change-Id: I571805b93ddd19be6f6990ce34f5c248a57f36b3 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/329763 Reviewed-by: Tomas Gunnarsson Commit-Queue: Harald Alvestrand Cr-Commit-Position: refs/heads/main@{#41315} --- rtc_base/byte_buffer.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/rtc_base/byte_buffer.h b/rtc_base/byte_buffer.h index 77c80680c1..c15773779e 100644 --- a/rtc_base/byte_buffer.h +++ b/rtc_base/byte_buffer.h @@ -41,6 +41,17 @@ class ByteBufferWriterT { const value_type* Data() const { return buffer_.data(); } size_t Length() const { return buffer_.size(); } size_t Capacity() const { return buffer_.capacity(); } + rtc::ArrayView DataView() const { + return rtc::MakeArrayView(Data(), Length()); + } + // Accessor that returns a string_view, independent of underlying type. + // Intended to provide access for existing users that expect char* + // when the underlying type changes to uint8_t. + // TODO(bugs.webrtc.org/15665): Delete when users are converted. + absl::string_view DataAsStringView() const { + return absl::string_view(reinterpret_cast(Data()), Length()); + } + char* DataAsCharPointer() const { return reinterpret_cast(Data()); } // Write value to the buffer. Resizes the buffer when it is // neccessary. @@ -152,7 +163,7 @@ class ByteBufferReader { // Returns number of unprocessed bytes. size_t Length() const { return end_ - start_; } // Returns a view of the unprocessed data. - rtc::ArrayView DataView() { + rtc::ArrayView DataView() const { return rtc::ArrayView(bytes_ + start_, end_ - start_); }