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

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

Issue 11299023: Add real support for uint128. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: One more try Created 8 years, 1 month 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_protocol.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/quic/quic_data_writer.h" 5 #include "net/quic/quic_data_writer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 uint32 hi = value >> 32; 49 uint32 hi = value >> 32;
50 uint32 lo = value & GG_UINT64_C(0x00000000FFFFFFFF); 50 uint32 lo = value & GG_UINT64_C(0x00000000FFFFFFFF);
51 return WriteUInt32(lo) && WriteUInt16(hi); 51 return WriteUInt32(lo) && WriteUInt16(hi);
52 } 52 }
53 53
54 bool QuicDataWriter::WriteUInt64(uint64 value) { 54 bool QuicDataWriter::WriteUInt64(uint64 value) {
55 return WriteBytes(&value, sizeof(value)); 55 return WriteBytes(&value, sizeof(value));
56 } 56 }
57 57
58 bool QuicDataWriter::WriteUInt128(uint128 value) { 58 bool QuicDataWriter::WriteUInt128(uint128 value) {
59 return WriteUInt64(value.lo) && WriteUInt64(value.hi); 59 return WriteUInt64(Uint128Low64(value)) && WriteUInt64(Uint128High64(value));
60 } 60 }
61 61
62 bool QuicDataWriter::WriteStringPiece16(StringPiece val) { 62 bool QuicDataWriter::WriteStringPiece16(StringPiece val) {
63 if (val.length() > numeric_limits<uint16>::max()) { 63 if (val.length() > numeric_limits<uint16>::max()) {
64 return false; 64 return false;
65 } 65 }
66 if (!WriteUInt16(val.size())) { 66 if (!WriteUInt16(val.size())) {
67 return false; 67 return false;
68 } 68 }
69 return WriteBytes(val.data(), val.size()); 69 return WriteBytes(val.data(), val.size());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 uint32 lo = value & 0x00000000FFFFFFFF; 110 uint32 lo = value & 0x00000000FFFFFFFF;
111 WriteUint32ToBuffer(lo, buffer); 111 WriteUint32ToBuffer(lo, buffer);
112 WriteUint16ToBuffer(hi, buffer + sizeof(lo)); 112 WriteUint16ToBuffer(hi, buffer + sizeof(lo));
113 } 113 }
114 114
115 void QuicDataWriter::WriteUint64ToBuffer(uint64 value, char* buffer) { 115 void QuicDataWriter::WriteUint64ToBuffer(uint64 value, char* buffer) {
116 memcpy(buffer, &value, sizeof(value)); 116 memcpy(buffer, &value, sizeof(value));
117 } 117 }
118 118
119 void QuicDataWriter::WriteUint128ToBuffer(uint128 value, char* buffer) { 119 void QuicDataWriter::WriteUint128ToBuffer(uint128 value, char* buffer) {
120 WriteUint64ToBuffer(value.lo, buffer); 120 uint64 high = Uint128High64(value);
121 WriteUint64ToBuffer(value.hi, buffer + sizeof(value.lo)); 121 uint64 low = Uint128Low64(value);
122 WriteUint64ToBuffer(low, buffer);
123 WriteUint64ToBuffer(high, buffer + sizeof(low));
122 } 124 }
123 125
124 } // namespace net 126 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_data_writer.h ('k') | net/quic/quic_protocol.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698