summaryrefslogtreecommitdiffstats
path: root/chromium/base/big_endian.h
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/base/big_endian.h')
-rw-r--r--chromium/base/big_endian.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/chromium/base/big_endian.h b/chromium/base/big_endian.h
index 8fea64f248d..96650a6955f 100644
--- a/chromium/base/big_endian.h
+++ b/chromium/base/big_endian.h
@@ -67,10 +67,26 @@ class BASE_EXPORT BigEndianReader {
bool ReadU32(uint32_t* value);
bool ReadU64(uint64_t* value);
+ // Reads a length-prefixed region:
+ // 1. reads a big-endian length L from the buffer;
+ // 2. sets |*out| to a StringPiece over the next L many bytes
+ // of the buffer (beyond the end of the bytes encoding the length); and
+ // 3. skips the main reader past this L-byte substring.
+ //
+ // Fails if reading a U8 or U16 fails, or if the parsed length is greater
+ // than the number of bytes remaining in the stream.
+ //
+ // On failure, leaves the stream at the same position
+ // as before the call.
+ bool ReadU8LengthPrefixed(base::StringPiece* out);
+ bool ReadU16LengthPrefixed(base::StringPiece* out);
+
private:
// Hidden to promote type safety.
template<typename T>
bool Read(T* v);
+ template <typename T>
+ bool ReadLengthPrefixed(base::StringPiece* out);
const char* ptr_;
const char* end_;