OLD | NEW |
| (Empty) |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_COMMON_SAFE_BROWSING_PROTOBUF_MESSAGE_PARAM_TRAITS_H_ | |
6 #define CHROME_COMMON_SAFE_BROWSING_PROTOBUF_MESSAGE_PARAM_TRAITS_H_ | |
7 | |
8 #include <limits.h> | |
9 | |
10 #include <string> | |
11 | |
12 #include "base/pickle.h" | |
13 #include "ipc/ipc_message.h" | |
14 #include "ipc/ipc_param_traits.h" | |
15 #include "third_party/protobuf/src/google/protobuf/repeated_field.h" | |
16 | |
17 namespace IPC { | |
18 | |
19 template <class Element> | |
20 struct ParamTraits<google::protobuf::RepeatedPtrField<Element>> { | |
21 typedef google::protobuf::RepeatedPtrField<Element> param_type; | |
22 | |
23 static void GetSize(base::PickleSizer* s, const param_type& p) { | |
24 GetParamSize(s, p.size()); | |
25 for (const auto& element : p) | |
26 GetParamSize(s, element); | |
27 } | |
28 | |
29 static void Write(base::Pickle* m, const param_type& p) { | |
30 WriteParam(m, p.size()); | |
31 for (const auto& element : p) | |
32 WriteParam(m, element); | |
33 } | |
34 | |
35 static bool Read(const base::Pickle* m, | |
36 base::PickleIterator* iter, | |
37 param_type* p) { | |
38 int size; | |
39 if (!iter->ReadLength(&size) || size < 0) | |
40 return false; | |
41 if (INT_MAX / static_cast<int>(sizeof(void*)) <= size) | |
42 return false; | |
43 p->Clear(); | |
44 p->Reserve(size); | |
45 while (size--) { | |
46 if (!ReadParam(m, iter, p->Add())) | |
47 return false; | |
48 } | |
49 return true; | |
50 } | |
51 | |
52 static void Log(const param_type& p, std::string* l) { | |
53 bool logged_first = false; | |
54 for (const auto& element : p) { | |
55 if (logged_first) | |
56 l->push_back(' '); | |
57 else | |
58 logged_first = true; | |
59 LogParam(element, l); | |
60 } | |
61 } | |
62 }; | |
63 | |
64 } // namespace IPC | |
65 | |
66 #endif // CHROME_COMMON_SAFE_BROWSING_PROTOBUF_MESSAGE_PARAM_TRAITS_H_ | |
OLD | NEW |