[Android] Offer all TouchMoves to Javascript if TouchStart is consumed
[chromium-blink-merge.git] / ppapi / proxy / content_decryptor_private_serializer.h
blob249b01cace31828b43c4f1de6d45d730be326a0b
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 #ifndef PPAPI_PROXY_CONTENT_DECRYPTOR_PRIVATE_SERIALIZER_H_
6 #define PPAPI_PROXY_CONTENT_DECRYPTOR_PRIVATE_SERIALIZER_H_
8 #include <cstring>
9 #include <string>
11 #include "ppapi/c/private/pp_content_decryptor.h"
13 namespace ppapi {
14 namespace proxy {
16 // Serialization/deserialization utility functions for storing/extracting
17 // PP_DecryptedBlockInfo, PP_EncryptedBlockInfo, and PP_DecompressedFrameInfo
18 // structs within std::string's for passing through IPC. Both functions return
19 // true upon success, and false upon failure.
21 // Note, these functions check the size of |block_info| against the size of
22 // the "serialized" data stored within |serialized_block_info|, and will report
23 // failure if expectations are not met. Use of CHECK/DCHECK has been avoided
24 // because the functions are intended for use on both sides of the IPC proxy.
26 template <typename T>
27 bool SerializeBlockInfo(const T& block_info,
28 std::string* serialized_block_info) {
29 if (!serialized_block_info)
30 return false;
32 serialized_block_info->assign(reinterpret_cast<const char*>(&block_info),
33 sizeof(block_info));
35 if (serialized_block_info->size() != sizeof(block_info))
36 return false;
38 return true;
41 template <typename T>
42 bool DeserializeBlockInfo(const std::string& serialized_block_info,
43 T* block_info) {
44 if (!block_info)
45 return false;
47 if (serialized_block_info.size() != sizeof(*block_info))
48 return false;
50 std::memcpy(block_info, serialized_block_info.data(), sizeof(*block_info));
51 return true;
54 } // namespace proxy
55 } // namespace ppapi
57 #endif // PPAPI_PROXY_CONTENT_DECRYPTOR_PRIVATE_SERIALIZER_H_