www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - D serialization temporary fixup?

reply Shriramana Sharma <samjnaa_dont_spam_me gmail.com> writes:
I wanted a D equivalent to:
http://doc.qt.io/qt-5/qdatastream.html
https://docs.python.org/3/library/pickle.html

and saw that one is under construction:
http://wiki.dlang.org/Review/std.serialization

But till it's finalized, I'd just like to have a quick but reliable way to 
store real and int data types into a binary data file and read therefrom. Is 
there such a solution? The size of the data is fixed, but especially since I 
have real values, I'd like to not write to limited fixed decimal text 
format.

-- 

Oct 22 2015
next sibling parent John Colvin <john.loughran.colvin gmail.com> writes:
On Thursday, 22 October 2015 at 16:15:23 UTC, Shriramana Sharma 
wrote:
 I wanted a D equivalent to: 
 http://doc.qt.io/qt-5/qdatastream.html 
 https://docs.python.org/3/library/pickle.html

 and saw that one is under construction: 
 http://wiki.dlang.org/Review/std.serialization

 But till it's finalized, I'd just like to have a quick but 
 reliable way to store real and int data types into a binary 
 data file and read therefrom. Is there such a solution? The 
 size of the data is fixed, but especially since I have real 
 values, I'd like to not write to limited fixed decimal text 
 format.
Simple lumps of binary data can just be written directly using and there are corresponding functions for reading.
Oct 22 2015
prev sibling next sibling parent reply Laeeth Isharc <spamnolaeeth nospamlaeeth.com> writes:
On Thursday, 22 October 2015 at 16:15:23 UTC, Shriramana Sharma 
wrote:
 I wanted a D equivalent to: 
 http://doc.qt.io/qt-5/qdatastream.html 
 https://docs.python.org/3/library/pickle.html

 and saw that one is under construction: 
 http://wiki.dlang.org/Review/std.serialization

 But till it's finalized, I'd just like to have a quick but 
 reliable way to store real and int data types into a binary 
 data file and read therefrom. Is there such a solution? The 
 size of the data is fixed, but especially since I have real 
 values, I'd like to not write to limited fixed decimal text 
 format.
msgpack works quite well for me (see the D binding).
Oct 22 2015
parent Laeeth Isharc <spamnolaeeth nospamlaeeth.com> writes:
On Thursday, 22 October 2015 at 16:28:30 UTC, Laeeth Isharc wrote:
 On Thursday, 22 October 2015 at 16:15:23 UTC, Shriramana Sharma 
 wrote:
 I wanted a D equivalent to: 
 http://doc.qt.io/qt-5/qdatastream.html 
 https://docs.python.org/3/library/pickle.html

 and saw that one is under construction: 
 http://wiki.dlang.org/Review/std.serialization

 But till it's finalized, I'd just like to have a quick but 
 reliable way to store real and int data types into a binary 
 data file and read therefrom. Is there such a solution? The 
 size of the data is fixed, but especially since I have real 
 values, I'd like to not write to limited fixed decimal text 
 format.
msgpack works quite well for me (see the D binding).
it enforces correctness, to a certain degree.
Oct 22 2015
prev sibling next sibling parent TheFlyingFiddle <kurtyan student.chalmers.se> writes:
On Thursday, 22 October 2015 at 16:15:23 UTC, Shriramana Sharma 
wrote:
 I wanted a D equivalent to: 
 http://doc.qt.io/qt-5/qdatastream.html 
 https://docs.python.org/3/library/pickle.html

 and saw that one is under construction: 
 http://wiki.dlang.org/Review/std.serialization

 But till it's finalized, I'd just like to have a quick but 
 reliable way to store real and int data types into a binary 
 data file and read therefrom. Is there such a solution? The 
 size of the data is fixed, but especially since I have real 
 values, I'd like to not write to limited fixed decimal text 
 format.
If your only interested in POD data something like this should do the trick. module pod_encoding; import std.traits; import std.stdio; void encode(T)(string s, T[] t) if(!hasIndirections!T && (is(T == struct) || isNumeric!T)) { File(s, "wb").rawWrite(t); } T[] decode(T)(string s) if(!hasIndirections!T && (is(T == struct) || isNumeric!T)) { File f = File(s, "rb"); assert(f.size % T.sizeof == 0, "File does not contain array of " ~ T.stringof ~ "."); auto size = f.size / U.sizeof; auto data = new T[size]; data = f.rawRead(data); return data; }
Oct 22 2015
prev sibling next sibling parent Atila Neves <atila.neves gmail.com> writes:
On Thursday, 22 October 2015 at 16:15:23 UTC, Shriramana Sharma 
wrote:
 I wanted a D equivalent to: 
 http://doc.qt.io/qt-5/qdatastream.html 
 https://docs.python.org/3/library/pickle.html

 and saw that one is under construction: 
 http://wiki.dlang.org/Review/std.serialization

 But till it's finalized, I'd just like to have a quick but 
 reliable way to store real and int data types into a binary 
 data file and read therefrom. Is there such a solution? The 
 size of the data is fixed, but especially since I have real 
 values, I'd like to not write to limited fixed decimal text 
 format.
https://github.com/atilaneves/cerealed Atila
Oct 23 2015
prev sibling parent reply Shriramana Sharma <samjnaa_dont_spam_me gmail.com> writes:
Shriramana Sharma wrote:

 I'd just like to have a quick but reliable way to
 store real and int data types into a binary data file and read therefrom.
 Is there such a solution?
Wow thank you people! Nice to know I can do rawWrite and also have other options. BTW is there a reason that either msgpack or cerealed are not made part of Phobos but developed separately? --
Oct 23 2015
parent Atila Neves <atila.neves gmail.com> writes:
On Friday, 23 October 2015 at 16:27:11 UTC, Shriramana Sharma 
wrote:
 Shriramana Sharma wrote:

 I'd just like to have a quick but reliable way to
 store real and int data types into a binary data file and read 
 therefrom.
 Is there such a solution?
Wow thank you people! Nice to know I can do rawWrite and also have other options. BTW is there a reason that either msgpack or cerealed are not made part of Phobos but developed separately?
Developing a library and getting it on the dub registry is easy. Getting a whole library into Phobos is incredibly hard. Atila
Oct 26 2015