|
12 | 12 | use Temporal\Api\Common\V1\Payloads; |
13 | 13 | use Temporal\DataConverter\DataConverter; |
14 | 14 | use Temporal\DataConverter\DataConverterInterface; |
15 | | -use Temporal\DataConverter\EncodedCollection; |
16 | | -use Temporal\DataConverter\EncodedValues; |
| 15 | +use Temporal\DataConverter\EncodingKeys; |
17 | 16 |
|
18 | 17 | final class WireFrameDecoder |
19 | 18 | { |
@@ -89,28 +88,43 @@ private static function decodeMessage(Message $message, DataConverterInterface $ |
89 | 88 | */ |
90 | 89 | private static function decodePayloads(Payloads $payloads, DataConverterInterface $converter): array |
91 | 90 | { |
92 | | - try { |
93 | | - return \array_values(EncodedValues::fromPayloads($payloads, $converter)->getValues()); |
94 | | - } catch (\Throwable) { |
95 | | - return \array_map(self::payloadFallback(...), \iterator_to_array($payloads->getPayloads(), false)); |
| 91 | + $out = []; |
| 92 | + foreach ($payloads->getPayloads() as $payload) { |
| 93 | + $out[] = self::decodeSinglePayload($payload, $converter); |
96 | 94 | } |
| 95 | + return $out; |
97 | 96 | } |
98 | 97 |
|
99 | 98 | /** |
100 | 99 | * @return array<string, mixed> |
101 | 100 | */ |
102 | 101 | private static function decodeHeader(Header $header, DataConverterInterface $converter): array |
103 | 102 | { |
| 103 | + $out = []; |
104 | 104 | /** @var MapField<string, Payload> $fields */ |
105 | 105 | $fields = $header->getFields(); |
| 106 | + foreach ($fields as $name => $payload) { |
| 107 | + $out[$name] = self::decodeSinglePayload($payload, $converter); |
| 108 | + } |
| 109 | + return $out; |
| 110 | + } |
| 111 | + |
| 112 | + /** |
| 113 | + * Decodes a single payload using its own `metadata.encoding`. Falls back to a raw |
| 114 | + * representation when encoding is absent (e.g., {@see \Temporal\DataConverter\RawValue}) |
| 115 | + * or when the converter cannot interpret the bytes. |
| 116 | + */ |
| 117 | + private static function decodeSinglePayload(Payload $payload, DataConverterInterface $converter): mixed |
| 118 | + { |
| 119 | + /** @var MapField<string, string> $meta */ |
| 120 | + $meta = $payload->getMetadata(); |
| 121 | + if (!isset($meta[EncodingKeys::METADATA_ENCODING_KEY])) { |
| 122 | + return self::payloadFallback($payload); |
| 123 | + } |
106 | 124 | try { |
107 | | - return EncodedCollection::fromPayloadCollection($fields, $converter)->getValues(); |
| 125 | + return $converter->fromPayload($payload, null); |
108 | 126 | } catch (\Throwable) { |
109 | | - $out = []; |
110 | | - foreach ($fields as $name => $payload) { |
111 | | - $out[$name] = self::payloadFallback($payload); |
112 | | - } |
113 | | - return $out; |
| 127 | + return self::payloadFallback($payload); |
114 | 128 | } |
115 | 129 | } |
116 | 130 |
|
|
0 commit comments