@@ -45,8 +45,8 @@ struct ActorAddress: Sendable, Hashable, Codable {
4545//final class FakeActorSystem: DistributedActorSystem {
4646struct FakeActorSystem : DistributedActorSystem {
4747 typealias ActorID = ActorAddress
48- typealias InvocationDecoder = FakeInvocation
49- typealias InvocationEncoder = FakeInvocation
48+ typealias InvocationDecoder = FakeInvocationDecoder
49+ typealias InvocationEncoder = FakeInvocationEncoder
5050 typealias SerializationRequirement = Codable
5151
5252 init ( ) { }
@@ -105,16 +105,17 @@ struct FakeActorSystem: DistributedActorSystem {
105105
106106}
107107
108- struct FakeInvocation : DistributedTargetInvocationEncoder , DistributedTargetInvocationDecoder {
108+
109+ struct FakeInvocationEncoder : DistributedTargetInvocationEncoder {
109110 typealias SerializationRequirement = Codable
110111
111- var types : [ Any . Type ] = [ ]
112+ var substitutions : [ Any . Type ] = [ ]
112113 var arguments : [ Any ] = [ ]
113114 var returnType : Any . Type ? = nil
114115 var errorType : Any . Type ? = nil
115116
116117 mutating func recordGenericSubstitution< T> ( _ type: T . Type ) throws {
117- types . append ( type)
118+ substitutions . append ( type)
118119 }
119120 mutating func recordArgument< Argument: SerializationRequirement > ( _ argument: Argument ) throws {
120121 arguments. append ( argument)
@@ -127,17 +128,45 @@ struct FakeInvocation: DistributedTargetInvocationEncoder, DistributedTargetInvo
127128 }
128129 mutating func doneRecording( ) throws { }
129130
130- // === Receiving / decoding -------------------------------------------------
131+ // For testing only
132+ func makeDecoder( ) -> FakeInvocationDecoder {
133+ return . init(
134+ args: arguments,
135+ substitutions: substitutions,
136+ returnType: returnType,
137+ errorType: errorType
138+ )
139+ }
140+ }
141+
142+
143+ class FakeInvocationDecoder : DistributedTargetInvocationDecoder {
144+ typealias SerializationRequirement = Codable
131145
146+ var arguments : [ Any ] = [ ]
147+ var substitutions : [ Any . Type ] = [ ]
148+ var returnType : Any . Type ? = nil
149+ var errorType : Any . Type ? = nil
150+
151+ init (
152+ args: [ Any ] ,
153+ substitutions: [ Any . Type ] = [ ] ,
154+ returnType: Any . Type ? = nil ,
155+ errorType: Any . Type ? = nil
156+ ) {
157+ self . arguments = args
158+ self . substitutions = substitutions
159+ self . returnType = returnType
160+ self . errorType = errorType
161+ }
162+
163+ // === Receiving / decoding -------------------------------------------------
132164 func decodeGenericSubstitutions( ) throws -> [ Any . Type ] {
133- [ ]
165+ return substitutions
134166 }
135167
136168 var argumentIndex : Int = 0
137- mutating func decodeNextArgument< Argument> (
138- _ argumentType: Argument . Type ,
139- into pointer: UnsafeMutablePointer < Argument >
140- ) throws {
169+ func decodeNextArgument< Argument: SerializationRequirement > ( ) throws -> Argument {
141170 guard argumentIndex < arguments. count else {
142171 fatalError ( " Attempted to decode more arguments than stored! Index: \( argumentIndex) , args: \( arguments) " )
143172 }
@@ -148,16 +177,18 @@ struct FakeInvocation: DistributedTargetInvocationEncoder, DistributedTargetInvo
148177 }
149178
150179 print ( " > decode argument: \( argument) " )
151- pointer. pointee = argument
152180 argumentIndex += 1
181+ return argument
153182 }
154183
155- func decodeErrorType( ) throws -> Any . Type ? {
156- self . errorType
184+ public func decodeErrorType( ) throws -> Any . Type ? {
185+ print ( " > decode return type: \( errorType. map { String ( describing: $0) } ?? " nil " ) " )
186+ return self . errorType
157187 }
158188
159- func decodeReturnType( ) throws -> Any . Type ? {
160- self . returnType
189+ public func decodeReturnType( ) throws -> Any . Type ? {
190+ print ( " > decode return type: \( returnType. map { String ( describing: $0) } ?? " nil " ) " )
191+ return self . returnType
161192 }
162193}
163194
0 commit comments