write struct as raw data to file
Vitaliy Fadeev
vital.fadeev at gmail.com
Mon Sep 27 14:54:55 UTC 2021
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;
> @Bits!1 ubyte bit;
> @Bits!3 ubyte bits3;
> ubyte mybyte2; }
>
> assert(MyStruct(3, 123, 14, 1, 42).cerealise == [ 3, 0xea
> /*1110 1 010*/, 42]);
>
> mybyte1 = 3 ?
> nocereal1 = 123 ?
> nibble = 14 ?
> bit = 1 ?
> ??? bits3 = ___ ???
> mybyte2 = 42 ?
Author of package is https://github.com/atilaneves
Issues here: https://github.com/atilaneves/cerealed/issues
Yes, "Bits" not worked. No value for bits3.
Next is correct:
```
import std;
import cerealed;
struct MyStruct
{
ubyte mybyte1;
@NoCereal uint nocereal1; //won't be serialised
@Bits!4 ubyte nibble;
@Bits!1 ubyte bit;
@Bits!3 ubyte bits3;
ubyte mybyte2;
}
void main()
{
assert( MyStruct(3, 123, 14, 1, 2, 42).cerealise == [ 3,
0xea /*1110 1 010*/, 42]);
writeln( MyStruct(3, 123, 14, 1, 2, 42).cerealise );
}
```
`[3, 234, 42]`
And check simple struct without attributes Bits, NoCereal:
```
import std;
import cerealed;
struct MyStruct
{
ubyte mybyte1;
ubyte mybyte2;
}
void main()
{
writeln( MyStruct(3, 42).cerealise );
}
```
`[3, 42]`
More information about the Digitalmars-d-learn
mailing list