簡體   English   中英

如何確定DBus消息中“結構數組”的長度?

[英]How do I determine the length of an “array of structs” in a DBus message?

我正在使用libdbus API發送方法調用並接收回復。 對於這種方法,我希望收到以下格式的答復:

"a(sqns)"

DBus簽名符號中的含義是:結構數組,其中每個結構的內容是字符串,uint16,int16和字符串。

使用DBusMessageIter (迭代器),我可以遍歷數組和結構。 但是,為了簡化我的解析代碼,有沒有辦法在迭代之前獲得此數組的長度?

不幸的是,我不認為dbus_message_iter_get_fixed_array在這種情況下適用,因為我的數組包含的結構在此定義下似乎表示非固定大小

從API文檔對我來說,如何執行此操作(或如果可行)尚不十分清楚。

參加聚會可能有點晚,但是為了將來參考,我已經成功使用dbus_message_iter_get_element_count() 您可以這樣使用它:

int count = dbus_message_iter_get_element_count(iter);
if(count > 0) {
  DBusMessageIter arriter;
  dbus_message_iter_recurse(iter, &arriter);
  for(int i = 0; i < count; ++i) {
    // read items from arriter
  }
}
dbus_message_iter_next(iter);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM