Debian Codegraph @

util/criutil/alpha.go

raw
1 /*
2 Copyright The containerd Authors.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17 // Copied from https://github.com/containerd/containerd/blob/v1.7.0-beta.2/pkg/cri/util/alpha.go
18 // for allowing building stargz-snapshotter with older version of containerd
19
20 package criutil
21
22 import (
23 "github.com/containerd/containerd/protobuf/proto"
24 "google.golang.org/protobuf/reflect/protoreflect"
25 )
26
27 func AlphaReqToV1Req(
28 alphar protoreflect.ProtoMessage,
29 v1r interface{ Unmarshal(_ []byte) error },
30 ) error {
31 p, err := proto.Marshal(alphar)
32 if err != nil {
33 return err
34 }
35
36 if err = v1r.Unmarshal(p); err != nil {
37 return err
38 }
39 return nil
40 }
41
42 func V1RespToAlphaResp(
43 v1res interface{ Marshal() ([]byte, error) },
44 alphares protoreflect.ProtoMessage,
45 ) error {
46 p, err := v1res.Marshal()
47 if err != nil {
48 return err
49 }
50
51 if err = proto.Unmarshal(p, alphares); err != nil {
52 return err
53 }
54 return nil
55 }