bitmanip bigEndianToNative using a buffer slice?

Lucas Burson via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Oct 21 17:45:17 PDT 2014


I'm trying to create a primitive type given a specific buffer 
slice. I can place the uint into a sliced buffer but I'm getting 
compiler errors when using a slice to create the uint. Still new 
to Dlang and unfamiliar with the template system.

How do I get this working?

import std.bitmanip;
int main()
{
    size_t offset = 3;
    ubyte[10] buffer;
    buffer[offset..offset+4] = nativeToBigEndian!uint(cast(uint) 
104387);

    // compiler error
    uint fromBuf = 
bigEndianToNative!uint(buffer[offset..offset+4]);
    return 0;
}

The compiler error:
./test.d(11): Error: template std.bitmanip.bigEndianToNative does 
not match any function template declaration. Candidates are:
/usr/include/dmd/phobos/std/bitmanip.d(1689):        
std.bitmanip.bigEndianToNative(T, ulong n)(ubyte[n] val) if 
(canSwapEndianness!(T) && n == T.sizeof)
./test.d(11): Error: template std.bitmanip.bigEndianToNative(T, 
ulong n)(ubyte[n] val) if (canSwapEndianness!(T) && n == 
T.sizeof) cannot deduce template function from argument types 
!(uint)(ubyte[])
./test.d(11): Error: template instance bigEndianToNative!(uint) 
errors instantiating template


More information about the Digitalmars-d-learn mailing list