Re: [Vala] Writing objects to files
On 03/28/2018 10:44 AM, Steven Oliver wrote: > > On the other hand, though, if you throw in some kind of data structure > besides your basic types (int, string, etc.) it completely fails. https://developer.gnome.org/json-glib/stable/json-glib-Serializable-Interface.html#JsonSerializableIface If your GObject implements that interface, you can control what gets serialized and in what format. ___ vala-list mailing list vala-list@gnome.org https://mail.gnome.org/mailman/listinfo/vala-list
Re: [Vala] Writing objects to files
Hello, I don't know what it's worth, but if you prefer XML this seems to be a good solution: https://blogs.gnome.org/despinosa/2016/05/04/howto-gobje ct-serialization-to-xml-using-gxml/ Vivien Le lundi 26 mars 2018 à 14:02 -0700, Christian Hergert a écrit : > On 03/26/2018 11:44 AM, Steven Oliver wrote: > > I want to implement "saving" in my program. The data I want to save > > is > > a custom object. Is it possible in vala to simply write the object > > to > > disk (in binary I assume) without having to implement a to_string > > method? > > > > It seems like such a simple concept yet i can't seem to figure out > > how > > to do it in Vala. > > A very simple option (assuming you don't have an object graph to > serialize) could be to use either: > > Json.gobject_serialize() > Json.gobject_to_data() > > to serialize and > > Json.gobject_deserialize() > Json.gobject_from_data() > > to deserialize. If you need custom hooks into what will get > serialized, > you can implement Json.Serializable. > > If you really want binary, GVariant is a rather nice serialization > format, but you might need to bring your own serializers. Json-GLib > has > some code for working with GVariant too, but I've not used it. > > If you need an object graph, the Gom¹ library I made several years > back > can help, but it is more intrusive on your object design. I've only > used > it from C, but others have used it from Gjs, so I would expect it to > work in some form from Vala. > > -- Christian > > ¹ https://git.gnome.org/browse/gom > ___ > vala-list mailing list > vala-list@gnome.org > https://mail.gnome.org/mailman/listinfo/vala-list ___ vala-list mailing list vala-list@gnome.org https://mail.gnome.org/mailman/listinfo/vala-list
Re: [Vala] Writing objects to files
On 03/26/2018 11:44 AM, Steven Oliver wrote: > I want to implement "saving" in my program. The data I want to save is > a custom object. Is it possible in vala to simply write the object to > disk (in binary I assume) without having to implement a to_string > method? > > It seems like such a simple concept yet i can't seem to figure out how > to do it in Vala. A very simple option (assuming you don't have an object graph to serialize) could be to use either: Json.gobject_serialize() Json.gobject_to_data() to serialize and Json.gobject_deserialize() Json.gobject_from_data() to deserialize. If you need custom hooks into what will get serialized, you can implement Json.Serializable. If you really want binary, GVariant is a rather nice serialization format, but you might need to bring your own serializers. Json-GLib has some code for working with GVariant too, but I've not used it. If you need an object graph, the Gom¹ library I made several years back can help, but it is more intrusive on your object design. I've only used it from C, but others have used it from Gjs, so I would expect it to work in some form from Vala. -- Christian ¹ https://git.gnome.org/browse/gom ___ vala-list mailing list vala-list@gnome.org https://mail.gnome.org/mailman/listinfo/vala-list
[Vala] Writing objects to files
I want to implement "saving" in my program. The data I want to save is a custom object. Is it possible in vala to simply write the object to disk (in binary I assume) without having to implement a to_string method? It seems like such a simple concept yet i can't seem to figure out how to do it in Vala. Steven N. Oliver ___ vala-list mailing list vala-list@gnome.org https://mail.gnome.org/mailman/listinfo/vala-list