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

Side by Side Diff: net/quic/quic_data_writer.cc

Issue 11125002: Add QuicFramer and friends. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix final comments. 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/quic/quic_data_writer.h ('k') | net/quic/quic_framer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/quic/quic_data_writer.h"
6
7 #include <algorithm>
8 #include <limits>
9
10 #include "base/basictypes.h"
11 #include "base/logging.h"
12 #include "net/quic/quic_protocol.h"
13
14 using std::numeric_limits;
15
16 namespace net {
17
18 QuicDataWriter::QuicDataWriter(size_t size)
19 : buffer_(new char[size]),
20 capacity_(size),
21 length_(0) {
22 }
23
24 QuicDataWriter::~QuicDataWriter() {
25 delete[] buffer_;
26 }
27
28 char* QuicDataWriter::BeginWrite(size_t length) {
29 if (capacity_ - length_ < length) {
30 return NULL;
31 }
32
33 #ifdef ARCH_CPU_64_BITS
34 DCHECK_LE(length, numeric_limits<uint32>::max());
35 #endif
36
37 return buffer_ + length_;
38 }
39
40 bool QuicDataWriter::AdvancePointer(uint32 len) {
41 if (!BeginWrite(len)) {
42 return false;
43 }
44 length_ += len;
45 return true;
46 }
47
48 bool QuicDataWriter::WriteBytes(const void* data, uint32 data_len) {
49 char* dest = BeginWrite(data_len);
50 if (!dest) {
51 return false;
52 }
53
54 memcpy(dest, data, data_len);
55
56 length_ += data_len;
57 return true;
58 }
59
60 void QuicDataWriter::WriteUint64ToBuffer(uint64 value, char* buffer) {
61 memcpy(buffer, &value, sizeof(value));
62 }
63
64 void QuicDataWriter::WriteUint128ToBuffer(uint128 value, char* buffer) {
65 WriteUint64ToBuffer(value.lo, buffer);
66 WriteUint64ToBuffer(value.hi, buffer + sizeof(value.lo));
67 }
68
69 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_data_writer.h ('k') | net/quic/quic_framer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698