Merge pull request #8757 from dcantah/proto-api-conversions

Add From/ToProto helpers
This commit is contained in:
Kazuyoshi Kato
2023-07-03 10:59:08 -07:00
committed by GitHub
13 changed files with 200 additions and 374 deletions

View File

@@ -116,6 +116,7 @@ import (
specs "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/containerd/containerd/api/types"
"github.com/containerd/containerd/errdefs"
)
@@ -275,3 +276,30 @@ func Normalize(platform specs.Platform) specs.Platform {
return platform
}
// ToProto converts from a slice of [Platform] to a slice of
// the protobuf definition [types.Platform].
func ToProto(platforms []Platform) []*types.Platform {
ap := make([]*types.Platform, len(platforms))
for i := range platforms {
p := types.Platform{
OS: platforms[i].OS,
Architecture: platforms[i].Architecture,
Variant: platforms[i].Variant,
}
ap[i] = &p
}
return ap
}
// FromProto converts a slice of the protobuf definition [types.Platform]
// to a slice of [Platform].
func FromProto(platforms []*types.Platform) []Platform {
op := make([]Platform, len(platforms))
for i := range platforms {
op[i].OS = platforms[i].OS
op[i].Architecture = platforms[i].Architecture
op[i].Variant = platforms[i].Variant
}
return op
}