Hi, On 18.02.2014 15:34, Adrien Destugues wrote:
18 février 2014 14:58 "Stephan Aßmus" <superstippi@xxxxxx> a écrit:I completely fail to see what the problem is. As far as I understand, you want to use a class which implements BDataOutput in a context where you need a BDataIO. As Ingo pointed out, instead of changing all the places where BDataOutput was previously used, you could have simply written a BDataIO which wraps a BDataOutput. The fact that BDataIO can in theory return less bytes from Read() then requested, is completely irrelevant in this context, since when the underlying BDataOutput (the deflate output) only returns all or nothing, then that's what happens in your wrapper. It simply has the behavior of always returning the requested number of bytes. Why would that be any sort of problem?The "problem" is the other way around; a BDataOutput that wraps a BDataIO. I'm concerned with the case where the loop (in the code you provide below) iterates at least once, writing some bytes, and then fails. With the current BDataOutput API, all it can do is return the error code, leaving the caller with no information about how much data was actually written (that's the whole point of using that different class - the caller doesn't want to handle that). The case where a write error is only temporary (in my case, a buffer that is full, but can be emptied and reused later) is a bit more tricky to handle. I was trying to handle that in the ZlibDecompressor, to resume writing exactly where it stopped, but now I see it can be done in the adapter, by having ZlibDecompressor "replay" the failed write, and the adapter ignore the bytes it has already written (it must keep track of this internally, by remembering how many bytes were wrote during the last call). This makes the adapter only slightly more complicated, and it's a good solution.
What buffer are you talking about? The buffer you pass into Read() is just a block of memory which must already be at least as large as "size" you pass as second argument. You mean you would free that buffer and allocate a smaller one when you get B_NO_MEMORY from Read()?
The only use-case I can see where you don't know how much data you are able to read before calling Read(). This fits with BDataIO not providing Size(). Is that the case here? I think then I would understand.
Best regards, -Stephan