Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Unified Diff: net/quic/quic_data_writer.cc

Issue 11230005: Move non-trivial methods from QuicDataWriter to the .cc file (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix WriteUInt128 Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/quic/quic_data_writer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/quic_data_writer.cc
diff --git a/net/quic/quic_data_writer.cc b/net/quic/quic_data_writer.cc
index f76b2537fdb9a973a57e39fde1d6b4873b14929c..91d8868598bfdd82b99e675d2cfc6fc4b25c50b6 100644
--- a/net/quic/quic_data_writer.cc
+++ b/net/quic/quic_data_writer.cc
@@ -11,6 +11,7 @@
#include "base/logging.h"
#include "net/quic/quic_protocol.h"
+using base::StringPiece;
using std::numeric_limits;
namespace net {
@@ -25,6 +26,50 @@ QuicDataWriter::~QuicDataWriter() {
delete[] buffer_;
}
+char* QuicDataWriter::take() {
+ char* rv = buffer_;
+ buffer_ = NULL;
+ capacity_ = 0;
+ length_ = 0;
+ return rv;
+}
+
+bool QuicDataWriter::WriteUInt8(uint8 value) {
+ return WriteBytes(&value, sizeof(value));
+}
+
+bool QuicDataWriter::WriteUInt16(uint16 value) {
+ return WriteBytes(&value, sizeof(value));
+}
+
+bool QuicDataWriter::WriteUInt32(uint32 value) {
+ return WriteBytes(&value, sizeof(value));
+}
+
+bool QuicDataWriter::WriteUInt48(uint64 value) {
+ uint32 hi = value >> 32;
+ uint32 lo = value & GG_UINT64_C(0x00000000FFFFFFFF);
+ return WriteUInt32(lo) && WriteUInt16(hi);
+}
+
+bool QuicDataWriter::WriteUInt64(uint64 value) {
+ return WriteBytes(&value, sizeof(value));
+}
+
+bool QuicDataWriter::WriteUInt128(uint128 value) {
+ return WriteUInt64(value.lo) && WriteUInt64(value.hi);
+}
+
+bool QuicDataWriter::WriteStringPiece16(StringPiece val) {
+ if (val.length() > numeric_limits<uint16>::max()) {
+ return false;
+ }
+ if (!WriteUInt16(val.size())) {
+ return false;
+ }
+ return WriteBytes(val.data(), val.size());
+}
+
char* QuicDataWriter::BeginWrite(size_t length) {
if (capacity_ - length_ < length) {
return NULL;
@@ -37,14 +82,6 @@ char* QuicDataWriter::BeginWrite(size_t length) {
return buffer_ + length_;
}
-bool QuicDataWriter::AdvancePointer(uint32 len) {
- if (!BeginWrite(len)) {
- return false;
- }
- length_ += len;
- return true;
-}
-
bool QuicDataWriter::WriteBytes(const void* data, uint32 data_len) {
char* dest = BeginWrite(data_len);
if (!dest) {
« no previous file with comments | « net/quic/quic_data_writer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698