Open Abscissa opened 8 years ago
@Abscissa [sorry if it's only very mildly related] I'm wondering whether SDL would be a good fit for protobuf human readable format (see https://github.com/msoucy/dproto/issues/71#issuecomment-361011866 where i was trying to improve on default protobuf text format which I don't like because of treatment of repeated fields)
(also very mildly related to https://github.com/Abscissa/SDLang-D/issues/30 since that deals with conversion from X to/from SDL)
mixin ProtocolBufferFromString!"message Person { optional string name=1; optional int32 age=2; } "; // eg from cf https://github.com/msoucy/dproto
Person a;
a.parseSDL(some_sdl_string);
assert(some_sdl_string == a.serializeSDL);
one important use case would be reading in structured data (with an enforced schema) to command line programs:
// usage:
// echo 'name bob \n age 22' | rdmd main.d
void main(string[]args){
Person a;
a.parseSDL(args[1]); // type-safe schema compliant parsing here
writeln(a.name);
}
My understanding of protobuf isn't especially deep (it's been a long time), but from what I do know of it: Yea, the SDLang format should work fine for it, I don't see why not.
Incidentally, some time ago I did have a go at designing a schema format for SDLang written in SDLang, but in doing so I came to the conclusion it would make far more sense to just use D structs/classes with UDAs as the schema, like most typical serialization libs.
Eventually, an SDLang-based SDLang schema could still be developed if sharing an SDLang schema across different programming languages becomes an important concern (much like protobuf), but I think UDA-based serialization is a far more sensible (and arguably necessary) as a first step.
Just mentioning for completeness: https://code.dlang.org/packages/vibe-sdlang
This implements a vibe.data.serialization
based serializer with some extra UDAs to control attributes and values.
Obviously in SDLang itself, of course.
This will allow for a much simpler, more robust API that's more statically-typed and has vastly better error-checking built-in for both parsing and writing.
It should also help with a generic "SDLang <--> other formats" converter (ie, #30).
I have some work done on the design, but still need to finish & implement.