Serialization library candidate review request

monkyyy crazymonkyyy at gmail.com
Mon Aug 28 01:01:57 UTC 2023


On Sunday, 27 August 2023 at 19:39:05 UTC, GrimMaple wrote:
> Hello everyone! When my 
> https://github.com/dlang/phobos/pull/8662 predictably failed, I 
> moved on to create a common serialization library instead that 
> could later on be included in phobos. So I would like to 
> request a review from you to get it to a decent state. If 
> interested, you can find the code 
> [here](https://github.com/GrimMaple/mud/tree/v0.3.0/source/mud/serialization), and if you want to use it with dub you can use `"mud": "~>0.3.0"`.
>
> Code contains two files: package.d to ease making 
> serializators, and json.d is an example serializator from/to 
> json. Please consider this example to see how it works in 
> general:
> ```
>     struct Foo
>     {
>         // Works with or without brackets
>         @serializable int a = 123;
>         @serializable() double floating = 123;
>         @serializable("flag") bool check = true;
>     }
>
>     // Will produce `{"a":123,"floating"=123,"flag"=true}`
>     serializeToJSONString(Foo());
> ```
>
> If you're interested in making a custom serializator, here's a 
> rough idea on how it's going to be implemented with this 
> library:
> ```d
> foreach(alias prop; readableSerializables!T)
> {
>     enum name = getSerializableName!prop;
>     // Work your magic here
> }
> ```
>
> I tried to make it as universal as I could, but any suggestions 
> are welcome for a discussion.

isnt the hard part enumerating over every base type to make it 
have sane encoding/decoding string behavior?

I dont understand why your adding a uda rather then assuming all 
values are serializable.

I wouldnt make json be the base case, "dlang object notation" or 
something that spits binary into a file, or ideally both


More information about the Digitalmars-d mailing list