通訊協定功能

是特定

library fuchsia.examples;

const MAX_STRING_LENGTH uint64 = 32;

@discoverable
protocol Echo {
    EchoString(struct {
        value string:MAX_STRING_LENGTH;
    }) -> (struct {
        response string:MAX_STRING_LENGTH;
    });
    SendString(struct {
        value string:MAX_STRING_LENGTH;
    });
    -> OnString(struct {
        response string:MAX_STRING_LENGTH;
    });
};

並從另一個元件中的 namespace 消耗。

提供通訊協定功能

如要提供通訊協定能力,元件必須宣告該能力,並從 self 路由該功能。元件會在其

如要定義能力,請為其新增 capabilities 宣告:

{
    capabilities: [
        {
            protocol: "fuchsia.example.ExampleProtocol",
        },
    ],
}

這會定義這個元件所代管的能力,其傳出目錄路徑為 /svc/fuchsia.example.ExampleProtocol。您也可以自訂路徑:

{
    capabilities: [
        {
            protocol: "fuchsia.example.ExampleProtocol",
            path: "/my_svc/fuchsia.example.MyExampleProtocol",
        },
    ],
}

路由通訊協定功能

元件會將通訊協定功能公開給父項,並提供給子項。

如要進一步瞭解架構如何將元件功能轉送至其他元件,請參閱「功能轉送」。

公開

公開通訊協定能力可讓元件的父項存取該能力:

{
    expose: [
        {
            protocol: "fuchsia.example.ExampleProtocol",
            from: "self",
        },
    ],
}

from: "self" 指令表示此元件提供通訊協定能力。

提供

提供通訊協定能力可讓子元件存取該能力:

{
    offer: [
        {
            protocol: "fuchsia.example.ExampleProtocol",
            from: "self",
            to: [ "#child-a", "#child_b" ],
        },
    ],
}

使用通訊協定功能

如要使用通訊協定能力,元件必須要求該能力,並在其

如要要求此能力,請為其新增 use 宣告:

{
    use: [
        {
            protocol: "fuchsia.example.ExampleProtocol",
        },
    ],
}

這會在元件命名空間的已知路徑 /svc/fuchsia.example.ExampleProtocol 中填入通訊協定。您也可以自訂路徑:

{
    use: [
        {
            protocol: "fuchsia.example.ExampleProtocol",
            path: "/my_svc/fuchsia.example.MyExampleProtocol",
        },
    ],
}

如要進一步瞭解開啟要求,請參閱「通訊協定開啟的生命週期」。

使用選用通訊協定功能

請參閱「Connect 元件:使用選用功能」。

架構通訊協定

架構通訊協定是元件架構提供的通訊協定。任何元件都可以將 framework 設為來源,而無須搭配父項的 offer,即可use這些功能。Fuchsia 支援下列架構通訊協定:

{
    use: [
        {
            protocol: "fuchsia.component.Realm",
            from: "framework",
        },
    ],
}