Chromium Code Reviews| Index: ipc/ipc_message_utils.h |
| diff --git a/ipc/ipc_message_utils.h b/ipc/ipc_message_utils.h |
| index 58d6aa26da34fb125d45bd9f2ddd3f767a2f7313..dcbbf6cd8dbd964c5c788aa95304919ed06ee976 100644 |
| --- a/ipc/ipc_message_utils.h |
| +++ b/ipc/ipc_message_utils.h |
| @@ -307,6 +307,46 @@ 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]> { |
| + using param_type = P[Size]; |
| + static void GetSize(base::PickleSizer* sizer, const param_type& p) { |
| + 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
|
| + for (size_t i = 0; i < Size; i++) |
| + GetParamSize(sizer, p[i]); |
| + } |
| + static void Write(base::Pickle* m, const param_type& p) { |
| + WriteParam(m, base::checked_cast<int>(Size)); |
| + 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.
|
| + 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 mismatch indicates invalid data. |
| + 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) { |
| + l->append("["); |
| + for (size_t i = 0; i < Size; ++i) { |
| + if (i != 0) |
| + l->append(" "); |
| + LogParam((p[i]), l); |
| + } |
| + l->append("]"); |
| + } |
| +}; |
| + |
| // STL ParamTraits ------------------------------------------------------------- |
| template <> |