Chromium Code Reviews| Index: ppapi/proxy/content_decryptor_private_serializer-inl.h |
| diff --git a/ppapi/proxy/content_decryptor_private_serializer-inl.h b/ppapi/proxy/content_decryptor_private_serializer-inl.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3a87e4749b96f0d2b3bbb6fb04f193dfd2930474 |
| --- /dev/null |
| +++ b/ppapi/proxy/content_decryptor_private_serializer-inl.h |
| @@ -0,0 +1,55 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
|
Tom Finegan
2012/08/20 21:31:45
Two questions about this file:
1) Is this file sm
dmichael (off chromium)
2012/08/21 17:37:08
Yeah, we don't use the -inl suffix anywhere else i
Tom Finegan
2012/08/21 22:57:38
Done.
|
| +#ifndef PPAPI_PROXY_CONTENT_DECRYPTOR_PRIVATE_SERIALIZER_INL_H_ |
| +#define PPAPI_PROXY_CONTENT_DECRYPTOR_PRIVATE_SERIALIZER_INL_H_ |
| + |
| +#include <cstring> |
| +#include <string> |
| + |
| +#include "ppapi/c/private/pp_content_decryptor.h" |
| + |
| +namespace ppapi { |
| +namespace proxy { |
| + |
| +// Serialization/deserialization utility functions for storing/extracting |
| +// PP_{De|En}cryptedBlockInfo structs within std::string's for passing through |
| +// IPC. Return true upon success, and false upon failure. |
|
xhwang
2012/08/20 22:19:31
nit: Return+s+
Tom Finegan
2012/08/20 22:50:03
Done, but did s/Return/Both functions return/ inst
|
| +// |
| +// Note, these functions check the size of |block_info| against the size of |
| +// the "serialized" data stored within |serialized_block_info|, and will report |
| +// failure if expectations are not met. Use of CHECK/DCHECK has been avoided |
| +// because the functions are intended for use on both sides of the IPC proxy. |
| + |
| +template <typename T> |
| +bool SerializeBlockInfo(const T* block_info, |
|
xhwang
2012/08/20 22:19:31
Google style strongly recommends passing const ref
Tom Finegan
2012/08/20 22:50:03
Done.
|
| + std::string* serialized_block_info) { |
| + if (!block_info || !serialized_block_info) |
| + return false; |
| + |
| + if (serialized_block_info->size() != sizeof(T)) |
|
xhwang
2012/08/20 22:19:31
If we pass block_info as ref, we can use "sizeof(b
Tom Finegan
2012/08/20 22:50:03
Done/bug fixed.
|
| + return false; |
| + |
| + serialized_block_info->assign(reinterpret_cast<const char*>(block_info), |
| + sizeof(T)); |
| + return true; |
| +} |
| + |
| +template <typename T> |
| +bool DeserializeBlockInfo(const std::string& serialized_block_info, |
| + T* block_info) { |
| + if (!block_info) |
| + return false; |
| + |
| + if (serialized_block_info.size() != sizeof(T)) |
| + return false; |
| + |
| + std::memcpy(block_info, serialized_block_info.data(), sizeof(T)); |
| + return true; |
| +} |
| + |
| +} // namespace proxy |
| +} // namespace ppapi |
| + |
| +#endif // PPAPI_PROXY_CONTENT_DECRYPTOR_PRIVATE_SERIALIZER_INL_H_ |