Add extension for encoding collections
What is your use-case and why do you need this feature?
There is an extension for encoding structures (encodeStructure) but no extension for encoding collection which would be useful for custom serializers.
Describe the solution you'd like I'd like for an extension to be added. It's signature would be:
public inline fun Encoder.encodeCollection(
descriptor: SerialDescriptor,
collectionSize: Int,
block: CompositeEncoder.() -> Unit
)
and where is the equivalent decodeCollection or how does one decode a structure encoded with encodeCollection?
@Aphexus encodeCollection is simply the same as beginStructure with a collection size parameter. How you decode it depends on where you've stored this collection size. Generally, Decoder.beginStructure is enough with optional decodeCollectionSize to return the stored size