gpt4 book ai didi

c - 使用 GDBus 通过 D-Bus 发送字节数组(类型 `ay`)

转载 作者:太空狗 更新时间:2023-10-29 14:55:00 24 4
gpt4 key购买 nike

我正在尝试使用 GDBus 绑定(bind)通过 D-Bus 生成字节数组。你能告诉我如何实现这一目标吗?我尝试使用谷歌搜索但没有帮助。

字节数组包含图像文件,因此无法转换为 charbytearray

需要任何帮助

最佳答案

我使用 XML 进行了一些测试,其中我使用了类型 ay .这适用于 QT 绑定(bind)(由 qdbusxml2cpp 生成),它转换为 QByteArray。然而,它似乎不适用于 glib 绑定(bind)​​(由 gdbus-codegen 生成),它在 gchar * 中翻译看起来你失去了 \0 之后的东西- 因为它以某种方式作为字符串处理。然而你会发现:

This automatic mapping can be turned off by using the annotation org.gtk.GDBus.C.ForceGVariant - if used then a GVariant is always exchanged instead of the corresponding native C type. This annotation may be convenient to use when using bytestrings (type-string ay) for data that could have embedded NUL bytes.

这意味着根据 https://developer.gnome.org/gio/stable/gdbus-codegen.html您可以将其处理为 GVariant .我通过添加注释标签 org.gtk.GDBus.C.ForceGVariant 来测试它<annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/>在每个参数上都有效。

关于c - 使用 GDBus 通过 D-Bus 发送字节数组(类型 `ay`),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22937588/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com