|
| 1 | +// |
| 2 | +// Sources/SwiftProtobuf/Applying.swift - Applying protocol and errors |
| 3 | +// |
| 4 | +// Copyright (c) 2023 Apple Inc. and the project authors |
| 5 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 6 | +// |
| 7 | +// See LICENSE.txt for license information: |
| 8 | +// https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt |
| 9 | +// |
| 10 | +// ----------------------------------------------------------------------------- |
| 11 | +/// |
| 12 | +/// Applying feature (including protocol and errors) |
| 13 | +/// |
| 14 | +// ----------------------------------------------------------------------------- |
| 15 | + |
| 16 | +/// Describes errors can occure during applying a value to proto |
| 17 | +public enum ProtoApplyingError: Error { |
| 18 | + |
| 19 | + /// Describes a mismatch in type of the field |
| 20 | + /// |
| 21 | + /// If a value of type A is applied to a fieldNumber with type B |
| 22 | + /// this error will be thrown by the applying() method. |
| 23 | + case typeMismatch |
| 24 | + |
| 25 | + /// Describes that the fieldNumber is not valid |
| 26 | + /// |
| 27 | + /// If a value is applied to an undefined fieldNumber of the model |
| 28 | + /// this error will be thrown by the applying() method. |
| 29 | + case invalidFieldNumber |
| 30 | +} |
| 31 | + |
| 32 | +public protocol _ProtoApplying: Message { |
| 33 | + |
| 34 | + /// Applies a value on a particular field of a protobuf Message |
| 35 | + /// In cases that value is not appliable, an ProtoApplyingError will be thrown. |
| 36 | + /// |
| 37 | + /// If you wish to use this method, the Applying option in protoc should |
| 38 | + /// be set to true, so that the applying method will be generated for all |
| 39 | + /// the protobuf Messages. |
| 40 | + /// |
| 41 | + /// - Parameters: |
| 42 | + /// - value: any value to be applied on a particular field |
| 43 | + /// - fieldNumber: integer index refering to a field of proto model |
| 44 | + /// - Returns: a copy of the model which the value has been applied on it. |
| 45 | + func applying(_ value: Any, for fieldNumber: Int) throws -> Self |
| 46 | +} |
0 commit comments