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

Side by Side Diff: ipc/ipc_message_utils.h

Issue 2686503004: Add IPC ParamTraits for c-style arrays (Closed)
Patch Set: feedback Created 3 years, 10 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 | « cc/ipc/cc_param_traits_macros.h ('k') | ppapi/proxy/ppapi_messages.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 #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
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 static_assert(
313 Size <= std::numeric_limits<int>::max(),
314 "ParamTraits for fixed-size arrays only supports sizes under max int.");
315 using param_type = P[Size];
316 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
317 GetParamSize(sizer, static_cast<int>(Size));
318 for (size_t i = 0; i < Size; i++)
319 GetParamSize(sizer, p[i]);
320 }
321 static void Write(base::Pickle* m, const param_type& p) {
322 WriteParam(m, static_cast<int>(Size));
323 for (size_t i = 0; i < Size; i++)
324 WriteParam(m, p[i]);
325 }
326 static bool Read(const base::Pickle* m,
327 base::PickleIterator* iter,
328 param_type* r) {
329 int size;
330 // ReadLength() checks for < 0 itself.
331 if (!iter->ReadLength(&size))
332 return false;
333 // For a fixed size array, a size mismath indicates invalid data.
dcheng 2017/02/08 19:21:11 Nit: mismatch
ericrk 2017/02/08 21:07:15 Done.
334 if (size != Size)
335 return false;
336 for (size_t i = 0; i < Size; i++) {
337 if (!ReadParam(m, iter, &(*r)[i]))
338 return false;
339 }
340 return true;
341 }
342 static void Log(const param_type& p, std::string* l) {
343 for (size_t i = 0; i < Size; ++i) {
vmpstr 2017/02/08 20:06:11 drive-by: In the other files where we do something
ericrk 2017/02/08 21:07:15 This is pretty inconsistent - CC already has trait
344 if (i != 0)
345 l->append(" ");
346 LogParam((p[i]), l);
347 }
348 }
349 };
350
310 // STL ParamTraits ------------------------------------------------------------- 351 // STL ParamTraits -------------------------------------------------------------
311 352
312 template <> 353 template <>
313 struct ParamTraits<std::string> { 354 struct ParamTraits<std::string> {
314 typedef std::string param_type; 355 typedef std::string param_type;
315 static void GetSize(base::PickleSizer* sizer, const param_type& p) { 356 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
316 sizer->AddString(p); 357 sizer->AddString(p);
317 } 358 }
318 static void Write(base::Pickle* m, const param_type& p) { m->WriteString(p); } 359 static void Write(base::Pickle* m, const param_type& p) { m->WriteString(p); }
319 static bool Read(const base::Pickle* m, 360 static bool Read(const base::Pickle* m,
(...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after
1139 template <class ReplyParamType> 1180 template <class ReplyParamType>
1140 inline void LogReplyParamsToMessage(const ReplyParamType& reply_params, 1181 inline void LogReplyParamsToMessage(const ReplyParamType& reply_params,
1141 const Message* msg) {} 1182 const Message* msg) {}
1142 1183
1143 inline void ConnectMessageAndReply(const Message* msg, Message* reply) {} 1184 inline void ConnectMessageAndReply(const Message* msg, Message* reply) {}
1144 #endif 1185 #endif
1145 1186
1146 } // namespace IPC 1187 } // namespace IPC
1147 1188
1148 #endif // IPC_IPC_MESSAGE_UTILS_H_ 1189 #endif // IPC_IPC_MESSAGE_UTILS_H_
OLDNEW
« no previous file with comments | « cc/ipc/cc_param_traits_macros.h ('k') | ppapi/proxy/ppapi_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698