<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Distributed/DistributedTargetInvocationDecoder",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "Distributed"
    ],
    "preciseIdentifier" : "s:11Distributed0A23TargetInvocationDecoderP"
  },
  "title" : "DistributedTargetInvocationDecoder"
}
-->

# DistributedTargetInvocationDecoder

Decoder that must be provided to `executeDistributedTarget` and is used
by the Swift runtime to decode arguments of the invocation.

```
protocol DistributedTargetInvocationDecoder<SerializationRequirement>
```

## Overview

### Decoding DistributedActor arguments using Codable

When using an actor system where `ActorID` is `Codable`, every distributed actor using that system
is also implicitly `Codable` (see [`DistributedActorSystem`](/documentation/Distributed/DistributedActorSystem)). Such distributed actors are encoded
as their `ActorID` stored in an `Encoder.singlevaluecontainer()`. When `Codable` is being used
by such a system, the [`decodeNextArgument()`](/documentation/Distributed/DistributedTargetInvocationDecoder/decodeNextArgument()) method will be using `Decoder` to
decode the incoming values, which may themselves be distributed actors.

An actor system must be provided to the `Decoder` in order for a distributed actor’s `Decodable.init(from:)`
to be able to return the instance of the actor. Specifically, the decoded `ActorID` is passed to the actor system’s `resolve(id:as:)` method in order to
return either a local instance identified by this ID, or creating a remote actor reference.
Thus, you must set the actor system the decoding is performed for, on the decoder’s `userInfo`, as follows:

```
mutating func decodeNextArgument<Argument: SerializationRequirement>() throws -> Argument {
  let argumentData: Data = /// ...
  // ...
  decoder.userInfo[.actorSystemKey] = self.actorSystem
  return try Argument.decode(
}
```

## Topics

### Associated Types

[`associatedtype SerializationRequirement`](/documentation/Distributed/DistributedTargetInvocationDecoder/SerializationRequirement)

The serialization requirement that the types passed to `decodeNextArgument` are required to conform to.
The type returned by `decodeReturnType` is also expected to conform to this associated type requirement.

### Instance Methods

[`func decodeErrorType() throws -> (any Any.Type)?`](/documentation/Distributed/DistributedTargetInvocationDecoder/decodeErrorType())

Decode the specific error type that the distributed invocation target has recorded.
Currently this effectively can only ever be `Error.self`.

[`func decodeGenericSubstitutions() throws -> [any Any.Type]`](/documentation/Distributed/DistributedTargetInvocationDecoder/decodeGenericSubstitutions())

Decode all generic substitutions that were recorded for this invocation.

[`func decodeNextArgument<Argument>() throws -> Argument`](/documentation/Distributed/DistributedTargetInvocationDecoder/decodeNextArgument())

Attempt to decode the next argument from the underlying buffers into pre-allocated storage
pointed at by ‘pointer’.

[`func decodeReturnType() throws -> (any Any.Type)?`](/documentation/Distributed/DistributedTargetInvocationDecoder/decodeReturnType())

Attempt to decode the known return type of the distributed invocation.

## Relationships

### Conforming Types

[`LocalTestingInvocationDecoder`](/documentation/Distributed/LocalTestingInvocationDecoder)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)