digitalmars.D - BinaryStream? and Hello!
- Nate (24/24) Jan 23 2005 Hello Guys,
- John Demme (9/45) Jan 23 2005 Mango's IO package provides stuff like this:
- Nate (2/53) Jan 23 2005
- Ben Hinkle (6/14) Jan 23 2005 See phobos' std.stream module: http://www.digitalmars.com/d/std_stream.h...
- Ben Hinkle (5/5) Jan 23 2005 I should add someone reported a problem with the latest phobos build on
- Nate Plumm (2/23) Jan 23 2005
Hello Guys, bad. I do not come from a C/C++ background and so some obvious things are new to me. Pointers n related are perplexing to me, I'll learn more about them later I suppose! (thanks Derelict!) and it works very well. My next step is reading and writing game data, my preferred method is to use a binary file (aka DAT For example, to read 4 bytes then a long... byte[] myBytes = new byte[4]; myBytes[0] = reader.ReadByte(); myBytes[1] = reader.ReadByte(); myBytes[2] = reader.ReadByte(); myBytes[3] = reader.ReadByte(); long mySomeWhatBigNumber; mySomeWhatBigNumber = reader.ReadInt64(); The binary writer was just as easy. Writer.Write(myBytes[0]); // Automatically write a byte Writer.Write(mySomeWhatBigNumber); // Automatically write a long How can I do this in D? Its an absoluate pain to search google, etc for such a thing. Thanks in advance for your time guys! Nate
Jan 23 2005
Mango's IO package provides stuff like this: FileConduit fc = new FileConduit("file.txt"); IReader r = new Reader(fc); byte[] b = new byte[4]; long l; r.get(b[0]).get(b[1]).get(b[2]).get(b[3]).get(l); You can get it at dsource.org John Nate wrote:Hello Guys, bad. I do not come from a C/C++ background and so some obvious things are new to me. Pointers n related are perplexing to me, I'll learn more about them later I suppose! (thanks Derelict!) and it works very well. My next step is reading and writing game data, my preferred method is to use a binary file (aka DAT For example, to read 4 bytes then a long... byte[] myBytes = new byte[4]; myBytes[0] = reader.ReadByte(); myBytes[1] = reader.ReadByte(); myBytes[2] = reader.ReadByte(); myBytes[3] = reader.ReadByte(); long mySomeWhatBigNumber; mySomeWhatBigNumber = reader.ReadInt64(); The binary writer was just as easy. Writer.Write(myBytes[0]); // Automatically write a byte Writer.Write(mySomeWhatBigNumber); // Automatically write a long How can I do this in D? Its an absoluate pain to search google, etc for such a thing. Thanks in advance for your time guys! Nate
Jan 23 2005
Thank you very much John, this is exactly what I needed. John Demme wrote:Mango's IO package provides stuff like this: FileConduit fc = new FileConduit("file.txt"); IReader r = new Reader(fc); byte[] b = new byte[4]; long l; r.get(b[0]).get(b[1]).get(b[2]).get(b[3]).get(l); You can get it at dsource.org John Nate wrote:Hello Guys, bad. I do not come from a C/C++ background and so some obvious things are new to me. Pointers n related are perplexing to me, I'll learn more about them later I suppose! (thanks Derelict!) and it works very well. My next step is reading and writing game data, my preferred method is to use a binary file (aka Writer. For example, to read 4 bytes then a long... byte[] myBytes = new byte[4]; myBytes[0] = reader.ReadByte(); myBytes[1] = reader.ReadByte(); myBytes[2] = reader.ReadByte(); myBytes[3] = reader.ReadByte(); long mySomeWhatBigNumber; mySomeWhatBigNumber = reader.ReadInt64(); The binary writer was just as easy. Writer.Write(myBytes[0]); // Automatically write a byte Writer.Write(mySomeWhatBigNumber); // Automatically write a long How can I do this in D? Its an absoluate pain to search google, etc for such a thing. Thanks in advance for your time guys! Nate
Jan 23 2005
For example, to read 4 bytes then a long... byte[] myBytes = new byte[4]; myBytes[0] = reader.ReadByte(); myBytes[1] = reader.ReadByte(); myBytes[2] = reader.ReadByte(); myBytes[3] = reader.ReadByte(); long mySomeWhatBigNumber; mySomeWhatBigNumber = reader.ReadInt64();See phobos' std.stream module: http://www.digitalmars.com/d/std_stream.html You'll want to use the Stream.read and Stream.write functions. Phobos is the runtime library that comes with dmd.zip. Comments are welcome because phobos is still under development and it's easy to enhance it or fix bugs. -Ben
Jan 23 2005
I should add someone reported a problem with the latest phobos build on Windows - it looks like dmd version 0.111 has an out of date stream.obj file. Maybe Walter fixed it already. you but just in case you run into trouble with 0.111 you should recompile phobos.lib by changing to the phobos/srd directory and typing "make -f win32.mak"
Jan 23 2005
Cool! Even better than what I was about to do. Big thanks Ben. Ben Hinkle wrote:For example, to read 4 bytes then a long... byte[] myBytes = new byte[4]; myBytes[0] = reader.ReadByte(); myBytes[1] = reader.ReadByte(); myBytes[2] = reader.ReadByte(); myBytes[3] = reader.ReadByte(); long mySomeWhatBigNumber; mySomeWhatBigNumber = reader.ReadInt64();See phobos' std.stream module: http://www.digitalmars.com/d/std_stream.html You'll want to use the Stream.read and Stream.write functions. Phobos is the runtime library that comes with dmd.zip. Comments are welcome because phobos is still under development and it's easy to enhance it or fix bugs. -Ben
Jan 23 2005