Index: fuzz/Fuzz.h |
diff --git a/fuzz/Fuzz.h b/fuzz/Fuzz.h |
index 07c2c8456e248cc35ec7f65d1dd8f19f64d007ab..79bf675f45ae15dde6121191ca53bb0694b9c941 100644 |
--- a/fuzz/Fuzz.h |
+++ b/fuzz/Fuzz.h |
@@ -16,6 +16,14 @@ class Fuzz : SkNoncopyable { |
public: |
explicit Fuzz(SkData*); |
+ // Returns the total number of "random" bytes available. |
+ size_t size(); |
+ // Returns the total number of "random" bytes remaining for randomness. |
+ size_t remaining(); |
+ |
+ template <typename T> |
+ bool next(T* n); |
+ |
bool nextBool(); |
uint8_t nextB(); |
uint32_t nextU(); |
@@ -43,6 +51,17 @@ private: |
int fNextByte; |
}; |
+template <typename T> |
+bool Fuzz::next(T* n) { |
+ if (fNextByte + sizeof(T) > fBytes->size()) { |
+ return false; |
+ } |
+ |
+ memcpy(n, fBytes->bytes() + fNextByte, sizeof(T)); |
+ fNextByte += sizeof(T); |
+ return true; |
+} |
+ |
struct Fuzzable { |
const char* name; |
void (*fn)(Fuzz*); |