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

Side by Side Diff: webrtc/base/bytebuffer.cc

Issue 1362503003: Use suffixed {uint,int}{8,16,32,64}_t types. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase + revert basictypes.h (to be landed separately just in case of a revert due to unexpected us… Created 5 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
« no previous file with comments | « webrtc/base/bytebuffer.h ('k') | webrtc/base/bytebuffer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 memcpy(bytes_, bytes, end_); 59 memcpy(bytes_, bytes, end_);
60 } else { 60 } else {
61 end_ = 0; 61 end_ = 0;
62 } 62 }
63 } 63 }
64 64
65 ByteBuffer::~ByteBuffer() { 65 ByteBuffer::~ByteBuffer() {
66 delete[] bytes_; 66 delete[] bytes_;
67 } 67 }
68 68
69 bool ByteBuffer::ReadUInt8(uint8* val) { 69 bool ByteBuffer::ReadUInt8(uint8_t* val) {
70 if (!val) return false; 70 if (!val) return false;
71 71
72 return ReadBytes(reinterpret_cast<char*>(val), 1); 72 return ReadBytes(reinterpret_cast<char*>(val), 1);
73 } 73 }
74 74
75 bool ByteBuffer::ReadUInt16(uint16* val) { 75 bool ByteBuffer::ReadUInt16(uint16_t* val) {
76 if (!val) return false; 76 if (!val) return false;
77 77
78 uint16 v; 78 uint16_t v;
79 if (!ReadBytes(reinterpret_cast<char*>(&v), 2)) { 79 if (!ReadBytes(reinterpret_cast<char*>(&v), 2)) {
80 return false; 80 return false;
81 } else { 81 } else {
82 *val = (byte_order_ == ORDER_NETWORK) ? NetworkToHost16(v) : v; 82 *val = (byte_order_ == ORDER_NETWORK) ? NetworkToHost16(v) : v;
83 return true; 83 return true;
84 } 84 }
85 } 85 }
86 86
87 bool ByteBuffer::ReadUInt24(uint32* val) { 87 bool ByteBuffer::ReadUInt24(uint32_t* val) {
88 if (!val) return false; 88 if (!val) return false;
89 89
90 uint32 v = 0; 90 uint32_t v = 0;
91 char* read_into = reinterpret_cast<char*>(&v); 91 char* read_into = reinterpret_cast<char*>(&v);
92 if (byte_order_ == ORDER_NETWORK || IsHostBigEndian()) { 92 if (byte_order_ == ORDER_NETWORK || IsHostBigEndian()) {
93 ++read_into; 93 ++read_into;
94 } 94 }
95 95
96 if (!ReadBytes(read_into, 3)) { 96 if (!ReadBytes(read_into, 3)) {
97 return false; 97 return false;
98 } else { 98 } else {
99 *val = (byte_order_ == ORDER_NETWORK) ? NetworkToHost32(v) : v; 99 *val = (byte_order_ == ORDER_NETWORK) ? NetworkToHost32(v) : v;
100 return true; 100 return true;
101 } 101 }
102 } 102 }
103 103
104 bool ByteBuffer::ReadUInt32(uint32* val) { 104 bool ByteBuffer::ReadUInt32(uint32_t* val) {
105 if (!val) return false; 105 if (!val) return false;
106 106
107 uint32 v; 107 uint32_t v;
108 if (!ReadBytes(reinterpret_cast<char*>(&v), 4)) { 108 if (!ReadBytes(reinterpret_cast<char*>(&v), 4)) {
109 return false; 109 return false;
110 } else { 110 } else {
111 *val = (byte_order_ == ORDER_NETWORK) ? NetworkToHost32(v) : v; 111 *val = (byte_order_ == ORDER_NETWORK) ? NetworkToHost32(v) : v;
112 return true; 112 return true;
113 } 113 }
114 } 114 }
115 115
116 bool ByteBuffer::ReadUInt64(uint64* val) { 116 bool ByteBuffer::ReadUInt64(uint64_t* val) {
117 if (!val) return false; 117 if (!val) return false;
118 118
119 uint64 v; 119 uint64_t v;
120 if (!ReadBytes(reinterpret_cast<char*>(&v), 8)) { 120 if (!ReadBytes(reinterpret_cast<char*>(&v), 8)) {
121 return false; 121 return false;
122 } else { 122 } else {
123 *val = (byte_order_ == ORDER_NETWORK) ? NetworkToHost64(v) : v; 123 *val = (byte_order_ == ORDER_NETWORK) ? NetworkToHost64(v) : v;
124 return true; 124 return true;
125 } 125 }
126 } 126 }
127 127
128 bool ByteBuffer::ReadString(std::string* val, size_t len) { 128 bool ByteBuffer::ReadString(std::string* val, size_t len) {
129 if (!val) return false; 129 if (!val) return false;
(...skipping 10 matching lines...) Expand all
140 bool ByteBuffer::ReadBytes(char* val, size_t len) { 140 bool ByteBuffer::ReadBytes(char* val, size_t len) {
141 if (len > Length()) { 141 if (len > Length()) {
142 return false; 142 return false;
143 } else { 143 } else {
144 memcpy(val, bytes_ + start_, len); 144 memcpy(val, bytes_ + start_, len);
145 start_ += len; 145 start_ += len;
146 return true; 146 return true;
147 } 147 }
148 } 148 }
149 149
150 void ByteBuffer::WriteUInt8(uint8 val) { 150 void ByteBuffer::WriteUInt8(uint8_t val) {
151 WriteBytes(reinterpret_cast<const char*>(&val), 1); 151 WriteBytes(reinterpret_cast<const char*>(&val), 1);
152 } 152 }
153 153
154 void ByteBuffer::WriteUInt16(uint16 val) { 154 void ByteBuffer::WriteUInt16(uint16_t val) {
155 uint16 v = (byte_order_ == ORDER_NETWORK) ? HostToNetwork16(val) : val; 155 uint16_t v = (byte_order_ == ORDER_NETWORK) ? HostToNetwork16(val) : val;
156 WriteBytes(reinterpret_cast<const char*>(&v), 2); 156 WriteBytes(reinterpret_cast<const char*>(&v), 2);
157 } 157 }
158 158
159 void ByteBuffer::WriteUInt24(uint32 val) { 159 void ByteBuffer::WriteUInt24(uint32_t val) {
160 uint32 v = (byte_order_ == ORDER_NETWORK) ? HostToNetwork32(val) : val; 160 uint32_t v = (byte_order_ == ORDER_NETWORK) ? HostToNetwork32(val) : val;
161 char* start = reinterpret_cast<char*>(&v); 161 char* start = reinterpret_cast<char*>(&v);
162 if (byte_order_ == ORDER_NETWORK || IsHostBigEndian()) { 162 if (byte_order_ == ORDER_NETWORK || IsHostBigEndian()) {
163 ++start; 163 ++start;
164 } 164 }
165 WriteBytes(start, 3); 165 WriteBytes(start, 3);
166 } 166 }
167 167
168 void ByteBuffer::WriteUInt32(uint32 val) { 168 void ByteBuffer::WriteUInt32(uint32_t val) {
169 uint32 v = (byte_order_ == ORDER_NETWORK) ? HostToNetwork32(val) : val; 169 uint32_t v = (byte_order_ == ORDER_NETWORK) ? HostToNetwork32(val) : val;
170 WriteBytes(reinterpret_cast<const char*>(&v), 4); 170 WriteBytes(reinterpret_cast<const char*>(&v), 4);
171 } 171 }
172 172
173 void ByteBuffer::WriteUInt64(uint64 val) { 173 void ByteBuffer::WriteUInt64(uint64_t val) {
174 uint64 v = (byte_order_ == ORDER_NETWORK) ? HostToNetwork64(val) : val; 174 uint64_t v = (byte_order_ == ORDER_NETWORK) ? HostToNetwork64(val) : val;
175 WriteBytes(reinterpret_cast<const char*>(&v), 8); 175 WriteBytes(reinterpret_cast<const char*>(&v), 8);
176 } 176 }
177 177
178 void ByteBuffer::WriteString(const std::string& val) { 178 void ByteBuffer::WriteString(const std::string& val) {
179 WriteBytes(val.c_str(), val.size()); 179 WriteBytes(val.c_str(), val.size());
180 } 180 }
181 181
182 void ByteBuffer::WriteBytes(const char* val, size_t len) { 182 void ByteBuffer::WriteBytes(const char* val, size_t len) {
183 memcpy(ReserveWriteBuffer(len), val, len); 183 memcpy(ReserveWriteBuffer(len), val, len);
184 } 184 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 return true; 229 return true;
230 } 230 }
231 231
232 void ByteBuffer::Clear() { 232 void ByteBuffer::Clear() {
233 memset(bytes_, 0, size_); 233 memset(bytes_, 0, size_);
234 start_ = end_ = 0; 234 start_ = end_ = 0;
235 ++version_; 235 ++version_;
236 } 236 }
237 237
238 } // namespace rtc 238 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/bytebuffer.h ('k') | webrtc/base/bytebuffer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698