diff --git a/plugin/set.go b/plugin/set.go index 9211e7ea5..68e6650bc 100644 --- a/plugin/set.go +++ b/plugin/set.go @@ -39,15 +39,24 @@ type Set struct { Datasources map[string]packersdk.Datasource } +// ProtocolVersion2 serves as a compatibility argument to the SetDescription +// so plugins can report whether or not they support protobuf/msgpack for +// serialising some of their entities (typically ObjectSpec) to protobuf. +// +// If absent from the SetDescription, it means only gob is supported, and both +// Packer and the plugins should use that for communication. +const ProtocolVersion2 = "v2" + // SetDescription describes a Set. type SetDescription struct { - Version string `json:"version"` - SDKVersion string `json:"sdk_version"` - APIVersion string `json:"api_version"` - Builders []string `json:"builders"` - PostProcessors []string `json:"post_processors"` - Provisioners []string `json:"provisioners"` - Datasources []string `json:"datasources"` + Version string `json:"version"` + SDKVersion string `json:"sdk_version"` + APIVersion string `json:"api_version"` + Builders []string `json:"builders"` + PostProcessors []string `json:"post_processors"` + Provisioners []string `json:"provisioners"` + Datasources []string `json:"datasources"` + ProtocolVersion string `json:"protocol_version"` } //// @@ -158,13 +167,14 @@ func (i *Set) start(kind, name string) error { func (i *Set) description() SetDescription { return SetDescription{ - Version: i.version, - SDKVersion: i.sdkVersion, - APIVersion: i.apiVersion, - Builders: i.buildersDescription(), - PostProcessors: i.postProcessorsDescription(), - Provisioners: i.provisionersDescription(), - Datasources: i.datasourceDescription(), + Version: i.version, + SDKVersion: i.sdkVersion, + APIVersion: i.apiVersion, + Builders: i.buildersDescription(), + PostProcessors: i.postProcessorsDescription(), + Provisioners: i.provisionersDescription(), + Datasources: i.datasourceDescription(), + ProtocolVersion: ProtocolVersion2, } } diff --git a/plugin/set_test.go b/plugin/set_test.go index f29ecc8f4..02d65e115 100644 --- a/plugin/set_test.go +++ b/plugin/set_test.go @@ -52,13 +52,14 @@ func TestSet(t *testing.T) { sdkVersion := pluginVersion.NewPluginVersion(pluginVersion.Version, pluginVersion.VersionPrerelease, "") if diff := cmp.Diff(SetDescription{ - Version: "1.1.1", - SDKVersion: sdkVersion.String(), - APIVersion: "x" + APIVersionMajor + "." + APIVersionMinor, - Builders: []string{"example", "example-2"}, - PostProcessors: []string{"example", "example-2"}, - Provisioners: []string{"example", "example-2"}, - Datasources: []string{"example", "example-2"}, + Version: "1.1.1", + SDKVersion: sdkVersion.String(), + APIVersion: "x" + APIVersionMajor + "." + APIVersionMinor, + Builders: []string{"example", "example-2"}, + PostProcessors: []string{"example", "example-2"}, + Provisioners: []string{"example", "example-2"}, + Datasources: []string{"example", "example-2"}, + ProtocolVersion: ProtocolVersion2, }, outputDesc); diff != "" { t.Fatalf("Unexpected description: %s", diff) }