OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef IPC_IPC_MESSAGE_UTILS_H_ | 5 #ifndef IPC_IPC_MESSAGE_UTILS_H_ |
6 #define IPC_IPC_MESSAGE_UTILS_H_ | 6 #define IPC_IPC_MESSAGE_UTILS_H_ |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 m->WriteInt64(p); | 219 m->WriteInt64(p); |
220 } | 220 } |
221 static bool Read(const Message* m, void** iter, param_type* r) { | 221 static bool Read(const Message* m, void** iter, param_type* r) { |
222 return m->ReadInt64(iter, reinterpret_cast<int64*>(r)); | 222 return m->ReadInt64(iter, reinterpret_cast<int64*>(r)); |
223 } | 223 } |
224 static void Log(const param_type& p, std::wstring* l) { | 224 static void Log(const param_type& p, std::wstring* l) { |
225 l->append(Uint64ToWString(p)); | 225 l->append(Uint64ToWString(p)); |
226 } | 226 } |
227 }; | 227 }; |
228 | 228 |
229 // Note that the IPC layer doesn't sanitize NaNs and +/- INF values. Clients | |
230 // should be sure to check the sanity of these values after receiving them over | |
231 // IPC. | |
232 template <> | |
233 struct ParamTraits<float> { | |
234 typedef float param_type; | |
235 static void Write(Message* m, const param_type& p) { | |
236 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(param_type)); | |
237 } | |
238 static bool Read(const Message* m, void** iter, param_type* r) { | |
239 const char *data; | |
agl
2010/06/15 14:10:15
Seems over complex:
const char* data;
int data_si
jeremy
2010/06/15 14:26:55
Agreed, I wanted to match the definition for doubl
| |
240 int data_size = 0; | |
241 bool result = m->ReadData(iter, &data, &data_size); | |
242 if (result && data_size == sizeof(param_type)) { | |
243 memcpy(r, data, sizeof(param_type)); | |
244 } else { | |
245 result = false; | |
246 NOTREACHED(); | |
247 } | |
248 | |
249 return result; | |
250 } | |
251 static void Log(const param_type& p, std::wstring* l) { | |
252 l->append(StringPrintf(L"e", p)); | |
253 } | |
254 }; | |
255 | |
229 template <> | 256 template <> |
230 struct ParamTraits<double> { | 257 struct ParamTraits<double> { |
231 typedef double param_type; | 258 typedef double param_type; |
232 static void Write(Message* m, const param_type& p) { | 259 static void Write(Message* m, const param_type& p) { |
233 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(param_type)); | 260 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(param_type)); |
234 } | 261 } |
235 static bool Read(const Message* m, void** iter, param_type* r) { | 262 static bool Read(const Message* m, void** iter, param_type* r) { |
236 const char *data; | 263 const char *data; |
237 int data_size = 0; | 264 int data_size = 0; |
238 bool result = m->ReadData(iter, &data, &data_size); | 265 bool result = m->ReadData(iter, &data, &data_size); |
(...skipping 1043 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1282 ReplyParam p(a, b, c, d, e); | 1309 ReplyParam p(a, b, c, d, e); |
1283 WriteParam(reply, p); | 1310 WriteParam(reply, p); |
1284 } | 1311 } |
1285 }; | 1312 }; |
1286 | 1313 |
1287 //----------------------------------------------------------------------------- | 1314 //----------------------------------------------------------------------------- |
1288 | 1315 |
1289 } // namespace IPC | 1316 } // namespace IPC |
1290 | 1317 |
1291 #endif // IPC_IPC_MESSAGE_UTILS_H_ | 1318 #endif // IPC_IPC_MESSAGE_UTILS_H_ |
OLD | NEW |