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_
11 #include "ppapi/c/private/pp_content_decryptor.h"
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.
27 bool SerializeBlockInfo(const T
& block_info
,
28 std::string
* serialized_block_info
) {
29 if (!serialized_block_info
)
32 serialized_block_info
->assign(reinterpret_cast<const char*>(&block_info
),
35 if (serialized_block_info
->size() != sizeof(block_info
))
42 bool DeserializeBlockInfo(const std::string
& serialized_block_info
,
47 if (serialized_block_info
.size() != sizeof(*block_info
))
50 std::memcpy(block_info
, serialized_block_info
.data(), sizeof(*block_info
));
57 #endif // PPAPI_PROXY_CONTENT_DECRYPTOR_PRIVATE_SERIALIZER_H_