blob: 545cf78df7f571ceb0e943c6a0a450bf84987544 [file] [log] [blame]
Zack Williamse940c7a2019-08-21 14:25:39 -07001/*
2Copyright 2014 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package serializer
18
19import (
20 "k8s.io/apimachinery/pkg/runtime"
21 "k8s.io/apimachinery/pkg/runtime/serializer/protobuf"
22)
23
24const (
25 // contentTypeProtobuf is the protobuf type exposed for Kubernetes. It is private to prevent others from
26 // depending on it unintentionally.
27 // TODO: potentially move to pkg/api (since it's part of the Kube public API) and pass it in to the
28 // CodecFactory on initialization.
29 contentTypeProtobuf = "application/vnd.kubernetes.protobuf"
30)
31
32func protobufSerializer(scheme *runtime.Scheme) (serializerType, bool) {
33 serializer := protobuf.NewSerializer(scheme, scheme, contentTypeProtobuf)
34 raw := protobuf.NewRawSerializer(scheme, scheme, contentTypeProtobuf)
35 return serializerType{
36 AcceptContentTypes: []string{contentTypeProtobuf},
37 ContentType: contentTypeProtobuf,
38 FileExtensions: []string{"pb"},
39 Serializer: serializer,
40
41 Framer: protobuf.LengthDelimitedFramer,
42 StreamSerializer: raw,
43 }, true
44}
45
46func init() {
47 serializerExtensions = append(serializerExtensions, protobufSerializer)
48}