• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 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 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_HANDLE_SERIALIZATION_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_HANDLE_SERIALIZATION_H_
7 
8 #include "mojo/public/cpp/bindings/lib/bindings_internal.h"
9 #include "mojo/public/cpp/bindings/lib/serialization_context.h"
10 #include "mojo/public/cpp/bindings/lib/serialization_forward.h"
11 #include "mojo/public/cpp/system/handle.h"
12 
13 namespace mojo {
14 namespace internal {
15 
16 template <typename T>
17 struct Serializer<ScopedHandleBase<T>, ScopedHandleBase<T>> {
18   static void Serialize(ScopedHandleBase<T>& input,
19                         Handle_Data* output,
20                         SerializationContext* context) {
21     context->AddHandle(ScopedHandle::From(std::move(input)), output);
22   }
23 
24   static bool Deserialize(Handle_Data* input,
25                           ScopedHandleBase<T>* output,
26                           SerializationContext* context) {
27     *output = context->TakeHandleAs<T>(*input);
28     return true;
29   }
30 };
31 
32 }  // namespace internal
33 }  // namespace mojo
34 
35 #endif  // MOJO_PUBLIC_CPP_BINDINGS_LIB_HANDLE_SERIALIZATION_H_
36