【发布时间】:2017-11-28 14:14:11
【问题描述】:
我正在尝试为 GJS 中的 chrome/firefox 扩展编写 native messaging host(因为它将依赖已用 GJS 编写的代码),但遇到了一些障碍。我使用chrome-gnome-shell作为一个粗略的模板,因为它也使用了GLib/Gio自省和GApplication,但它具有我没有的pythonstruct的优势。
很快,本地消息传递主机通过 stdin/stdout 交换消息,这些消息是 Int32(4 字节)长度,后跟一串 utf-8 编码的 JSON。
chrome-gnome-shell 使用 GLib.IOChannel 和 set_encoding('utf-8') 和 struct 来处理 int32 字节。我在 GJS 中使用该类时遇到了麻烦,并且没有 struct,所以一直在尝试将 Gio.UnixInputStream 包裹在 Gio.DataInputStream(和输出对应项)中,使用 put_int32()/read_int32() 和 put_string()/@ 987654335@.
显然,我对自己在做什么感到非常困惑。如果我打电话给Gio.DataInputStream.read_int32(),它会返回一个数字369098752,所以我猜int32 没有被转换为常规数字。如果我打电话给Gio.DataInputStream.read_bytes(4, null).unref_to_array() 得到一个字节数组; ByteArray.toString() 返回 '\u0016' 而 ByteArray[0] 返回似乎是实际长度的 '22'。
一些关于读取/写入 int32 到数据流的指针,将不胜感激。
chrome-gnome-shell 参考:
【问题讨论】:
标签: glib chrome-native-messaging gjs