ktoml icon indicating copy to clipboard operation
ktoml copied to clipboard

Implement `encodeToString`

Open Wavesonics opened this issue 3 years ago • 7 comments

This would be really useful in general

Wavesonics avatar Jul 14 '22 07:07 Wavesonics

Duplicate of #11

Yeah, @NightEule5 and I started this work already:

There is mostly everything done - this should take 1-2 weekends and 5-6 bottles of beer to implement

orchestr7 avatar Jul 14 '22 07:07 orchestr7

By the way - why do you need encoding of TOML? Usually TOML is used as a config-file format and decoder is needed. How do you want to use encoder?

orchestr7 avatar Jul 14 '22 07:07 orchestr7

My use case the program will have some UI to change some of the values

Wavesonics avatar Jul 14 '22 07:07 Wavesonics

So you plan to generate files in TOML format? Got it

orchestr7 avatar Jul 14 '22 07:07 orchestr7

Ya, if you guys have a branch up for the encoding I wouldn't mind contributing.

Wavesonics avatar Jul 14 '22 07:07 Wavesonics

Ya, if you guys have a branch up for the encoding I wouldn't mind contributing.

Everything is merged - AST enhancements, annotations for encoding -> so no existing branch is there. We can easily split the remaining logic and give you some part of the work if you wish :)

I will provide task list in this issue

orchestr7 avatar Jul 14 '22 07:07 orchestr7

I have a draft implementation up on my fork now. I've gotta test and debug still, it's not quite working. Progress is being made :)

NightEule5 avatar Jul 15 '22 23:07 NightEule5

@NightEule5 any progress on this? if there's a branch somewhere I wouldn't mind helping out

Wavesonics avatar Oct 19 '22 20:10 Wavesonics

@NightEule5 any progress on this? if there's a branch somewhere I wouldn't mind helping out

Everything's more or less working now, but the code is messier than I'd like. Here's the branch I'm working off of if you want to help or provide feedback. Perhaps it'd be easier if I created a draft pull request?

There are a few problems with it still:

  • The TomlComments annotation throws exceptions related to its inline default parameter. Nothing we can do about this, it's an issue with kotlinx.serialization that hasn't been fixed yet afaik
  • The isSynthetic property in TomlTable was made mutable, but that's a breaking change. I've been rewriting the encoders to defer table creation to the endStructure function to avoid this
  • Some formatting quirks persist with regards to indentation
  • Annotations are inaccessible from property types, i.e. val string: @TomlLiteral String produces a normal string. Looks like another limitation of kotlinx.serialization, but I'm not sure how useful that would be anyway

Apologies for the slow progress, I've been sidetracked by another project lately

NightEule5 avatar Oct 20 '22 05:10 NightEule5