Re: write struct as raw data to file

2021-09-27 Thread Vitaliy Fadeev via Digitalmars-d-learn
On Monday, 27 September 2021 at 13:45:19 UTC, Paul wrote: Vitaliy, Thanks for your assistance. I was looking at your serialization package. Is your example correct? struct MyStruct { ubyte mybyte1; @NoCereal uint nocereal1; //won't be serialised @Bits!4 ubyte nibble;

Re: write struct as raw data to file

2021-09-27 Thread Paul via Digitalmars-d-learn
Vitaliy, Thanks for your assistance. I was looking at your serialization package. Is your example correct? struct MyStruct { ubyte mybyte1; @NoCereal uint nocereal1; //won't be serialised @Bits!4 ubyte nibble; @Bits!1 ubyte bit; @Bits!3 ubyte bits3;

Re: write struct as raw data to file

2021-09-26 Thread Vitaliy Fadeev via Digitalmars-d-learn
On Sunday, 26 September 2021 at 15:09:38 UTC, Paul wrote: Is there way to write the myStruct data to the file in a single statement...or two? Thanks for any assistance. Header[1] header; void readFileHeader( ref File f ) { f.rawRead( header ); } S

Re: write struct as raw data to file

2021-09-26 Thread Paul via Digitalmars-d-learn
Finished product... ~15k samples x 2 sin() waves/composite wave x 16 DTMF tones = 16 DTMF wave files in ~40ms! I love D.

Re: write struct as raw data to file

2021-09-26 Thread Paul via Digitalmars-d-learn
What's with the 4 bytes of zero? I miss-counted. All is well! Thanks Ali / Steven

Re: write struct as raw data to file

2021-09-26 Thread Paul via Digitalmars-d-learn
Hmm...well this is what I did and sort of got what I wanted; it did compile and write data! auto myStruct = new mystruct[1]; File f = File("myFile.wav", "wb"); f.rawWrite(myStruct); //this is 44 bytes f.rawWrite(shortWaveArray); What I got in the file was this: -my 44 byte myStruct data + (4

Re: write struct as raw data to file

2021-09-26 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/26/21 11:09 AM, Paul wrote: I'm building a binary file.  I can write my 'short[] myArray' directly to the file using: File f = File( "myFile.wav", "wb" ); f.rawWrite(myArray); It doesn't write any array formatting stuff (i.e. '[ ,  , ]'); it just moves the data into myFile like I want. I

Re: write struct as raw data to file

2021-09-26 Thread Ali Çehreli via Digitalmars-d-learn
Correcting my sloppy code. :) On 9/26/21 8:53 AM, Ali Çehreli wrote: >// We need an array Ses (length of 1 in this case) >auto ses = new S[1]; Allocating a dynamic array there is egregious pessimization. The following works the same but this time the static array of a single S will be

Re: write struct as raw data to file

2021-09-26 Thread Ali Çehreli via Digitalmars-d-learn
rawRead and rawWrite work with slices (arrays) of things. You need to use an array of your struct even if there is a single item. Here is an example: import std.stdio; import std.file; struct S { int i; double d; } void readFrom(string name) { // We need an array Ses (length of 1 in thi