digitalmars.D.learn - D serialization temporary fixup?
- Shriramana Sharma (12/12) Oct 22 2015 I wanted a D equivalent to:
- John Colvin (6/17) Oct 22 2015 Simple lumps of binary data can just be written directly using
- Laeeth Isharc (3/14) Oct 22 2015 msgpack works quite well for me (see the D binding).
- Laeeth Isharc (2/18) Oct 22 2015 it enforces correctness, to a certain degree.
- TheFlyingFiddle (23/34) Oct 22 2015 If your only interested in POD data something like this should do
- Atila Neves (4/15) Oct 23 2015 https://github.com/atilaneves/cerealed
- Shriramana Sharma (7/10) Oct 23 2015 Wow thank you people! Nice to know I can do rawWrite and also have other...
- Atila Neves (5/14) Oct 26 2015 Developing a library and getting it on the dub registry is easy.
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
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
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
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:it enforces correctness, to a certain degree.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
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
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
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
On Friday, 23 October 2015 at 16:27:11 UTC, Shriramana Sharma wrote:Shriramana Sharma wrote:Developing a library and getting it on the dub registry is easy. Getting a whole library into Phobos is incredibly hard. AtilaI'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 26 2015