OLD | NEW |
---|---|
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 #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 <limits.h> | 8 #include <limits.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 #include <stdint.h> | 10 #include <stdint.h> |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 struct IPC_EXPORT ParamTraits<double> { | 300 struct IPC_EXPORT ParamTraits<double> { |
301 typedef double param_type; | 301 typedef double param_type; |
302 static void GetSize(base::PickleSizer* sizer, const param_type& p); | 302 static void GetSize(base::PickleSizer* sizer, const param_type& p); |
303 static void Write(base::Pickle* m, const param_type& p); | 303 static void Write(base::Pickle* m, const param_type& p); |
304 static bool Read(const base::Pickle* m, | 304 static bool Read(const base::Pickle* m, |
305 base::PickleIterator* iter, | 305 base::PickleIterator* iter, |
306 param_type* r); | 306 param_type* r); |
307 static void Log(const param_type& p, std::string* l); | 307 static void Log(const param_type& p, std::string* l); |
308 }; | 308 }; |
309 | 309 |
310 template <class P, size_t Size> | |
311 struct ParamTraits<P[Size]> { | |
312 using param_type = P[Size]; | |
313 static void GetSize(base::PickleSizer* sizer, const param_type& p) { | |
314 GetParamSize(sizer, base::checked_cast<int>(Size)); | |
ericrk
2017/02/08 21:07:15
Switched to checked_cast per your comment.
Tom Sepez
2017/02/09 17:14:37
Why are we passing the size over the wire? These
ericrk
2017/02/09 22:02:08
True enough, I guess I was thinking it was more ro
| |
315 for (size_t i = 0; i < Size; i++) | |
316 GetParamSize(sizer, p[i]); | |
317 } | |
318 static void Write(base::Pickle* m, const param_type& p) { | |
319 WriteParam(m, base::checked_cast<int>(Size)); | |
320 for (size_t i = 0; i < Size; i++) | |
Tom Sepez
2017/02/09 17:17:10
nit: can we use a range-based for loop and avoid h
ericrk
2017/02/09 22:02:08
Yup, we can.
| |
321 WriteParam(m, p[i]); | |
322 } | |
323 static bool Read(const base::Pickle* m, | |
324 base::PickleIterator* iter, | |
325 param_type* r) { | |
326 int size; | |
327 // ReadLength() checks for < 0 itself. | |
328 if (!iter->ReadLength(&size)) | |
329 return false; | |
330 // For a fixed size array, a size mismatch indicates invalid data. | |
331 if (size != Size) | |
332 return false; | |
333 for (size_t i = 0; i < Size; i++) { | |
334 if (!ReadParam(m, iter, &(*r)[i])) | |
335 return false; | |
336 } | |
337 return true; | |
338 } | |
339 static void Log(const param_type& p, std::string* l) { | |
340 l->append("["); | |
341 for (size_t i = 0; i < Size; ++i) { | |
342 if (i != 0) | |
343 l->append(" "); | |
344 LogParam((p[i]), l); | |
345 } | |
346 l->append("]"); | |
347 } | |
348 }; | |
349 | |
310 // STL ParamTraits ------------------------------------------------------------- | 350 // STL ParamTraits ------------------------------------------------------------- |
311 | 351 |
312 template <> | 352 template <> |
313 struct ParamTraits<std::string> { | 353 struct ParamTraits<std::string> { |
314 typedef std::string param_type; | 354 typedef std::string param_type; |
315 static void GetSize(base::PickleSizer* sizer, const param_type& p) { | 355 static void GetSize(base::PickleSizer* sizer, const param_type& p) { |
316 sizer->AddString(p); | 356 sizer->AddString(p); |
317 } | 357 } |
318 static void Write(base::Pickle* m, const param_type& p) { m->WriteString(p); } | 358 static void Write(base::Pickle* m, const param_type& p) { m->WriteString(p); } |
319 static bool Read(const base::Pickle* m, | 359 static bool Read(const base::Pickle* m, |
(...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1139 template <class ReplyParamType> | 1179 template <class ReplyParamType> |
1140 inline void LogReplyParamsToMessage(const ReplyParamType& reply_params, | 1180 inline void LogReplyParamsToMessage(const ReplyParamType& reply_params, |
1141 const Message* msg) {} | 1181 const Message* msg) {} |
1142 | 1182 |
1143 inline void ConnectMessageAndReply(const Message* msg, Message* reply) {} | 1183 inline void ConnectMessageAndReply(const Message* msg, Message* reply) {} |
1144 #endif | 1184 #endif |
1145 | 1185 |
1146 } // namespace IPC | 1186 } // namespace IPC |
1147 | 1187 |
1148 #endif // IPC_IPC_MESSAGE_UTILS_H_ | 1188 #endif // IPC_IPC_MESSAGE_UTILS_H_ |
OLD | NEW |