ExtensionMap.swift 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Sources/SwiftProtobuf/ExtensionMap.swift - Extension support
  2. //
  3. // Copyright (c) 2014 - 2017 Apple Inc. and the project authors
  4. // Licensed under Apache License v2.0 with Runtime Library Exception
  5. //
  6. // See LICENSE.txt for license information:
  7. // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt
  8. //
  9. // -----------------------------------------------------------------------------
  10. ///
  11. /// A set of extensions that can be passed into deserializers
  12. /// to provide details of the particular extensions that should
  13. /// be recognized.
  14. ///
  15. // -----------------------------------------------------------------------------
  16. /// A collection of extension objects.
  17. ///
  18. /// An `ExtensionMap` is used during decoding to look up
  19. /// extension objects corresponding to the serialized data.
  20. ///
  21. /// This is a protocol so that developers can build their own
  22. /// extension handling if they need something more complex than the
  23. /// standard `SimpleExtensionMap` implementation.
  24. @preconcurrency
  25. public protocol ExtensionMap: Sendable {
  26. /// Returns the extension object describing an extension or nil
  27. subscript(messageType: any Message.Type, fieldNumber: Int) -> (any AnyMessageExtension)? { get }
  28. /// Returns the field number for a message with a specific field name
  29. ///
  30. /// The field name here matches the format used by the protobuf
  31. /// Text serialization: it typically looks like
  32. /// `package.message.field_name`, where `package` is the package
  33. /// for the proto file and `message` is the name of the message in
  34. /// which the extension was defined. (This is different from the
  35. /// message that is being extended!)
  36. func fieldNumberForProto(messageType: any Message.Type, protoFieldName: String) -> Int?
  37. }