Convert binary to UUID from LDAP
WebFreak001
d.forum at webfreak.org
Tue Mar 28 10:36:57 UTC 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);
>
> ```d
> 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:
```d
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`
More information about the Digitalmars-d-learn
mailing list