digitalmars.D.learn - Best way to save/load an object to file?
- Saaa (3/3) Jun 18 2008 As the subject says : )
- BCS (6/12) Jun 18 2008 It might be possible to generate a generic save device using tuple of an...
- Saaa (11/18) Jun 20 2008 Lol, I think I'm not really that good a magician :)
- Lutger (5/10) Jun 19 2008 If you use Tango, you'll probably want to look into protocols. Haven't u...
- Saaa (3/9) Jun 20 2008 I could use tango.. wouldn't be that much of a difference. I need to tak...
- aarti_pl (14/18) Jun 22 2008 You may try doost serializer:
- Saaa (6/21) Jun 22 2008 Looks interesting, thanks.
- aarti_pl (6/33) Jun 23 2008 Do not hesitate to put comments on forum regarding API/problems/suggesti...
- Bill Baxter (6/35) Jun 22 2008 Sweet. Thanks for reminding me about that!
- Bill Baxter (9/45) Jun 23 2008 Just wanted to note here, that after playing with it a bit it does seem
- Christian Kamm (5/6) Jun 23 2008 Maybe Clay or I removed it. It can always be found here:
- Bill Baxter (4/14) Jun 23 2008 I see. From a quick look at the test file, I think Aarti's code is a
- aarti_pl (12/17) Jun 23 2008 Yes documentation is unfortunately not strongest point of Doost :-(
- Bill Baxter (9/15) Jun 26 2008 In addition to doost.util.serializer, which has been mentioned,
As the subject says : ) I could make my own personal loading saving functions of all the specific variables in the objects, but I'd love there to be an easier way than that.
Jun 18 2008
Reply to Saaa,As the subject says : ) I could make my own personal loading saving functions of all the specific variables in the objects, but I'd love there to be an easier way than that.It might be possible to generate a generic save device using tuple of and some magic to detect and deal with references (convert them to file references with some caching and delayed output to deal with loops and whatnot) <joke> I could show you how to do this, but then the knowledge would kill you </joke>
Jun 18 2008
Lol, I think I'm not really that good a magician :) A box model would suffice I think: box class 1{ auto colors[]=fruitsClass.colors[]; .. .. } save box to file -- load box from file would set all values. Are there boxes like this?It might be possible to generate a generic save device using tuple of and some magic to detect and deal with references (convert them to file references with some caching and delayed output to deal with loops and whatnot) <joke> I could show you how to do this, but then the knowledge would kill you </joke>
Jun 20 2008
Saaa wrote:As the subject says : ) I could make my own personal loading saving functions of all the specific variables in the objects, but I'd love there to be an easier way than that.If you use Tango, you'll probably want to look into protocols. Haven't used it myself yet, so I can't comment on it. There might be other serialization code around somewhere over at dsource though, arclib used to have some but I believe that makes use of Tango's now.
Jun 19 2008
I could use tango.. wouldn't be that much of a difference. I need to take a deeper look into these things (I've just seen the arclib serializer :). But as mentioned above, a simpler approach would suffice.If you use Tango, you'll probably want to look into protocols. Haven't used it myself yet, so I can't comment on it. There might be other serialization code around somewhere over at dsource though, arclib used to have some but I believe that makes use of Tango's now.
Jun 20 2008
Saaa pisze:As the subject says : ) I could make my own personal loading saving functions of all the specific variables in the objects, but I'd love there to be an easier way than that.You may try doost serializer: http://dsource.org/projects/doost/ You can serialize to file (generally: different kinds of storages) or to string. There are 2 kinds of archives: simple text archive and JSON archive. See below for use cases: http://dsource.org/projects/doost/browser/trunk/examples/util/serializer/FunctionTest.d http://dsource.org/projects/doost/browser/trunk/examples/util/serializer/FunctionTest1.d Simplest use case for storing in file you can find in FunctionTest1.d - 3rd unit test from top. Currently Phobos only, but should be rather easy to adapt for Tango. BR Marcin Kuszczak (aarti_pl)
Jun 22 2008
Looks interesting, thanks. I need to check the code a bit more, but the creating-JSON-archive-part really strikes my fancy :) Phobos only wouldn't be a problem for me. And as I read it, the boost license lets me use the code in compiled form without having to put the license in text form. Another plus!You may try doost serializer: http://dsource.org/projects/doost/ You can serialize to file (generally: different kinds of storages) or to string. There are 2 kinds of archives: simple text archive and JSON archive. See below for use cases: http://dsource.org/projects/doost/browser/trunk/examples/util/serializer/FunctionTest.d http://dsource.org/projects/doost/browser/trunk/examples/util/serializer/FunctionTest1.d Simplest use case for storing in file you can find in FunctionTest1.d - 3rd unit test from top. Currently Phobos only, but should be rather easy to adapt for Tango. BR Marcin Kuszczak (aarti_pl)
Jun 22 2008
Saaa pisze:Looks interesting, thanks. I need to check the code a bit more, but the creating-JSON-archive-part really strikes my fancy :) Phobos only wouldn't be a problem for me. And as I read it, the boost license lets me use the code in compiled form without having to put the license in text form. Another plus!Do not hesitate to put comments on forum regarding API/problems/suggestions. Hope that this library will be useful for you. BR Marcin Kuszczak aarti_plYou may try doost serializer: http://dsource.org/projects/doost/ You can serialize to file (generally: different kinds of storages) or to string. There are 2 kinds of archives: simple text archive and JSON archive. See below for use cases: http://dsource.org/projects/doost/browser/trunk/examples/util/serializer/FunctionTest.d http://dsource.org/projects/doost/browser/trunk/examples/util/serializer/FunctionTest1.d Simplest use case for storing in file you can find in FunctionTest1.d - 3rd unit test from top. Currently Phobos only, but should be rather easy to adapt for Tango. BR Marcin Kuszczak (aarti_pl)
Jun 23 2008
aarti_pl wrote:Saaa pisze:Sweet. Thanks for reminding me about that! I'm in the market for some serialization code too. Does it handle references properly? Meaning if I have class objects A and B that both refer to the same C, will C only get serialized once? --bbAs the subject says : ) I could make my own personal loading saving functions of all the specific variables in the objects, but I'd love there to be an easier way than that.You may try doost serializer: http://dsource.org/projects/doost/ You can serialize to file (generally: different kinds of storages) or to string. There are 2 kinds of archives: simple text archive and JSON archive. See below for use cases: http://dsource.org/projects/doost/browser/trunk/examples/util/seria izer/FunctionTest.d http://dsource.org/projects/doost/browser/trunk/examples/util/serial zer/FunctionTest1.d Simplest use case for storing in file you can find in FunctionTest1.d - 3rd unit test from top. Currently Phobos only, but should be rather easy to adapt for Tango. BR Marcin Kuszczak (aarti_pl)
Jun 22 2008
Bill Baxter wrote:aarti_pl wrote:Just wanted to note here, that after playing with it a bit it does seem to handle references properly. It also manages to serialize simple classes without any intrusive instrumentation whatsoever. Very nice! As usual with doost, though, it could use a little documentation. And more comments in the code. The few comments there are in Polish, which isn't much use to me. I couldn't find the serializer in arclib. What file is it in? --bbSaaa pisze:Sweet. Thanks for reminding me about that! I'm in the market for some serialization code too. Does it handle references properly? Meaning if I have class objects A and B that both refer to the same C, will C only get serialized once?As the subject says : ) I could make my own personal loading saving functions of all the specific variables in the objects, but I'd love there to be an easier way than that.You may try doost serializer: http://dsource.org/projects/doost/ You can serialize to file (generally: different kinds of storages) or to string. There are 2 kinds of archives: simple text archive and JSON archive. See below for use cases: http://dsource.org/projects/doost/browser/trunk/examples/util/seria izer/FunctionTest.d http://dsource.org/projects/doost/browser/trunk/examples/util/serial zer/FunctionTest1.d Simplest use case for storing in file you can find in FunctionTest1.d - 3rd unit test from top. Currently Phobos only, but should be rather easy to adapt for Tango. BR Marcin Kuszczak (aarti_pl)
Jun 23 2008
Bill Baxter Wrote:I couldn't find the serializer in arclib. What file is it in?Maybe Clay or I removed it. It can always be found here: http://www.dsource.org/projects/serialization It is discontinued though. Christian
Jun 23 2008
Christian Kamm wrote:Bill Baxter Wrote:I see. From a quick look at the test file, I think Aarti's code is a bit further along in development than that was. --bbI couldn't find the serializer in arclib. What file is it in?Maybe Clay or I removed it. It can always be found here: http://www.dsource.org/projects/serialization It is discontinued though. Christian
Jun 23 2008
Bill Baxter pisze:As usual with doost, though, it could use a little documentation. And more comments in the code. The few comments there are in Polish, which isn't much use to me. --bbYes documentation is unfortunately not strongest point of Doost :-( I will try to improve this situation in future, but it takes a lot of time, especially for me as I am not native English speaker. And sadly time is not from elastic rubber :-] Another think which stopped a bit development was uncertainty about current API design (especially everything connected with 'storage' concept). Current design works well, but I would be happy to get some feedback from real users. BR Marcin Kuszczak (aarti_pl)
Jun 23 2008
Saaa wrote:As the subject says : ) I could make my own personal loading saving functions of all the specific variables in the objects, but I'd love there to be an easier way than that.In addition to doost.util.serializer, which has been mentioned, h3r3tic has pointed out to me that team0xf has a library called xpose which does serialization to and from a binary format. Can be found here: http://team0xf.com:8080/xf/file/34c9c0ffde3a/xpose/Serialization.d Entire source included in xf, which you can get using hg: hg clone http://team0xf.com:8080/xf --bb
Jun 26 2008