| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 r->resize(data_size); | 490 r->resize(data_size); |
| 491 if (data_size) | 491 if (data_size) |
| 492 memcpy(&r->front(), data, data_size); | 492 memcpy(&r->front(), data, data_size); |
| 493 return true; | 493 return true; |
| 494 } | 494 } |
| 495 static void Log(const param_type& p, std::string* l) { | 495 static void Log(const param_type& p, std::string* l) { |
| 496 LogBytes(p, l); | 496 LogBytes(p, l); |
| 497 } | 497 } |
| 498 }; | 498 }; |
| 499 | 499 |
| 500 template <> |
| 501 struct ParamTraits<std::vector<bool> > { |
| 502 typedef std::vector<bool> param_type; |
| 503 static void Write(Message* m, const param_type& p) { |
| 504 WriteParam(m, static_cast<int>(p.size())); |
| 505 for (size_t i = 0; i < p.size(); i++) |
| 506 WriteParam(m, p[i]); |
| 507 } |
| 508 static bool Read(const Message* m, void** iter, param_type* r) { |
| 509 int size; |
| 510 // ReadLength() checks for < 0 itself. |
| 511 if (!m->ReadLength(iter, &size)) |
| 512 return false; |
| 513 r->resize(size); |
| 514 for (int i = 0; i < size; i++) { |
| 515 bool value; |
| 516 if (!ReadParam(m, iter, &value)) |
| 517 return false; |
| 518 (*r)[i] = value; |
| 519 } |
| 520 return true; |
| 521 } |
| 522 static void Log(const param_type& p, std::string* l) { |
| 523 for (size_t i = 0; i < p.size(); ++i) { |
| 524 if (i != 0) |
| 525 l->append(" "); |
| 526 LogParam((p[i]), l); |
| 527 } |
| 528 } |
| 529 }; |
| 530 |
| 500 template <class P> | 531 template <class P> |
| 501 struct ParamTraits<std::vector<P> > { | 532 struct ParamTraits<std::vector<P> > { |
| 502 typedef std::vector<P> param_type; | 533 typedef std::vector<P> param_type; |
| 503 static void Write(Message* m, const param_type& p) { | 534 static void Write(Message* m, const param_type& p) { |
| 504 WriteParam(m, static_cast<int>(p.size())); | 535 WriteParam(m, static_cast<int>(p.size())); |
| 505 for (size_t i = 0; i < p.size(); i++) | 536 for (size_t i = 0; i < p.size(); i++) |
| 506 WriteParam(m, p[i]); | 537 WriteParam(m, p[i]); |
| 507 } | 538 } |
| 508 static bool Read(const Message* m, void** iter, param_type* r) { | 539 static bool Read(const Message* m, void** iter, param_type* r) { |
| 509 int size; | 540 int size; |
| (...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1105 ReplyParam p(a, b, c, d, e); | 1136 ReplyParam p(a, b, c, d, e); |
| 1106 WriteParam(reply, p); | 1137 WriteParam(reply, p); |
| 1107 } | 1138 } |
| 1108 }; | 1139 }; |
| 1109 | 1140 |
| 1110 //----------------------------------------------------------------------------- | 1141 //----------------------------------------------------------------------------- |
| 1111 | 1142 |
| 1112 } // namespace IPC | 1143 } // namespace IPC |
| 1113 | 1144 |
| 1114 #endif // IPC_IPC_MESSAGE_UTILS_H_ | 1145 #endif // IPC_IPC_MESSAGE_UTILS_H_ |
| OLD | NEW |