pw_blob_store: Move BlobReader functions to the .cc

- Move some functions that do not need to be in the header to the
  source. These functions either can't be inlined because they're
  virtual or likely shouldn't be inlined because they're fairly long.
- Switch the PW_DASSERTS in the moved functions to PW_DCHECK.
- Make the internal pw::stream::Stream functions private.

Change-Id: I4ac620b43a8964383182148007d7098a7ba6e292
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/77751
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
Reviewed-by: David Rogers <davidrogers@google.com>
Commit-Queue: Wyatt Hepler <hepler@google.com>
diff --git a/pw_blob_store/blob_store.cc b/pw_blob_store/blob_store.cc
index a8be319..9a1fd7b 100644
--- a/pw_blob_store/blob_store.cc
+++ b/pw_blob_store/blob_store.cc
@@ -675,4 +675,55 @@
   return OkStatus();
 }
 
+size_t BlobStore::BlobReader::ConservativeLimit(LimitType limit) const {
+  if (limit == LimitType::kRead) {
+    PW_DCHECK(open_);
+    return store_.ReadableDataBytes() - offset_;
+  }
+  return 0;
+}
+
+Status BlobStore::BlobReader::Open(size_t offset) {
+  PW_DCHECK(!open_);
+  if (!store_.ValidToRead()) {
+    return Status::FailedPrecondition();
+  }
+  if (offset >= store_.ReadableDataBytes()) {
+    return Status::InvalidArgument();
+  }
+
+  offset_ = offset;
+  Status status = store_.OpenRead();
+  if (status.ok()) {
+    open_ = true;
+  }
+  return status;
+}
+
+size_t BlobStore::BlobReader::DoTell() const {
+  PW_DCHECK(open_);
+  return offset_;
+}
+
+Status BlobStore::BlobReader::DoSeek(ptrdiff_t offset, Whence origin) {
+  PW_DCHECK(open_);
+  // Note that Open ensures it is ValidToRead() which
+  // in turn guarantees store_.ReadableDataBytes() > 0.
+
+  size_t pos = offset_;
+  PW_TRY(CalculateSeek(offset, origin, store_.ReadableDataBytes() - 1, pos));
+  offset_ = pos;
+
+  return OkStatus();
+}
+
+StatusWithSize BlobStore::BlobReader::DoRead(ByteSpan dest) {
+  PW_DCHECK(open_);
+  StatusWithSize status = store_.Read(offset_, dest);
+  if (status.ok()) {
+    offset_ += status.size();
+  }
+  return status;
+}
+
 }  // namespace pw::blob_store
diff --git a/pw_blob_store/public/pw_blob_store/blob_store.h b/pw_blob_store/public/pw_blob_store/blob_store.h
index 3869d27..c9c272c 100644
--- a/pw_blob_store/public/pw_blob_store/blob_store.h
+++ b/pw_blob_store/public/pw_blob_store/blob_store.h
@@ -258,8 +258,10 @@
    public:
     constexpr BlobReader(BlobStore& store)
         : store_(store), open_(false), offset_(0) {}
+
     BlobReader(const BlobReader&) = delete;
     BlobReader& operator=(const BlobReader&) = delete;
+
     ~BlobReader() {
       if (open_) {
         Close().IgnoreError();  // TODO(pwbug/387): Handle Status properly
@@ -274,22 +276,7 @@
     // FAILED_PRECONDITION - No readable blob available.
     // INVALID_ARGUMENT - Invalid offset.
     // UNAVAILABLE - Unable to open, already open.
-    Status Open(size_t offset = 0) {
-      PW_DASSERT(!open_);
-      if (!store_.ValidToRead()) {
-        return Status::FailedPrecondition();
-      }
-      if (offset >= store_.ReadableDataBytes()) {
-        return Status::InvalidArgument();
-      }
-
-      offset_ = offset;
-      Status status = store_.OpenRead();
-      if (status.ok()) {
-        open_ = true;
-      }
-      return status;
-    }
+    Status Open(size_t offset = 0);
 
     // Finish reading a blob. Close fails in the closed state, do NOT retry
     // Close on error. Returns:
@@ -315,18 +302,7 @@
       return store_.GetFileName(dest);
     }
 
-    bool IsOpen() { return open_; }
-
-    // Probable (not guaranteed) minimum number of bytes at this time that can
-    // be read. Returns zero if, in the current state, Read would return status
-    // other than OK. See stream.h for additional details.
-    size_t ConservativeLimit(LimitType limit) const override {
-      if (limit == LimitType::kRead) {
-        PW_DASSERT(open_);
-        return store_.ReadableDataBytes() - offset_;
-      }
-      return 0;
-    }
+    bool IsOpen() const { return open_; }
 
     // Get a span with the MCU pointer and size of the data. Returns:
     //
@@ -338,33 +314,17 @@
       return store_.GetMemoryMappedBlob();
     }
 
-    size_t DoTell() const override {
-      PW_DASSERT(open_);
-      return offset_;
-    }
-
-    Status DoSeek(ptrdiff_t offset, Whence origin) override {
-      PW_DASSERT(open_);
-      // Note that Open ensures it is ValidToRead() which
-      // in turn guarantees store_.ReadableDataBytes() > 0.
-
-      size_t pos = offset_;
-      PW_TRY(
-          CalculateSeek(offset, origin, store_.ReadableDataBytes() - 1, pos));
-      offset_ = pos;
-
-      return OkStatus();
-    }
-
    private:
-    StatusWithSize DoRead(ByteSpan dest) override {
-      PW_DASSERT(open_);
-      StatusWithSize status = store_.Read(offset_, dest);
-      if (status.ok()) {
-        offset_ += status.size();
-      }
-      return status;
-    }
+    // Probable (not guaranteed) minimum number of bytes at this time that can
+    // be read. Returns zero if, in the current state, Read would return status
+    // other than OK. See stream.h for additional details.
+    size_t ConservativeLimit(LimitType limit) const override;
+
+    size_t DoTell() const override;
+
+    Status DoSeek(ptrdiff_t offset, Whence origin) override;
+
+    StatusWithSize DoRead(ByteSpan dest) override;
 
     BlobStore& store_;
     bool open_;