Lift generic functionality from QuicDataReader/QuicDataWriter into Quiche
The QUIC-specific functions stay in QuicDataReader/QuicDataWriter. Generally useful functions are moved into QuicheDataReader/QuicheDataWriter.
gfe-relnote: n/a, no functional change
PiperOrigin-RevId: 288584295
Change-Id: I53b102f56f43019a89db0aa624898ed44bb6ec11
diff --git a/quic/core/quic_data_reader.h b/quic/core/quic_data_reader.h
index 40ad4fc..08366b9 100644
--- a/quic/core/quic_data_reader.h
+++ b/quic/core/quic_data_reader.h
@@ -12,6 +12,7 @@
#include "net/third_party/quiche/src/quic/platform/api/quic_export.h"
#include "net/third_party/quiche/src/common/platform/api/quiche_endian.h"
#include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h"
+#include "net/third_party/quiche/src/common/quiche_data_reader.h"
namespace quic {
@@ -29,7 +30,7 @@
// trusted and it is up to the caller to throw away the failed instance and
// handle the error as appropriate. None of the Read*() methods should ever be
// called after failure, as they will also fail immediately.
-class QUIC_EXPORT_PRIVATE QuicDataReader {
+class QUIC_EXPORT_PRIVATE QuicDataReader : public quiche::QuicheDataReader {
public:
// Constructs a reader using NETWORK_BYTE_ORDER endianness.
// Caller must provide an underlying buffer to work on.
@@ -48,38 +49,11 @@
// Empty destructor.
~QuicDataReader() {}
- // Reads an 8/16/32/64-bit unsigned integer into the given output
- // parameter. Forwards the internal iterator on success. Returns true on
- // success, false otherwise.
- bool ReadUInt8(uint8_t* result);
- bool ReadUInt16(uint16_t* result);
- bool ReadUInt32(uint32_t* result);
- bool ReadUInt64(uint64_t* result);
-
- // Set |result| to 0, then read |num_bytes| bytes in the correct byte order
- // into least significant bytes of |result|.
- bool ReadBytesToUInt64(size_t num_bytes, uint64_t* result);
-
// Reads a 16-bit unsigned float into the given output parameter.
// Forwards the internal iterator on success.
// Returns true on success, false otherwise.
bool ReadUFloat16(uint64_t* result);
- // Reads a string prefixed with 16-bit length into the given output parameter.
- //
- // NOTE: Does not copy but rather references strings in the underlying buffer.
- // This should be kept in mind when handling memory management!
- //
- // Forwards the internal iterator on success.
- // Returns true on success, false otherwise.
- bool ReadStringPiece16(quiche::QuicheStringPiece* result);
-
- // Reads a given number of bytes into the given buffer. The buffer
- // must be of adequate size.
- // Forwards the internal iterator on success.
- // Returns true on success, false otherwise.
- bool ReadStringPiece(quiche::QuicheStringPiece* result, size_t len);
-
// Reads connection ID into the given output parameter.
// Forwards the internal iterator on success.
// Returns true on success, false otherwise.
@@ -90,70 +64,10 @@
// Returns true on success, false otherwise.
bool ReadLengthPrefixedConnectionId(QuicConnectionId* connection_id);
- // Reads tag represented as 32-bit unsigned integer into given output
- // parameter. Tags are in big endian on the wire (e.g., CHLO is
- // 'C','H','L','O') and are read in byte order, so tags in memory are in big
- // endian.
- bool ReadTag(uint32_t* tag);
-
- // Returns the remaining payload as a quiche::QuicheStringPiece.
- //
- // NOTE: Does not copy but rather references strings in the underlying buffer.
- // This should be kept in mind when handling memory management!
- //
- // Forwards the internal iterator.
- quiche::QuicheStringPiece ReadRemainingPayload();
-
- // Returns the remaining payload as a quiche::QuicheStringPiece.
- //
- // NOTE: Does not copy but rather references strings in the underlying buffer.
- // This should be kept in mind when handling memory management!
- //
- // DOES NOT forward the internal iterator.
- quiche::QuicheStringPiece PeekRemainingPayload() const;
-
- // Returns the entire payload as a quiche::QuicheStringPiece.
- //
- // NOTE: Does not copy but rather references strings in the underlying buffer.
- // This should be kept in mind when handling memory management!
- //
- // DOES NOT forward the internal iterator.
- quiche::QuicheStringPiece FullPayload() const;
-
- // Reads a given number of bytes into the given buffer. The buffer
- // must be of adequate size.
- // Forwards the internal iterator on success.
- // Returns true on success, false otherwise.
- bool ReadBytes(void* result, size_t size);
-
- // Skips over |size| bytes from the buffer and forwards the internal iterator.
- // Returns true if there are at least |size| bytes remaining to read, false
- // otherwise.
- bool Seek(size_t size);
-
- // Returns true if the entirety of the underlying buffer has been read via
- // Read*() calls.
- bool IsDoneReading() const;
-
// Returns the length in bytes of a variable length integer based on the next
// two bits available. Returns 1, 2, 4, or 8 on success, and 0 on failure.
QuicVariableLengthIntegerLength PeekVarInt62Length();
- // Returns the number of bytes remaining to be read.
- size_t BytesRemaining() const;
-
- // Truncates the reader down by reducing its internal length.
- // If called immediately after calling this, BytesRemaining will
- // return |truncation_length|. If truncation_length is less than the
- // current value of BytesRemaining, this does nothing and returns false.
- bool TruncateRemaining(size_t truncation_length);
-
- // Returns the next byte that to be read. Must not be called when there are no
- // bytes to be read.
- //
- // DOES NOT forward the internal iterator.
- uint8_t PeekByte() const;
-
// Read an IETF-encoded Variable Length Integer and place the result
// in |*result|.
// Returns true if it works, false if not. The only error is that
@@ -168,29 +82,6 @@
// returns false if there is a read error or if the value is
// greater than (2^32)-1.
bool ReadVarIntU32(uint32_t* result);
-
- std::string DebugString() const;
-
- private:
- // Returns true if the underlying buffer has enough room to read the given
- // amount of bytes.
- bool CanRead(size_t bytes) const;
-
- // To be called when a read fails for any reason.
- void OnFailure();
-
- // TODO(fkastenholz, b/73004262) change buffer_, et al, to be uint8_t, not
- // char. The data buffer that we're reading from.
- const char* data_;
-
- // The length of the data buffer that we're reading from.
- size_t len_;
-
- // The location of the next read from our data buffer.
- size_t pos_;
-
- // The endianness to read integers and floating numbers.
- quiche::Endianness endianness_;
};
} // namespace quic