Forum Navigation
Reading structs from Buffer / Conduit
Posted: 04/03/07 18:15:09I want to read some structs from a self-built MyConduit?. The latter defines a reader() method which fills data, returns length or Conduit.Eof at the end. I've also attached a buffer to the conduit.
Now I want to read some kind of struct one after another, not knowing the length! Which method of my buffer do I use?
I tested Buffer.fill(), but it didn't use buffering, so for every read, MyConduit?.reader() was invoked. Then Buffer.extract seemed to be quite good, as it really buffers the data and takes pointer/length pair - ideally for structs. But if MyConduit?.reader() returns Eof, Buffer.extract() prints an error: "end-of-file whilst reading". Or is this an exception, I can catch? I haven't figured it out, as it calls error().
Which function is preferrable?
PS: I also tested the Reader protocol, but it also shows the error!