[tools][utils] Split BufferReader out to separate files

This was already done for BufferWriter, but for some reason BufferReader got missed.

Change-Id: I633f195ca76abe1f2ea5e65c73ee95387ce97560
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/185363
Reviewed-by: dan sinclair <dsinclair@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
diff --git a/src/tint/cmd/fuzz/ir/fuzz.h b/src/tint/cmd/fuzz/ir/fuzz.h
index 533cac4..18ffdce 100644
--- a/src/tint/cmd/fuzz/ir/fuzz.h
+++ b/src/tint/cmd/fuzz/ir/fuzz.h
@@ -33,6 +33,7 @@
 #include <tuple>
 #include <utility>
 
+#include "src/tint/utils/bytes/buffer_reader.h"
 #include "src/tint/utils/bytes/decoder.h"
 #include "src/tint/utils/containers/slice.h"
 #include "src/tint/utils/macros/static_init.h"
diff --git a/src/tint/cmd/fuzz/wgsl/fuzz.h b/src/tint/cmd/fuzz/wgsl/fuzz.h
index c01455b..e4bc7a0 100644
--- a/src/tint/cmd/fuzz/wgsl/fuzz.h
+++ b/src/tint/cmd/fuzz/wgsl/fuzz.h
@@ -33,6 +33,7 @@
 #include <utility>
 
 #include "src/tint/lang/wgsl/program/program.h"
+#include "src/tint/utils/bytes/buffer_reader.h"
 #include "src/tint/utils/bytes/decoder.h"
 #include "src/tint/utils/containers/slice.h"
 #include "src/tint/utils/macros/static_init.h"
