| |
 | Posted by aerto in reply to Dennis | Permalink Reply |
|
aerto 
Posted in reply to Dennis
| On Monday, 16 January 2023 at 15:35:38 UTC, Dennis wrote:
> On Monday, 16 January 2023 at 15:16:46 UTC, aerto wrote:
> The above code doesn't work.
What doesn't work?
Can you also give the definitions of the variables and functions involved?
class iv{
private byte[] buffer;
private ulong writePos;
private ulong readPos;
this(){}
void write(T)(T value) if (is(T == uint)){
buffer ~= nativeToLittleEndian!uint(value);
writePos += uint.sizeof;
}
uint readUint()
{
assert(readPos == 0);
uint value = littleEndianToNative!uint(cast(ubyte[uint.sizeof])buffer[readPos..readPos+uint.sizeof]);
readPos += uint.sizeof;
return value;
}
uint readUint_test()
{
assert(readPos == 0);
uint value = littleEndianToNative!uint(cast(ubyte[uint.sizeof])buffer[0..0+uint.sizeof]);
readPos += uint.sizeof;
return value;
}
}
void main()
{
auto cc = new iv();
uint ptr = 1000000;
cc.write(ptr);
writeln(cc.readUint()); //not works
writeln(cc.readUint_test()); // works
}
The readUint_test its working while the readUint not.
|