serialization_traits.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. *
  3. * Copyright 2015 gRPC authors.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. #ifndef GRPCPP_IMPL_CODEGEN_SERIALIZATION_TRAITS_H
  19. #define GRPCPP_IMPL_CODEGEN_SERIALIZATION_TRAITS_H
  20. // IWYU pragma: private, include <grpcpp/impl/serialization_traits.h>
  21. namespace grpc {
  22. /// Defines how to serialize and deserialize some type.
  23. ///
  24. /// Used for hooking different message serialization API's into GRPC.
  25. /// Each SerializationTraits<Message> implementation must provide the
  26. /// following functions:
  27. /// 1. static Status Serialize(const Message& msg,
  28. /// ByteBuffer* buffer,
  29. /// bool* own_buffer);
  30. /// OR
  31. /// static Status Serialize(const Message& msg,
  32. /// grpc_byte_buffer** buffer,
  33. /// bool* own_buffer);
  34. /// The former is preferred; the latter is deprecated
  35. ///
  36. /// 2. static Status Deserialize(ByteBuffer* buffer,
  37. /// Message* msg);
  38. /// OR
  39. /// static Status Deserialize(grpc_byte_buffer* buffer,
  40. /// Message* msg);
  41. /// The former is preferred; the latter is deprecated
  42. ///
  43. /// Serialize is required to convert message to a ByteBuffer, and
  44. /// return that byte buffer through *buffer. *own_buffer should
  45. /// be set to true if the caller owns said byte buffer, or false if
  46. /// ownership is retained elsewhere.
  47. ///
  48. /// Deserialize is required to convert buffer into the message stored at
  49. /// msg. max_receive_message_size is passed in as a bound on the maximum
  50. /// number of message bytes Deserialize should accept.
  51. ///
  52. /// Both functions return a Status, allowing them to explain what went
  53. /// wrong if required.
  54. template <class Message,
  55. class UnusedButHereForPartialTemplateSpecialization = void>
  56. class SerializationTraits;
  57. } // namespace grpc
  58. #endif // GRPCPP_IMPL_CODEGEN_SERIALIZATION_TRAITS_H