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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ipc/ipc_message_utils.h
diff --git a/ipc/ipc_message_utils.h b/ipc/ipc_message_utils.h
index 58d6aa26da34fb125d45bd9f2ddd3f767a2f7313..1da8a65ad4b6e3275e347ca11d29c403b7ed344c 100644
--- a/ipc/ipc_message_utils.h
+++ b/ipc/ipc_message_utils.h
@@ -307,6 +307,47 @@ struct IPC_EXPORT ParamTraits<double> {
static void Log(const param_type& p, std::string* l);
};
+template <class P, size_t Size>
+struct ParamTraits<P[Size]> {
+ static_assert(
+ Size <= std::numeric_limits<int>::max(),
+ "ParamTraits for fixed-size arrays only supports sizes under max int.");
+ using param_type = P[Size];
+ static void GetSize(base::PickleSizer* sizer, const param_type& p) {
+ GetParamSize(sizer, static_cast<int>(Size));
+ for (size_t i = 0; i < Size; i++)
+ GetParamSize(sizer, p[i]);
+ }
+ static void Write(base::Pickle* m, const param_type& p) {
+ WriteParam(m, static_cast<int>(Size));
+ for (size_t i = 0; i < Size; i++)
+ WriteParam(m, p[i]);
+ }
+ static bool Read(const base::Pickle* m,
+ base::PickleIterator* iter,
+ param_type* r) {
+ int size;
+ // ReadLength() checks for < 0 itself.
+ if (!iter->ReadLength(&size))
+ return false;
+ // 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.
+ if (size != Size)
+ return false;
+ for (size_t i = 0; i < Size; i++) {
+ if (!ReadParam(m, iter, &(*r)[i]))
+ return false;
+ }
+ return true;
+ }
+ static void Log(const param_type& p, std::string* l) {
+ 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
+ if (i != 0)
+ l->append(" ");
+ LogParam((p[i]), l);
+ }
+ }
+};
+
// STL ParamTraits -------------------------------------------------------------
template <>
« 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