aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core/SkStream.h
diff options
context:
space:
mode:
authorGravatar scroggo <scroggo@google.com>2015-04-02 13:19:51 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-04-02 13:19:51 -0700
commit028a4135aa6404ccd3a494813befe6e1a35e5e6c (patch)
treec8fcabf479a597c8117fcad7a6a506d11beed9bd /include/core/SkStream.h
parentf92ace90d89cc99b34162dda26be564e34ca80ef (diff)
Add a method to read a stream without advancing it.
Add a virtual method on SkStream which will do a "peek" some bytes, so that those bytes are read, but the next call to read will be unaffected. Implement peek for SkMemoryStream, where the implementation is simple and obvious. Implement peek on SkFrontBufferedStream. Add tests. Motivated by decoding streams which cannot be rewound. TBR=reed@google.com BUG=skia:3257 Review URL: https://codereview.chromium.org/1044953002
Diffstat (limited to 'include/core/SkStream.h')
-rw-r--r--include/core/SkStream.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/include/core/SkStream.h b/include/core/SkStream.h
index c227765b36..4c9c461e64 100644
--- a/include/core/SkStream.h
+++ b/include/core/SkStream.h
@@ -63,6 +63,20 @@ public:
return this->read(NULL, size);
}
+ /**
+ * Attempt to peek at size bytes.
+ * If this stream supports peeking, and it can peek size bytes, copy size
+ * bytes into buffer, and return true.
+ * If the stream does not support peeking, or cannot peek size bytes,
+ * return false and leave buffer unchanged.
+ * The stream is guaranteed to be in the same visible state after this
+ * call, regardless of success or failure.
+ * @param buffer Must not be NULL. Destination to copy bytes.
+ * @param size Number of bytes to copy.
+ * @return Whether the peek was performed.
+ */
+ virtual bool peek(void* /* buffer */, size_t /* size */) const { return false; }
+
/** Returns true when all the bytes in the stream have been read.
* This may return true early (when there are no more bytes to be read)
* or late (after the first unsuccessful read).
@@ -319,6 +333,8 @@ public:
size_t read(void* buffer, size_t size) override;
bool isAtEnd() const override;
+ bool peek(void* buffer, size_t size) const override;
+
bool rewind() override;
SkMemoryStream* duplicate() const override;