Add ByteBufferReader constructor for ArrayView
Bug: webrtc:14870
Change-Id: I0643af4a44bb2bc26581df971221766316124996
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/327520
Auto-Submit: Per Kjellander <perkj@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#41182}
diff --git a/rtc_base/byte_buffer_unittest.cc b/rtc_base/byte_buffer_unittest.cc
index 4f8043c..615237c 100644
--- a/rtc_base/byte_buffer_unittest.cc
+++ b/rtc_base/byte_buffer_unittest.cc
@@ -12,6 +12,8 @@
#include <string.h>
+#include <cstdint>
+
#include "rtc_base/arraysize.h"
#include "rtc_base/byte_order.h"
#include "test/gtest.h"
@@ -247,4 +249,19 @@
EXPECT_EQ(size, read_buffer.Length());
}
+TEST(ByteBufferTest, ReadFromArrayView) {
+ const uint8_t buf[] = {'a', 'b', 'c'};
+ ArrayView<const uint8_t> view(buf, 3);
+
+ ByteBufferReader read_buffer(view);
+ uint8_t val;
+ EXPECT_TRUE(read_buffer.ReadUInt8(&val));
+ EXPECT_EQ(val, 'a');
+ EXPECT_TRUE(read_buffer.ReadUInt8(&val));
+ EXPECT_EQ(val, 'b');
+ EXPECT_TRUE(read_buffer.ReadUInt8(&val));
+ EXPECT_EQ(val, 'c');
+ EXPECT_FALSE(read_buffer.ReadUInt8(&val));
+}
+
} // namespace rtc