u

    ushort

    1 year ago
    Hello, was wondering if anyone can help me understand how a custom decoder should handle maps? Specifically how it might be handled inside decodeElementIndex. I'm having trouble with writing decoder that handles map<string, object>. What currently happens is it decodes one of the map keys, then it switches to class structure and after decoding the class members, it continues to decode the class members of the other key instead of ending the structure and restarting?
    russhwolf

    russhwolf

    1 year ago
    It's hard to give specific advice without seeing your code, but there's a bunch of manual accounting you need to do if you're using
    AbstractDecoder
    . If you want an example to compare to, here's what I have in Multiplatform Settings for using the
    Settings
    store (which has a pretty similar API to a map) as a serialization format:https://github.com/russhwolf/multiplatform-settings/blob/master/multiplatform-settings-serialization/src/commonMain/kotlin/SettingsSerialization.kt#L292
    b

    Ben Woodworth

    1 year ago
    Yeah it's a little tedious. But basically even indices are keys, and odd indices are values. When you're decoding a String, if it's an even index you can return the current entry's key
    u

    ushort

    1 year ago
    Thanks! Got it :]