GRPCProtobufPayload.swift 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright 2020, gRPC Authors All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import NIO
  17. import SwiftProtobuf
  18. /// Provides default implementations of `GRPCPayload` for `SwiftProtobuf.Message`s.
  19. public protocol GRPCProtobufPayload: GRPCPayload, Message {}
  20. public extension GRPCProtobufPayload {
  21. init(serializedByteBuffer: inout NIO.ByteBuffer) throws {
  22. try self.init(contiguousBytes: serializedByteBuffer.readableBytesView)
  23. }
  24. func serialize(into buffer: inout NIO.ByteBuffer) throws {
  25. let data = try self.serializedData()
  26. buffer.writeBytes(data)
  27. }
  28. }
  29. // SwiftProtobuf ships a bunch of different messages. We'll provide conformance to them here to
  30. // avoid having to generate the conformance.
  31. //
  32. // See: https://github.com/grpc/grpc-swift/issues/801
  33. extension Google_Protobuf_Any: GRPCProtobufPayload {}
  34. extension Google_Protobuf_Api: GRPCProtobufPayload {}
  35. extension Google_Protobuf_BoolValue: GRPCProtobufPayload {}
  36. extension Google_Protobuf_BytesValue: GRPCProtobufPayload {}
  37. extension Google_Protobuf_DescriptorProto: GRPCProtobufPayload {}
  38. extension Google_Protobuf_DoubleValue: GRPCProtobufPayload {}
  39. extension Google_Protobuf_Duration: GRPCProtobufPayload {}
  40. extension Google_Protobuf_Empty: GRPCProtobufPayload {}
  41. extension Google_Protobuf_Enum: GRPCProtobufPayload {}
  42. extension Google_Protobuf_EnumDescriptorProto: GRPCProtobufPayload {}
  43. extension Google_Protobuf_EnumOptions: GRPCProtobufPayload {}
  44. extension Google_Protobuf_EnumValue: GRPCProtobufPayload {}
  45. extension Google_Protobuf_EnumValueDescriptorProto: GRPCProtobufPayload {}
  46. extension Google_Protobuf_EnumValueOptions: GRPCProtobufPayload {}
  47. extension Google_Protobuf_ExtensionRangeOptions: GRPCProtobufPayload {}
  48. extension Google_Protobuf_Field: GRPCProtobufPayload {}
  49. extension Google_Protobuf_FieldDescriptorProto: GRPCProtobufPayload {}
  50. extension Google_Protobuf_FieldMask: GRPCProtobufPayload {}
  51. extension Google_Protobuf_FieldOptions: GRPCProtobufPayload {}
  52. extension Google_Protobuf_FileDescriptorProto: GRPCProtobufPayload {}
  53. extension Google_Protobuf_FileDescriptorSet: GRPCProtobufPayload {}
  54. extension Google_Protobuf_FileOptions: GRPCProtobufPayload {}
  55. extension Google_Protobuf_FloatValue: GRPCProtobufPayload {}
  56. extension Google_Protobuf_GeneratedCodeInfo: GRPCProtobufPayload {}
  57. extension Google_Protobuf_Int32Value: GRPCProtobufPayload {}
  58. extension Google_Protobuf_Int64Value: GRPCProtobufPayload {}
  59. extension Google_Protobuf_ListValue: GRPCProtobufPayload {}
  60. extension Google_Protobuf_MessageOptions: GRPCProtobufPayload {}
  61. extension Google_Protobuf_Method: GRPCProtobufPayload {}
  62. extension Google_Protobuf_MethodDescriptorProto: GRPCProtobufPayload {}
  63. extension Google_Protobuf_MethodOptions: GRPCProtobufPayload {}
  64. extension Google_Protobuf_Mixin: GRPCProtobufPayload {}
  65. extension Google_Protobuf_OneofDescriptorProto: GRPCProtobufPayload {}
  66. extension Google_Protobuf_OneofOptions: GRPCProtobufPayload {}
  67. extension Google_Protobuf_Option: GRPCProtobufPayload {}
  68. extension Google_Protobuf_ServiceDescriptorProto: GRPCProtobufPayload {}
  69. extension Google_Protobuf_ServiceOptions: GRPCProtobufPayload {}
  70. extension Google_Protobuf_SourceCodeInfo: GRPCProtobufPayload {}
  71. extension Google_Protobuf_SourceContext: GRPCProtobufPayload {}
  72. extension Google_Protobuf_StringValue: GRPCProtobufPayload {}
  73. extension Google_Protobuf_Struct: GRPCProtobufPayload {}
  74. extension Google_Protobuf_Timestamp: GRPCProtobufPayload {}
  75. extension Google_Protobuf_Type: GRPCProtobufPayload {}
  76. extension Google_Protobuf_UInt32Value: GRPCProtobufPayload {}
  77. extension Google_Protobuf_UInt64Value: GRPCProtobufPayload {}
  78. extension Google_Protobuf_UninterpretedOption: GRPCProtobufPayload {}
  79. extension Google_Protobuf_Value: GRPCProtobufPayload {}