<commit_before>/*
Copyright 2014 Google Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package api

import (
	"fmt"
	"reflect"

	"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1"
	"github.com/GoogleCloudPlatform/kubernetes/pkg/conversion"
	"gopkg.in/v1/yaml"
)

// codec defines methods for serializing and deserializing API
// objects
type codec interface {
	Encode(obj interface{}) (data []byte, err error)
	Decode(data []byte) (interface{}, error)
	DecodeInto(data []byte, obj interface{}) error
}

// resourceVersioner provides methods for setting and retrieving
// the resource version from an API object
type resourceVersioner interface {
	SetResourceVersion(obj interface{}, version uint64) error
	ResourceVersion(obj interface{}) (uint64, error)
}

var Codec codec
var ResourceVersioner resourceVersioner

var conversionScheme *conversion.Scheme

func init() {
	conversionScheme = conversion.NewScheme()
	conversionScheme.InternalVersion = ""
	conversionScheme.ExternalVersion = "v1beta1"
	conversionScheme.MetaInsertionFactory = metaInsertion{}
	AddKnownTypes("",
		PodList{},
		Pod{},
		ReplicationControllerList{},
		ReplicationController{},
		ServiceList{},
		Service{},
		MinionList{},
		Minion{},
		Status{},
		ServerOpList{},
		ServerOp{},
		ContainerManifestList{},
		Endpoints{},
		Binding{},
	)
	AddKnownTypes("v1beta1",
		v1beta1.PodList{},
		v1beta1.Pod{},
		v1beta1.ReplicationControllerList{},
		v1beta1.ReplicationController{},
		v1beta1.ServiceList{},
		v1beta1.Service{},
		v1beta1.MinionList{},
		v1beta1.Minion{},
		v1beta1.Status{},
		v1beta1.ServerOpList{},
		v1beta1.ServerOp{},
		v1beta1.ContainerManifestList{},
		v1beta1.Endpoints{},
		v1beta1.Binding{},
	)

	// TODO: when we get more of this stuff, move to its own file. This is not a
	// good home for lots of conversion functions.
	// TODO: Consider inverting dependency chain-- imagine v1beta1 package
	// registering all of these functions. Then, if you want to be able to understand
	// v1beta1 objects, you just import that package for its side effects.
	AddConversionFuncs(
		// EnvVar's Name is depricated in favor of Key.
		func(in *EnvVar, out *v1beta1.EnvVar) error {
			out.Value = in.Value
			out.Key = in.Name
			out.Name = in.Name
			return nil
		},
		func(in *v1beta1.EnvVar, out *EnvVar) error {
			out.Value = in.Value
			if in.Name != "" {
				out.Name = in.Name
			} else {
				out.Name = in.Key
			}
			return nil
		},
	)

	Codec = conversionScheme
	ResourceVersioner = NewJSONBaseResourceVersioner()
}

// AddKnownTypes registers the types of the arguments to the marshaller of the package api.
// Encode() refuses the object unless its type is registered with AddKnownTypes.
func AddKnownTypes(version string, types ...interface{}) {
	conversionScheme.AddKnownTypes(version, types...)
}

// New returns a new API object of the given version ("" for internal
// representation) and name, or an error if it hasn't been registered.<commit_msg>Correct confusing comment.<commit_after>/*
Copyright 2014 Google Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package api

import (
	"fmt"
	"reflect"

	"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1"
	"github.com/GoogleCloudPlatform/kubernetes/pkg/conversion"
	"gopkg.in/v1/yaml"
)

// codec defines methods for serializing and deserializing API
// objects
type codec interface {
	Encode(obj interface{}) (data []byte, err error)
	Decode(data []byte) (interface{}, error)
	DecodeInto(data []byte, obj interface{}) error
}

// resourceVersioner provides methods for setting and retrieving
// the resource version from an API object
type resourceVersioner interface {
	SetResourceVersion(obj interface{}, version uint64) error
	ResourceVersion(obj interface{}) (uint64, error)
}

var Codec codec
var ResourceVersioner resourceVersioner

var conversionScheme *conversion.Scheme

func init() {
	conversionScheme = conversion.NewScheme()
	conversionScheme.InternalVersion = ""
	conversionScheme.ExternalVersion = "v1beta1"
	conversionScheme.MetaInsertionFactory = metaInsertion{}
	AddKnownTypes("",
		PodList{},
		Pod{},
		ReplicationControllerList{},
		ReplicationController{},
		ServiceList{},
		Service{},
		MinionList{},
		Minion{},
		Status{},
		ServerOpList{},
		ServerOp{},
		ContainerManifestList{},
		Endpoints{},
		Binding{},
	)
	AddKnownTypes("v1beta1",
		v1beta1.PodList{},
		v1beta1.Pod{},
		v1beta1.ReplicationControllerList{},
		v1beta1.ReplicationController{},
		v1beta1.ServiceList{},
		v1beta1.Service{},
		v1beta1.MinionList{},
		v1beta1.Minion{},
		v1beta1.Status{},
		v1beta1.ServerOpList{},
		v1beta1.ServerOp{},
		v1beta1.ContainerManifestList{},
		v1beta1.Endpoints{},
		v1beta1.Binding{},
	)

	// TODO: when we get more of this stuff, move to its own file. This is not a
	// good home for lots of conversion functions.
	// TODO: Consider inverting dependency chain-- imagine v1beta1 package
	// registering all of these functions. Then, if you want to be able to understand
	// v1beta1 objects, you just import that package for its side effects.
	AddConversionFuncs(
		// EnvVar's Key is deprecated in favor of Name.
		func(in *EnvVar, out *v1beta1.EnvVar) error {
			out.Value = in.Value
			out.Key = in.Name
			out.Name = in.Name
			return nil
		},
		func(in *v1beta1.EnvVar, out *EnvVar) error {
			out.Value = in.Value
			if in.Name != "" {
				out.Name = in.Name
			} else {
				out.Name = in.Key
			}
			return nil
		},
	)

	Codec = conversionScheme
	ResourceVersioner = NewJSONBaseResourceVersioner()
}

// AddKnownTypes registers the types of the arguments to the marshaller of the package api.
// Encode() refuses the object unless its type is registered with AddKnownTypes.
func AddKnownTypes(version string, types ...interface{}) {
	conversionScheme.AddKnownTypes(version, types...)
}

// New returns a new API object of the given version ("" for internal
// representation) and name, or an error if it hasn't been registered.
{'fraction_non_alphanumeric': 0.10093592512598992, 'fraction_numerical': 0.01583873290136789, 'mean_word_length': 4.2701062215478, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4762769', 'n_tokens_mistral': 2230, 'n_tokens_neox': 2043, 'n_words': 699}