Created
May 23, 2021 21:09
-
-
Save raydiak/cded4a7621e3fd5762fa6e8390023ffb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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