March 28, 2023

On Tuesday, 28 March 2023 at 05:05:58 UTC, Alexander Zhirov wrote:

>

On Tuesday, 28 March 2023 at 00:51:43 UTC, Steven Schveighoffer wrote:

>

auto uuid = UUID(cast(ubyte[16])youruuiddata.ptr);

ubyte[] arr = cast(ubyte[])value.attributes["objectGUID"][0].dup;
writeln(UUID(cast(ubyte[16])arr.ptr));

Error: cannot cast expression 'cast(ubyte*)arr' of type 'ubyte*' to 'ubyte[16]'

No, it's not possible to transform. The array is initially immutable(char[]).

the formatting messed up here. Try this code:

auto uuid = UUID(
    (cast(const(ubyte)[]) value.attributes["objectGUID"][0])
    [0 .. 16]
);

no need to .dup the values - UUID can work without manipulating the original data, so we just need to cast the immutable(char)[] to const(ubyte)[]

The LDAP library should probably really instead expose ubyte[] instead of string

March 28, 2023

This guid is (int,short,short,byte[8]) in little endian byte order. So if you want to convert it to big endian, you'll need to swap bytes in those int and two shorts.

ubyte[] guid=...
int* g1=cast(int*)guid.ptr;
*g1=bswap(*g1);
March 28, 2023

On 3/28/23 1:05 AM, Alexander Zhirov wrote:

>

On Tuesday, 28 March 2023 at 00:51:43 UTC, Steven Schveighoffer wrote:

>

auto uuid = UUID(*cast(ubyte[16]*)youruuiddata.ptr); (added quotes here)

ubyte[] arr = cast(ubyte[])value.attributes["objectGUID"][0].dup;
writeln(UUID(cast(ubyte[16])arr.ptr));

Error: cannot cast expression 'cast(ubyte*)arr' of type 'ubyte*' to 'ubyte[16]'

No, it's not possible to transform. The array is initially immutable(char[]).

Apologies, I quoted my original above to suppress the markdown formatting. Here it is again with syntax highlighting.

auto uuid = UUID(*cast(ubyte[16]*)youruuiddata.ptr);

That should work. I sometimes forget that my newsreader adds the markdown tag, even though it looks good on my end.

-Steve

March 28, 2023

On 3/28/23 6:36 AM, WebFreak001 wrote:

>

the formatting messed up here. Try this code:

auto uuid = UUID(
     (cast(const(ubyte)[]) value.attributes["objectGUID"][0])
     [0 .. 16]
);

Nice, I didn't think this would work actually!

-Steve

March 28, 2023

On Tuesday, 28 March 2023 at 13:18:59 UTC, Kagamin wrote:

>

This guid is (int,short,short,byte[8]) in little endian byte order. So if you want to convert it to big endian, you'll need to swap bytes in those int and two shorts.

ubyte[] guid=...
int* g1=cast(int*)guid.ptr;
*g1=bswap(*g1);

Yes, therefore, my option remains more correct rather than directly converting to UUID, since it does not correspond to the value specified in LDAP. Therefore, it is necessary to do byte permutations.

1 2
Next ›   Last »