Add ReadStringView() to ByteBufferReader
ReadStringView() is a simple alternative to ReadString() but doesn't
involve a heap allocation for a new std::string.
Using the new methods in one place to start with.
Bug: none
Change-Id: I1100c6d258ffb4c8a31a46ba88a7f8bff9cf35cb
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/332120
Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#41533}
diff --git a/rtc_base/byte_buffer.h b/rtc_base/byte_buffer.h
index 6df285a..1508bd6 100644
--- a/rtc_base/byte_buffer.h
+++ b/rtc_base/byte_buffer.h
@@ -178,6 +178,9 @@
// 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);
+ // Same as `ReadString` except that the returned string_view will point into
+ // the internal buffer (no additional buffer allocation).
+ bool ReadStringView(absl::string_view* val, size_t len);
// Moves current position `size` bytes forward. Returns false if
// there is less than `size` bytes left in the buffer. Consume doesn't