Thread overview
D serialization temporary fixup?
Oct 22, 2015
Shriramana Sharma
Oct 22, 2015
John Colvin
Oct 22, 2015
Laeeth Isharc
Oct 22, 2015
Laeeth Isharc
Oct 22, 2015
TheFlyingFiddle
Oct 23, 2015
Atila Neves
Oct 23, 2015
Shriramana Sharma
Oct 26, 2015
Atila Neves
October 22, 2015
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.

-- 
Shriramana Sharma, Penguin #395953
October 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 http://dlang.org/phobos/std_file.html#.write or http://dlang.org/phobos/std_stdio.html#.File.rawWrite
and there are corresponding functions for reading.
October 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).
October 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:
>> 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.
October 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;
}
October 23, 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
October 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?

-- 
Shriramana Sharma, Penguin #395953
October 26, 2015
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