Skip to content

Commit de3bc2b

Browse files
author
Pouya Yarandi
committed
Separate applying file
1 parent 13701be commit de3bc2b

File tree

3 files changed

+47
-9
lines changed

3 files changed

+47
-9
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
}

Sources/SwiftProtobuf/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ add_library(SwiftProtobuf
33
AnyMessageStorage.swift
44
AnyUnpackError.swift
55
api.pb.swift
6+
Applying.swift
67
BinaryDecoder.swift
78
BinaryDecodingError.swift
89
BinaryDecodingOptions.swift

Sources/SwiftProtobuf/ProtobufMirror.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,3 @@ public extension ProtobufMirror {
303303
}
304304

305305
}
306-
307-
public enum ProtoApplyingError: Error {
308-
case typeMismatch
309-
case invalidFieldNumber
310-
}
311-
312-
public protocol _ProtoApplying: Message {
313-
func applying(_ value: Any, for fieldNumber: Int) throws -> Self
314-
}

0 commit comments

Comments
 (0)