std.stream.EndianStream ...

torhu fake at address.dude
Thu Feb 8 11:30:13 PST 2007


Ben Hinkle wrote:
> "torhu" <fake at address.dude> wrote in message 
> news:eqeff9$22i3$1 at digitaldaemon.com...
>> nescire wrote:
>>> EndianStream es = new EndianStream( new MemoryStream() );
>>> ubyte b;
>>> es.read( b );
>>>
>>> dmd gives the error:
>>>
>>> function std.stream.EndianStream.read called with argument types:
>>> (ubyte)
>>> matches both:
>>> std.stream.EndianStream.read(short)
>>> and:
>>> std.stream.EndianStream.read(dchar)
>>>
>>> Which seems to suggest the EndianStream class does not have a void 
>>> read( out ubyte ) method, even though it should inherit it from 
>>> FilterStream.
>>
>> It's hard to find anything about this in the docs.  But it seems overloads 
>> are not inherited by default, which is the same behavior as in C++. 
>> EndianStream redefine most of the read() overloads, but not the byte and 
>> ubyte versions.  The read() methods does the actual byteswapping, which 
>> wouldn't work on single-byte reads.  So this is done on purpose.
>>
>> You would do 'alias SuperClass.method method;' to pull in 'method()' 
>> overloads from SuperClass.
> 
> yeah, looks like that should be added to EndianStream.

Why?  Stream's methods don't do byteswapping, which seems to be the 
whole point of EndianStream.

> 
>>> And the following code compiles:
>>>
>>> EndianStream es = new EndianStream( new MemoryStream() );
>>> ubyte b;
>>> (cast(InputStream) es).read( b );
>>>
>>>
>>> Could someone explain? Am I missing something obvious, or is it a 
>>> compiler bug?
>>
>>
>> I'm guessing this makes it call Stream's version of read(ubyte), which 
>> will give the wrong result.
> 
> Why is that the wrong result? EndianStream only swaps when reading 
> multi-byte data since there's nothing to swap with a single byte. 
> 

Is EndianStream supposed to be used for single-byte reads too?


More information about the Digitalmars-d-learn mailing list