如果通訊協定具有 @transport("Driver") 屬性,通訊協定會透過驅動程式庫傳輸作業,而非 Zircon 管道傳輸作業:
library fuchsia.example;
@transport("Driver")
protocol Protocol {
TwoWay(struct {
request uint32;
}) -> (struct {
response uint32;
});
};
驅動程式傳輸建構於 Fuchsia 驅動程式庫,與 Zircon 管道相比,具有不同的記憶體管理限制和不同的執行緒模型。因此,FIDL 用戶端和伺服器類型與 Zircon 管道上的通訊協定不同,可提供專屬 API。
fidl:: 命名空間下的大多數用戶端/伺服器類型,在 fdf:: 命名空間中都會有對應項目,提供相同功能,但專為驅動程式庫執行階段設計。舉例來說,如果要在 Zircon 管道傳輸上宣告非同步用戶端,您會編寫 fidl::Client,但如要使用上述範例通訊協定,則會編寫 fdf::Client<fuchsia_example::Protocol>。產生的 FIDL 標頭格式為 #include <fidl/fuchsia.example/cpp/driver/fidl.h>。
同樣地,使用僅限於線路類型的用戶端和伺服器 API 時,會編寫 fidl::WireClient 來透過 Zircon 管道傳輸宣告非同步用戶端,但若要使用上述範例通訊協定,則會編寫 fdf::WireClient<fuchsia_example::Protocol>。其中一個可能包含 #include <fidl/fuchsia.example/cpp/driver/wire.h> 的線路子集標頭。
透過驅動程式庫傳輸的 C++ 繫結正在疊代中。目前測試可做為使用繫結的範例。