Should we implement check during implement the Enc...
# serialization
i
Should we implement check during implement the Encoder/Decoder? Such as the
decode*Element
require the
descriptor
keep equals with
beginStructure
, should we do an explicit check? I found the JSON format doesn't do it.
b
I would say it's unnecessary to check, since the contract for CompositeEncoder/Decoder requires that methods be called with the same descriptor. So if someone does call with a different instance, it would be undefined behavior (might throw, might serialize differently, or the descriptor might be entirely ignored) https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-core/kotlinx.serialization.encoding/-composite-encoder/
•
descriptor
is always the same as one used in
Encoder.beginStructure
. While this parameter may seem redundant, it is required for efficient serialization process to avoid excessive field spilling. If you are writing your own format, you can safely ignore this parameter and use one used in
beginStructure
for simplicity.