digitalmars.D.learn - read/peek and automatically advance index in buffer
- jwatson-CO-edu (27/27) Mar 16 2023 I read a file into a `ubyte` buffer as shown:
- ag0aep6g (2/6) Mar 16 2023 You just forgot the exclamation mark there.
- jwatson-CO-edu (7/14) Mar 16 2023 "there" was not descriptive in this context, but I was able to
I read a file into a `ubyte` buffer as shown: ```d \\ ... buffer = cast(ubyte[]) read( fName ); // Read the entire file as bytestring marker = 0; // Current index to read from, managed manually, :( \\ ... ``` The data file contains numbers of varying size, and I want to read them sequentially. I gleaned the following from forum posts: ```d // Start read at marker, cast as int int rtnVal = peek!(int, Endian.bigEndian)(buffer[marker..$]); marker += 4; // I just peeked 32 bits ``` [The docs imply](https://dlang.org/library/std/bitmanip/peek.html) that I can peek and also advance my index appropriately, but I'm unsure how to specify the return type, endianness, and index pointer all at once. The following does not work: ```d int rtnVal = buffer.peek(int,Endian.bigEndian)(&marker); // Error: found `,` when expecting `.` following int ``` What is the idiom / function call that will automatically advance my `marker` index variable?
Mar 16 2023
On Thursday, 16 March 2023 at 18:39:00 UTC, jwatson-CO-edu wrote:```d int rtnVal = buffer.peek(int,Endian.bigEndian)(&marker); // Error: found `,` when expecting `.` following int ```You just forgot the exclamation mark there.
Mar 16 2023
On Thursday, 16 March 2023 at 18:58:18 UTC, ag0aep6g wrote:On Thursday, 16 March 2023 at 18:39:00 UTC, jwatson-CO-edu wrote:"there" was not descriptive in this context, but I was able to infer what you meant by trial and error. The following gives me the behavior I needed: ```d int rtnVal = buffer.peek!(int, Endian.bigEndian)(&marker); ``````d int rtnVal = buffer.peek(int,Endian.bigEndian)(&marker); // Error: found `,` when expecting `.` following int ```You just forgot the exclamation mark there.
Mar 16 2023