![]() |
VOOZH | about |
| OLD | NEW |
|---|---|
| (Empty) | |
| // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| // Use of this source code is governed by a BSD-style license that can be | |
| // found in the LICENSE file. | |
| #include "net/quic/quic_data_writer.h" | |
| #include <algorithm> | |
| #include <limits> | |
| #include "base/basictypes.h" | |
| #include "base/logging.h" | |
| #include "net/quic/quic_protocol.h" | |
| using std::numeric_limits; | |
| namespace net { | |
| QuicDataWriter::QuicDataWriter(size_t size) | |
| : buffer_(new char[size]), | |
|
jar (doing other things)
2012/10/14 23:04:38
nit/comment: It is a bit tempting to have a fixed
Ryan Hamilton
2012/10/15 21:22:08
But then the take() method could not be implemente
| |
| capacity_(size), | |
| length_(0) { | |
| } | |
| QuicDataWriter::~QuicDataWriter() { | |
| delete[] buffer_; | |
| } | |
| char* QuicDataWriter::BeginWrite(size_t length) { | |
| size_t offset = length_; | |
| size_t needed_size = length_ + length; | |
| if (needed_size > capacity_) { | |
|
jar (doing other things)
2012/10/14 23:04:38
nit: to handle wrapping, perhaps better would be:
Ryan Hamilton
2012/10/15 21:22:08
Done. FYI, This code was simply copied from the s
| |
| return NULL; | |
| } | |
| #ifdef ARCH_CPU_64_BITS | |
| DCHECK_LE(length, numeric_limits<uint32>::max()); | |
| #endif | |
| return buffer_ + offset; | |
|
jar (doing other things)
2012/10/14 23:04:38
Why did you save length_ into offset? Isn't this
Ryan Hamilton
2012/10/15 21:22:08
This code was copied from the spdy variant.
| |
| } | |
| bool QuicDataWriter::AdvancePointer(uint32 len) { | |
| if (!BeginWrite(len)) return false; | |
|
jar (doing other things)
2012/10/14 23:04:38
nit: probably want to be consistent with braces an
Ryan Hamilton
2012/10/15 21:22:08
Done. But just to be clear, this is perfectly acc
| |
| length_ += len; | |
| return true; | |
| } | |
| bool QuicDataWriter::WriteBytes(const void* data, uint32 data_len) { | |
| char* dest = BeginWrite(data_len); | |
| if (!dest) { | |
| return false; | |
| } | |
| memcpy(dest, data, data_len); | |
| length_ += data_len; | |
| return true; | |
| } | |
| void QuicDataWriter::WriteUint64ToBuffer(uint64 value, char* buffer) { | |
| memcpy(buffer, &value, sizeof(value)); | |
| } | |
| void QuicDataWriter::WriteUint128ToBuffer(uint128 value, char* buffer) { | |
| WriteUint64ToBuffer(value.lo, buffer); | |
| WriteUint64ToBuffer(value.hi, buffer + sizeof(value.lo)); | |
| } | |
| } // namespace net | |
| OLD | NEW |