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

Side by Side Diff: ipc/ipc_message_repeated_field_utils.h

Issue 2968003005: Support Serializing and Deserializing RepeatedField / RepeatedPtrField in IPC::Message (Closed)
Patch Set: Update IsPickleSizeSufficent to avoid GetSize Created 3 years, 5 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
OLDNEW
(Empty)
1 // Copyright 2017 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 IPC_IPC_MESSAGE_REPEATED_FIELD_UTILS_H_
6 #define IPC_IPC_MESSAGE_REPEATED_FIELD_UTILS_H_
7
8 #include "build/build_config.h"
9
10 #if defined(OS_NACL_NONSFI)
11 static_assert(false,
12 "ipc_message_repeated_field_utils is not able to work with "
13 "nacl_nonsfi configuration.");
14 #endif
15
16 #include "base/pickle.h"
17 #include "ipc/ipc_param_traits.h"
18 #include "ipc/ipc_message_utils.h"
19 #include "third_party/protobuf/src/google/protobuf/repeated_field.h"
20
21 namespace IPC {
22
23 template <template<class> class RepeatedFieldLike, class P>
24 struct RepeatedFieldParamTraits {
25 typedef RepeatedFieldLike<P> param_type;
26 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
27 GetParamSize(sizer, p.size());
28 for (int i = 0; i < p.size(); i++)
29 GetParamSize(sizer, p.Get(i));
30 }
31 static void Write(base::Pickle* m, const param_type& p) {
32 WriteParam(m, p.size());
33 for (int i = 0; i < p.size(); i++)
34 WriteParam(m, p.Get(i));
35 }
36 static bool Read(const base::Pickle* m,
37 base::PickleIterator* iter,
38 param_type* r) {
39 int size;
40 // ReadLength() checks for < 0 itself.
41 if (!iter->ReadLength(&size))
42 return false;
43 if (!IsPickleSizeSufficient<P>(m, size))
44 return false;
45 r->Reserve(size);
46 for (int i = 0; i < size; i++) {
47 if (!ReadParam(m, iter, r->Add()))
48 return false;
49 }
50 return true;
51 }
52 static void Log(const param_type& p, std::string* l) {
53 for (int i = 0; i < p.size(); ++i) {
54 if (i != 0)
55 l->append(" ");
56 LogParam(p.Get(i), l);
57 }
58 }
59 };
60
61 template <class P>
62 struct ParamTraits<google::protobuf::RepeatedField<P>> :
63 RepeatedFieldParamTraits<google::protobuf::RepeatedField, P> {};
64
65 template <class P>
66 struct ParamTraits<google::protobuf::RepeatedPtrField<P>> :
67 RepeatedFieldParamTraits<google::protobuf::RepeatedPtrField, P> {};
68
69 } // namespace IPC
70
71 #endif // IPC_IPC_MESSAGE_REPEATED_FIELD_UTILS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698