| 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 // Protobuf Messages over IPC |
| 6 // |
| 7 // Protobuf messages are registered with IPC_PROTOBUF_MESSAGE_TRAITS_BEGIN() and |
| 8 // friends in much the same way as other externally-defined structs (see |
| 9 // ipc/ipc_message_macros.h). These macros also cause only registration of the |
| 10 // protobuf message type IPC with message generation. Within matching calls to |
| 11 // _BEGIN() and _END(), one may use: |
| 12 // - IPC_PROTOBUF_MESSAGE_TRAITS_OPTIONAL_FUNDAMENTAL_MEMBER() to register an |
| 13 // optional field of fundamental type (any scalar message field type save |
| 14 // "string" and "bytes"). |
| 15 // - IPC_PROTOBUF_MESSAGE_TRAITS_OPTIONAL_COMPLEX_MEMBER() to register an |
| 16 // optional field of complex type (scalar message field type "string" or |
| 17 // "bytes", or another message type). |
| 18 // - IPC_PROTOBUF_MESSAGE_TRAITS_REPEATED_COMPLEX_MEMBER() to register a |
| 19 // repeated field of complex type (scalar message field type "string" or |
| 20 // "bytes", or another message type). |
| 21 // |
| 22 // Enum types in protobuf messages are registered with |
| 23 // IPC_ENUM_TRAITS_VALIDATE() as with any other enum. In this case, the |
| 24 // validation expression should be the _IsValid() function provided by the |
| 25 // generated protobuf code. For example: |
| 26 // |
| 27 // IPC_ENUM_TRAITS_VALIDATE(MyEnumType, MyEnumType_IsValid(value)) |
| 28 |
| 29 #ifndef CHROME_COMMON_SAFE_BROWSING_IPC_PROTOBUF_MESSAGE_MACROS_H_ |
| 30 #define CHROME_COMMON_SAFE_BROWSING_IPC_PROTOBUF_MESSAGE_MACROS_H_ |
| 31 |
| 32 #include <string> |
| 33 |
| 34 #define IPC_PROTOBUF_MESSAGE_TRAITS_BEGIN(message_name) \ |
| 35 namespace IPC { \ |
| 36 template <> \ |
| 37 struct IPC_MESSAGE_EXPORT ParamTraits<message_name> { \ |
| 38 typedef message_name param_type; \ |
| 39 static void Write(Message* m, const param_type& p); \ |
| 40 static bool Read(const Message* m, PickleIterator* iter, param_type* p); \ |
| 41 static void Log(const param_type& p, std::string* l); \ |
| 42 \ |
| 43 private: \ |
| 44 template <class P> \ |
| 45 static bool ReadParamF(const Message* m, \ |
| 46 PickleIterator* iter, \ |
| 47 param_type* p, \ |
| 48 void (param_type::*setter_function)(P)); \ |
| 49 }; \ |
| 50 } // namespace IPC |
| 51 |
| 52 #define IPC_PROTOBUF_MESSAGE_TRAITS_OPTIONAL_FUNDAMENTAL_MEMBER(name) |
| 53 #define IPC_PROTOBUF_MESSAGE_TRAITS_OPTIONAL_COMPLEX_MEMBER(name) |
| 54 #define IPC_PROTOBUF_MESSAGE_TRAITS_REPEATED_COMPLEX_MEMBER(name) |
| 55 #define IPC_PROTOBUF_MESSAGE_TRAITS_END() |
| 56 |
| 57 #endif // CHROME_COMMON_SAFE_BROWSING_IPC_PROTOBUF_MESSAGE_MACROS_H_ |
| OLD | NEW |