You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3
+
*/
4
+
5
+
packagekotlinx.serialization.encoding
6
+
7
+
importkotlinx.serialization.*
8
+
importkotlinx.serialization.descriptors.*
9
+
importkotlinx.serialization.modules.*
10
+
11
+
12
+
/**
13
+
* Encodes elements in a user-defined order managed by [mapElementIndex].
14
+
*
15
+
* This encoder will replicate the behavior of a standard encoding, but calling the `encode*Element` methods in
16
+
* the order defined by [mapElementIndex]. It first buffers each `encode*Element` calls in an array following
17
+
* the given indexes using [mapElementIndex], then when [endStructure] is called, it encodes the buffered calls
18
+
* in the expected order by replaying the previous calls on the given [compositeEncoderDelegate].
19
+
*
20
+
* This encoder is stateful and not designed to be reused.
21
+
*
22
+
* @param compositeEncoderDelegate the [CompositeEncoder] to be used to encode the given descriptor's elements in the expected order.
23
+
* @param encodedElementsCount The final number of elements to encode, which could be smaller than the original descriptor when [mapElementIndex] returns [SKIP_ELEMENT_INDEX] or when the index mapper has returned the same index twice.
24
+
* @param mapElementIndex maps the element index to a new positional zero-based index.
25
+
* The mapped index just helps to reorder the elements,
26
+
* but the reordered `encode*Element` method calls will still pass the original element index.
27
+
* If this mapper returns [SKIP_ELEMENT_INDEX] or -1, the element will be ignored and not encoded.
28
+
* If this mapper provides the same index for multiple elements,
29
+
* only the last one will be encoded as the previous ones will be overridden.
// This method is normally called from within encodeSerializableValue or encodeNullableSerializableValue which is buffered, so we should never go here during buffering as it will be delegated to the concrete CompositeEncoder
244
+
throwUnsupportedOperationException("Non-standard usage of ${CompositeEncoder::class.simpleName}: $methodName should be called from within encodeSerializableValue or encodeNullableSerializableValue")
0 commit comments