Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env raku
use NativeCall;
constant EContactPhotoType is export := uint32;
our enum EContactPhotoTypeEnum is export <
E_CONTACT_PHOTO_TYPE_INLINED
E_CONTACT_PHOTO_TYPE_URI
>;
class EPhotoDataInlined is repr<CStruct> {
has Str $!mime_type;
has uint64 $.length is rw;
has CArray[uint8] $!data;
method data is rw {
Proxy.new:
FETCH => -> $ { $!data },
STORE => -> $, \v { $!data := v };
}
method mime_type is rw {
Proxy.new:
FETCH => -> $ { $!mime_type },
STORE => -> $, \v { $!mime_type := v };
}
}
class EPhotoData is repr<CUnion> {
HAS EPhotoDataInlined $!inlined;
has Str $!uri;
method inlined is rw {
Proxy.new:
FETCH => -> $ { $!inlined },
STORE => -> $, \v { $!inlined := v };
}
}
class EContactPhoto is repr<CStruct> is export {
has EContactPhotoType $.type;
HAS EPhotoData $.data;
}
my $fd = CArray[uint8].new(0 xx 160 ** 2);
my $p = EContactPhoto.new;
$p.data.inlined.data = CArray[uint8].new;
$p.data.inlined.length = $fd.elems;
$p.gist.say;
say nativecast(Pointer, $p);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment