Skip to content

Instantly share code, notes, and snippets.

@raydiak
Created May 23, 2021 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raydiak/cded4a7621e3fd5762fa6e8390023ffb to your computer and use it in GitHub Desktop.
Save raydiak/cded4a7621e3fd5762fa6e8390023ffb to your computer and use it in GitHub Desktop.
#!/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