diff --git a/src/tint/utils/bytes/BUILD.bazel b/src/tint/utils/bytes/BUILD.bazel
index 3b0bb76..3daeace 100644
--- a/src/tint/utils/bytes/BUILD.bazel
+++ b/src/tint/utils/bytes/BUILD.bazel
@@ -39,11 +39,13 @@
 cc_library(
   name = "bytes",
   srcs = [
+    "buffer_reader.cc",
     "bytes.cc",
     "reader.cc",
     "writer.cc",
   ],
   hdrs = [
+    "buffer_reader.h",
     "buffer_writer.h",
     "decoder.h",
     "endianness.h",
@@ -71,9 +73,9 @@
   name = "test",
   alwayslink = True,
   srcs = [
+    "buffer_reader_test.cc",
     "buffer_writer_test.cc",
     "decoder_test.cc",
-    "reader_test.cc",
     "swap_test.cc",
   ],
   deps = [
diff --git a/src/tint/utils/bytes/BUILD.cmake b/src/tint/utils/bytes/BUILD.cmake
index 6d919d3..3438bbb 100644
--- a/src/tint/utils/bytes/BUILD.cmake
+++ b/src/tint/utils/bytes/BUILD.cmake
@@ -39,6 +39,8 @@
 # Kind:      lib
 ################################################################################
 tint_add_target(tint_utils_bytes lib
+  utils/bytes/buffer_reader.cc
+  utils/bytes/buffer_reader.h
   utils/bytes/buffer_writer.h
   utils/bytes/bytes.cc
   utils/bytes/decoder.h
@@ -69,9 +71,9 @@
 # Kind:      test
 ################################################################################
 tint_add_target(tint_utils_bytes_test test
+  utils/bytes/buffer_reader_test.cc
   utils/bytes/buffer_writer_test.cc
   utils/bytes/decoder_test.cc
-  utils/bytes/reader_test.cc
   utils/bytes/swap_test.cc
 )
 
diff --git a/src/tint/utils/bytes/BUILD.gn b/src/tint/utils/bytes/BUILD.gn
index d3babe2..6618381 100644
--- a/src/tint/utils/bytes/BUILD.gn
+++ b/src/tint/utils/bytes/BUILD.gn
@@ -44,6 +44,8 @@
 
 libtint_source_set("bytes") {
   sources = [
+    "buffer_reader.cc",
+    "buffer_reader.h",
     "buffer_writer.h",
     "bytes.cc",
     "decoder.h",
@@ -71,9 +73,9 @@
 if (tint_build_unittests) {
   tint_unittests_source_set("unittests") {
     sources = [
+      "buffer_reader_test.cc",
       "buffer_writer_test.cc",
       "decoder_test.cc",
-      "reader_test.cc",
       "swap_test.cc",
     ]
     deps = [
diff --git a/src/tint/utils/bytes/buffer_reader.cc b/src/tint/utils/bytes/buffer_reader.cc
new file mode 100644
index 0000000..4294fef
--- /dev/null
+++ b/src/tint/utils/bytes/buffer_reader.cc
@@ -0,0 +1,46 @@
+// Copyright 2024 The Dawn & Tint Authors
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this
+//    list of conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation
+//    and/or other materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its
+//    contributors may be used to endorse or promote products derived from
+//    this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "src/tint/utils/bytes/buffer_reader.h"
+
+namespace tint::bytes {
+
+BufferReader::~BufferReader() = default;
+
+size_t BufferReader::Read(std::byte* out, size_t count) {
+    size_t n = std::min(count, bytes_remaining_);
+    memcpy(out, data_, n);
+    data_ += n;
+    bytes_remaining_ -= n;
+    return n;
+}
+
+bool BufferReader::IsEOF() const {
+    return bytes_remaining_ == 0;
+}
+
+}  // namespace tint::bytes
diff --git a/src/tint/utils/bytes/buffer_reader.h b/src/tint/utils/bytes/buffer_reader.h
new file mode 100644
index 0000000..0367bb0
--- /dev/null
+++ b/src/tint/utils/bytes/buffer_reader.h
@@ -0,0 +1,81 @@
+// Copyright 2024 The Dawn & Tint Authors
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this
+//    list of conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation
+//    and/or other materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its
+//    contributors may be used to endorse or promote products derived from
+//    this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef SRC_TINT_UTILS_BYTES_BUFFER_READER_H_
+#define SRC_TINT_UTILS_BYTES_BUFFER_READER_H_
+
+#include <algorithm>
+#include <string>
+
+#include "src/tint/utils/bytes/reader.h"
+#include "src/tint/utils/ice/ice.h"
+
+namespace tint::bytes {
+
+/// BufferReader is an implementation of the Reader interface backed by a buffer.
+class BufferReader final : public Reader {
+  public:
+    // Destructor
+    ~BufferReader() override;
+
+    /// Constructor
+    /// @param data the data to read from
+    /// @param size the number of bytes in the buffer
+    BufferReader(const std::byte* data, size_t size) : data_(data), bytes_remaining_(size) {
+        TINT_ASSERT(data);
+    }
+
+    /// Constructor
+    /// @param string the string to read from
+    explicit BufferReader(std::string_view string)
+        : data_(reinterpret_cast<const std::byte*>(string.data())),
+          bytes_remaining_(string.length()) {}
+
+    /// Constructor
+    /// @param slice the byte slice to read from
+    explicit BufferReader(Slice<const std::byte> slice)
+        : data_(slice.data), bytes_remaining_(slice.len) {
+        TINT_ASSERT(slice.data);
+    }
+
+    /// @copydoc Reader::Read
+    size_t Read(std::byte* out, size_t count) override;
+
+    /// @copydoc Reader::IsEOF
+    bool IsEOF() const override;
+
+  private:
+    /// The data to read from
+    const std::byte* data_ = nullptr;
+
+    /// The number of bytes remaining
+    size_t bytes_remaining_ = 0;
+};
+
+}  // namespace tint::bytes
+
+#endif  // SRC_TINT_UTILS_BYTES_BUFFER_READER_H_
diff --git a/src/tint/utils/bytes/reader_test.cc b/src/tint/utils/bytes/buffer_reader_test.cc
similarity index 97%
rename from src/tint/utils/bytes/reader_test.cc
rename to src/tint/utils/bytes/buffer_reader_test.cc
index 2e90e88..b0b72d8 100644
--- a/src/tint/utils/bytes/reader_test.cc
+++ b/src/tint/utils/bytes/buffer_reader_test.cc
@@ -1,4 +1,4 @@
-// Copyright 2023 The Dawn & Tint Authors
+// Copyright 2024 The Dawn & Tint Authors
 //
 // Redistribution and use in source and binary forms, with or without
 // modification, are permitted provided that the following conditions are met:
@@ -25,7 +25,7 @@
 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-#include "src/tint/utils/bytes/reader.h"
+#include "src/tint/utils/bytes/buffer_reader.h"
 
 #include "gtest/gtest.h"
 
@@ -33,7 +33,7 @@
 namespace {
 
 template <typename... ARGS>
-auto Data(ARGS&&... args) {
+auto Data(ARGS... args) {
     return std::array{std::byte{static_cast<uint8_t>(args)}...};
 }
 
diff --git a/src/tint/utils/bytes/decoder_test.cc b/src/tint/utils/bytes/decoder_test.cc
index 125d7e6..11f663a 100644
--- a/src/tint/utils/bytes/decoder_test.cc
+++ b/src/tint/utils/bytes/decoder_test.cc
@@ -34,6 +34,7 @@
 #include <utility>
 
 #include "gmock/gmock.h"
+#include "src/tint/utils/bytes/buffer_reader.h"
 #include "src/tint/utils/result/result.h"
 
 namespace tint {
diff --git a/src/tint/utils/bytes/reader.cc b/src/tint/utils/bytes/reader.cc
index fc2dfc2..e12a020 100644
--- a/src/tint/utils/bytes/reader.cc
+++ b/src/tint/utils/bytes/reader.cc
@@ -31,18 +31,4 @@
 
 Reader::~Reader() = default;
 
-BufferReader::~BufferReader() = default;
-
-size_t BufferReader::Read(std::byte* out, size_t count) {
-    size_t n = std::min(count, bytes_remaining_);
-    memcpy(out, data_, n);
-    data_ += n;
-    bytes_remaining_ -= n;
-    return n;
-}
-
-bool BufferReader::IsEOF() const {
-    return bytes_remaining_ == 0;
-}
-
 }  // namespace tint::bytes
diff --git a/src/tint/utils/bytes/reader.h b/src/tint/utils/bytes/reader.h
index 3b5f51a..f0d074a 100644
--- a/src/tint/utils/bytes/reader.h
+++ b/src/tint/utils/bytes/reader.h
@@ -28,15 +28,11 @@
 #ifndef SRC_TINT_UTILS_BYTES_READER_H_
 #define SRC_TINT_UTILS_BYTES_READER_H_
 
-#include <algorithm>
-#include <cstdint>
 #include <string>
 
 #include "src/tint/utils/bytes/endianness.h"
 #include "src/tint/utils/bytes/swap.h"
-#include "src/tint/utils/containers/slice.h"
 #include "src/tint/utils/result/result.h"
-
 namespace tint::bytes {
 
 /// A binary stream reader interface
@@ -114,46 +110,6 @@
     }
 };
 
-/// BufferReader is an implementation of the Reader interface backed by a buffer.
-class BufferReader final : public Reader {
-  public:
-    // Destructor
-    ~BufferReader() override;
-
-    /// Constructor
-    /// @param data the data to read from
-    /// @param size the number of bytes in the buffer
-    BufferReader(const std::byte* data, size_t size) : data_(data), bytes_remaining_(size) {
-        TINT_ASSERT(data);
-    }
-
-    /// Constructor
-    /// @param string the string to read from
-    explicit BufferReader(std::string_view string)
-        : data_(reinterpret_cast<const std::byte*>(string.data())),
-          bytes_remaining_(string.length()) {}
-
-    /// Constructor
-    /// @param slice the byte slice to read from
-    explicit BufferReader(Slice<const std::byte> slice)
-        : data_(slice.data), bytes_remaining_(slice.len) {
-        TINT_ASSERT(slice.data);
-    }
-
-    /// @copydoc Reader::Read
-    size_t Read(std::byte* out, size_t count) override;
-
-    /// @copydoc Reader::IsEOF
-    bool IsEOF() const override;
-
-  private:
-    /// The data to read from
-    const std::byte* data_ = nullptr;
-
-    /// The number of bytes remaining
-    size_t bytes_remaining_ = 0;
-};
-
 }  // namespace tint::bytes
 
 #endif  // SRC_TINT_UTILS_BYTES_READER_H_