So my question is in subject/title. I want to parse binary file
into D structs and cant really find any good way of doing it.
What I try to do now is something like this
byte[4] fake_integer;
auto fd = File("binary.data", "r");
fd.rawRead(fake_integer);
int real_integer = *(cast(int*) fake_int
On Monday, 19 November 2018 at 22:32:55 UTC, H. S. Teoh wrote:
Actually, the case is unnecessary, because arrays implicitly
convert to void[], and pointers are sliceable. So all you need
is:
SomeStruct myStruct;
fd.rawRead((&myStruct)[0 .. 1]);
This works for all POD types.
On Tue, Mar 30, 2021 at 12:32:36AM +, mw via Digitalmars-d-learn wrote:
> On Monday, 19 November 2018 at 22:32:55 UTC, H. S. Teoh wrote:
> > Actually, the case is unnecessary, because arrays implicitly convert
> > to void[], and pointers are sliceable. So all you need is:
> >
> > SomeStru
On Mon, 19 Nov 2018 21:30:36 +, welkam wrote:
> So my question is in subject/title. I want to parse binary file into D
> structs and cant really find any good way of doing it. What I try to do
> now is something like this
>
> byte[4] fake_integer;
> auto fd = File("binary.data", "r");
> fd.raw
On Mon, Nov 19, 2018 at 10:14:25PM +, Neia Neutuladh via
Digitalmars-d-learn wrote:
> On Mon, 19 Nov 2018 21:30:36 +, welkam wrote:
> > So my question is in subject/title. I want to parse binary file into D
> > structs and cant really find any good way of doing it. What I try to do
> > now
On Mon, 19 Nov 2018 14:32:55 -0800, H. S. Teoh wrote:
>> Standard caveats about byte order and alignment.
>
> Alignment shouldn't be a problem, since local variables should already
> be properly aligned.
Right, and the IO layer probably doesn't need to read to aligned memory
anyway.
Struct fiel
On Monday, 19 November 2018 at 22:14:25 UTC, Neia Neutuladh wrote:
Nothing stops you from writing:
SomeStruct myStruct;
fd.rawRead((cast(ubyte*)&myStruct)[0..SomeStruct.sizeof]);
Standard caveats about byte order and alignment.
Never would I thought about casting struct to static arr
On Tuesday, 20 November 2018 at 11:54:59 UTC, welkam wrote:
On Monday, 19 November 2018 at 22:14:25 UTC, Neia Neutuladh
wrote:
Nothing stops you from writing:
SomeStruct myStruct;
fd.rawRead((cast(ubyte*)&myStruct)[0..SomeStruct.sizeof]);
Standard caveats about byte order and alignmen
On Tuesday, 20 November 2018 at 12:01:49 UTC, Stanislav Blinov
wrote:
On Tuesday, 20 November 2018 at 11:54:59 UTC, welkam wrote:
On Monday, 19 November 2018 at 22:14:25 UTC, Neia Neutuladh
wrote:
Nothing stops you from writing:
SomeStruct myStruct;
fd.rawRead((cast(ubyte*)&myStruct)[