Add ICU message format support
[chromium-blink-merge.git] / content / common / content_param_traits.cc
blob2924d61a35bc6e4091c60d36a1b76f08742cb092
1 // Copyright (c) 2012 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.
5 #include "content/common/content_param_traits.h"
7 #include "base/strings/string_number_conversions.h"
8 #include "content/common/input/web_input_event_traits.h"
9 #include "net/base/ip_endpoint.h"
11 namespace IPC {
13 void ParamTraits<WebInputEventPointer>::Write(Message* m, const param_type& p) {
14 m->WriteData(reinterpret_cast<const char*>(p), p->size);
17 bool ParamTraits<WebInputEventPointer>::Read(const Message* m,
18 base::PickleIterator* iter,
19 param_type* r) {
20 const char* data;
21 int data_length;
22 if (!iter->ReadData(&data, &data_length)) {
23 NOTREACHED();
24 return false;
26 if (data_length < static_cast<int>(sizeof(blink::WebInputEvent))) {
27 NOTREACHED();
28 return false;
30 param_type event = reinterpret_cast<param_type>(data);
31 // Check that the data size matches that of the event.
32 if (data_length != static_cast<int>(event->size)) {
33 NOTREACHED();
34 return false;
36 const size_t expected_size_for_type =
37 content::WebInputEventTraits::GetSize(event->type);
38 if (data_length != static_cast<int>(expected_size_for_type)) {
39 NOTREACHED();
40 return false;
42 *r = event;
43 return true;
46 void ParamTraits<WebInputEventPointer>::Log(const param_type& p,
47 std::string* l) {
48 l->append("(");
49 LogParam(p->size, l);
50 l->append(", ");
51 LogParam(p->type, l);
52 l->append(", ");
53 LogParam(p->timeStampSeconds, l);
54 l->append(")");
57 } // namespace IPC
59 // Generate param traits write methods.
60 #include "ipc/param_traits_write_macros.h"
61 namespace IPC {
62 #undef CONTENT_COMMON_CONTENT_PARAM_TRAITS_MACROS_H_
63 #include "content/common/content_param_traits_macros.h"
64 } // namespace IPC
66 // Generate param traits read methods.
67 #include "ipc/param_traits_read_macros.h"
68 namespace IPC {
69 #undef CONTENT_COMMON_CONTENT_PARAM_TRAITS_MACROS_H_
70 #include "content/common/content_param_traits_macros.h"
71 } // namespace IPC
73 // Generate param traits log methods.
74 #include "ipc/param_traits_log_macros.h"
75 namespace IPC {
76 #undef CONTENT_COMMON_CONTENT_PARAM_TRAITS_MACROS_H_
77 #include "content/common/content_param_traits_macros.h"
78 } // namespace IPC