Copyright 2018 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

package impl

import (
	
	

	pref 
)
unwrapper unwraps the value to the underlying value. This is implemented by List and Map.
type unwrapper interface {
	protoUnwrap() interface{}
}
A Converter coverts to/from Go reflect.Value types and protobuf protoreflect.Value types.
PBValueOf converts a reflect.Value to a protoreflect.Value.
	PBValueOf(reflect.Value) pref.Value
GoValueOf converts a protoreflect.Value to a reflect.Value.
	GoValueOf(pref.Value) reflect.Value
IsValidPB returns whether a protoreflect.Value is compatible with this type.
	IsValidPB(pref.Value) bool
IsValidGo returns whether a reflect.Value is compatible with this type.
	IsValidGo(reflect.Value) bool
New returns a new field value. For scalars, it returns the default value of the field. For composite types, it returns a new mutable value.
	New() pref.Value
Zero returns a new field value. For scalars, it returns the default value of the field. For composite types, it returns an immutable, empty value.
	Zero() pref.Value
}
NewConverter matches a Go type with a protobuf field and returns a Converter that converts between the two. Enums must be a named int32 kind that implements protoreflect.Enum, and messages must be pointer to a named struct type that implements protoreflect.ProtoMessage. This matcher deliberately supports a wider range of Go types than what protoc-gen-go historically generated to be able to automatically wrap some v1 messages generated by other forks of protoc-gen-go.
Default isn't defined for repeated fields.
			return 
		}
		return .Default()
	}
	switch .Kind() {
	case pref.BoolKind:
		if .Kind() == reflect.Bool {
			return &boolConverter{, (, boolZero)}
		}
	case pref.Int32Kind, pref.Sint32Kind, pref.Sfixed32Kind:
		if .Kind() == reflect.Int32 {
			return &int32Converter{, (, int32Zero)}
		}
	case pref.Int64Kind, pref.Sint64Kind, pref.Sfixed64Kind:
		if .Kind() == reflect.Int64 {
			return &int64Converter{, (, int64Zero)}
		}
	case pref.Uint32Kind, pref.Fixed32Kind:
		if .Kind() == reflect.Uint32 {
			return &uint32Converter{, (, uint32Zero)}
		}
	case pref.Uint64Kind, pref.Fixed64Kind:
		if .Kind() == reflect.Uint64 {
			return &uint64Converter{, (, uint64Zero)}
		}
	case pref.FloatKind:
		if .Kind() == reflect.Float32 {
			return &float32Converter{, (, float32Zero)}
		}
	case pref.DoubleKind:
		if .Kind() == reflect.Float64 {
			return &float64Converter{, (, float64Zero)}
		}
	case pref.StringKind:
		if .Kind() == reflect.String || (.Kind() == reflect.Slice && .Elem() == byteType) {
			return &stringConverter{, (, stringZero)}
		}
	case pref.BytesKind:
		if .Kind() == reflect.String || (.Kind() == reflect.Slice && .Elem() == byteType) {
			return &bytesConverter{, (, bytesZero)}
		}
Handle enums, which must be a named int32 type.
		if .Kind() == reflect.Int32 {
			return newEnumConverter(, )
		}
	case pref.MessageKind, pref.GroupKind:
		return newMessageConverter()
	}
	panic(fmt.Sprintf("invalid Go type %v for field %v", , .FullName()))
}

type boolConverter struct {
	goType reflect.Type
	def    pref.Value
}

func ( *boolConverter) ( reflect.Value) pref.Value {
	if .Type() != .goType {
		panic(fmt.Sprintf("invalid type: got %v, want %v", .Type(), .goType))
	}
	return pref.ValueOfBool(.Bool())
}
func ( *boolConverter) ( pref.Value) reflect.Value {
	return reflect.ValueOf(.Bool()).Convert(.goType)
}
func ( *boolConverter) ( pref.Value) bool {
	,  := .Interface().(bool)
	return 
}
func ( *boolConverter) ( reflect.Value) bool {
	return .IsValid() && .Type() == .goType
}
func ( *boolConverter) () pref.Value  { return .def }
func ( *boolConverter) () pref.Value { return .def }

type int32Converter struct {
	goType reflect.Type
	def    pref.Value
}

func ( *int32Converter) ( reflect.Value) pref.Value {
	if .Type() != .goType {
		panic(fmt.Sprintf("invalid type: got %v, want %v", .Type(), .goType))
	}
	return pref.ValueOfInt32(int32(.Int()))
}
func ( *int32Converter) ( pref.Value) reflect.Value {
	return reflect.ValueOf(int32(.Int())).Convert(.goType)
}
func ( *int32Converter) ( pref.Value) bool {
	,  := .Interface().(int32)
	return 
}
func ( *int32Converter) ( reflect.Value) bool {
	return .IsValid() && .Type() == .goType
}
func ( *int32Converter) () pref.Value  { return .def }
func ( *int32Converter) () pref.Value { return .def }

type int64Converter struct {
	goType reflect.Type
	def    pref.Value
}

func ( *int64Converter) ( reflect.Value) pref.Value {
	if .Type() != .goType {
		panic(fmt.Sprintf("invalid type: got %v, want %v", .Type(), .goType))
	}
	return pref.ValueOfInt64(int64(.Int()))
}
func ( *int64Converter) ( pref.Value) reflect.Value {
	return reflect.ValueOf(int64(.Int())).Convert(.goType)
}
func ( *int64Converter) ( pref.Value) bool {
	,  := .Interface().(int64)
	return 
}
func ( *int64Converter) ( reflect.Value) bool {
	return .IsValid() && .Type() == .goType
}
func ( *int64Converter) () pref.Value  { return .def }
func ( *int64Converter) () pref.Value { return .def }

type uint32Converter struct {
	goType reflect.Type
	def    pref.Value
}

func ( *uint32Converter) ( reflect.Value) pref.Value {
	if .Type() != .goType {
		panic(fmt.Sprintf("invalid type: got %v, want %v", .Type(), .goType))
	}
	return pref.ValueOfUint32(uint32(.Uint()))
}
func ( *uint32Converter) ( pref.Value) reflect.Value {
	return reflect.ValueOf(uint32(.Uint())).Convert(.goType)
}
func ( *uint32Converter) ( pref.Value) bool {
	,  := .Interface().(uint32)
	return 
}
func ( *uint32Converter) ( reflect.Value) bool {
	return .IsValid() && .Type() == .goType
}
func ( *uint32Converter) () pref.Value  { return .def }
func ( *uint32Converter) () pref.Value { return .def }

type uint64Converter struct {
	goType reflect.Type
	def    pref.Value
}

func ( *uint64Converter) ( reflect.Value) pref.Value {
	if .Type() != .goType {
		panic(fmt.Sprintf("invalid type: got %v, want %v", .Type(), .goType))
	}
	return pref.ValueOfUint64(uint64(.Uint()))
}
func ( *uint64Converter) ( pref.Value) reflect.Value {
	return reflect.ValueOf(uint64(.Uint())).Convert(.goType)
}
func ( *uint64Converter) ( pref.Value) bool {
	,  := .Interface().(uint64)
	return 
}
func ( *uint64Converter) ( reflect.Value) bool {
	return .IsValid() && .Type() == .goType
}
func ( *uint64Converter) () pref.Value  { return .def }
func ( *uint64Converter) () pref.Value { return .def }

type float32Converter struct {
	goType reflect.Type
	def    pref.Value
}

func ( *float32Converter) ( reflect.Value) pref.Value {
	if .Type() != .goType {
		panic(fmt.Sprintf("invalid type: got %v, want %v", .Type(), .goType))
	}
	return pref.ValueOfFloat32(float32(.Float()))
}
func ( *float32Converter) ( pref.Value) reflect.Value {
	return reflect.ValueOf(float32(.Float())).Convert(.goType)
}
func ( *float32Converter) ( pref.Value) bool {
	,  := .Interface().(float32)
	return 
}
func ( *float32Converter) ( reflect.Value) bool {
	return .IsValid() && .Type() == .goType
}
func ( *float32Converter) () pref.Value  { return .def }
func ( *float32Converter) () pref.Value { return .def }

type float64Converter struct {
	goType reflect.Type
	def    pref.Value
}

func ( *float64Converter) ( reflect.Value) pref.Value {
	if .Type() != .goType {
		panic(fmt.Sprintf("invalid type: got %v, want %v", .Type(), .goType))
	}
	return pref.ValueOfFloat64(float64(.Float()))
}
func ( *float64Converter) ( pref.Value) reflect.Value {
	return reflect.ValueOf(float64(.Float())).Convert(.goType)
}
func ( *float64Converter) ( pref.Value) bool {
	,  := .Interface().(float64)
	return 
}
func ( *float64Converter) ( reflect.Value) bool {
	return .IsValid() && .Type() == .goType
}
func ( *float64Converter) () pref.Value  { return .def }
func ( *float64Converter) () pref.Value { return .def }

type stringConverter struct {
	goType reflect.Type
	def    pref.Value
}

func ( *stringConverter) ( reflect.Value) pref.Value {
	if .Type() != .goType {
		panic(fmt.Sprintf("invalid type: got %v, want %v", .Type(), .goType))
	}
	return pref.ValueOfString(.Convert(stringType).String())
}
pref.Value.String never panics, so we go through an interface conversion here to check the type.
	 := .Interface().(string)
	if .goType.Kind() == reflect.Slice &&  == "" {
		return reflect.Zero(.goType) // ensure empty string is []byte(nil)
	}
	return reflect.ValueOf().Convert(.goType)
}
func ( *stringConverter) ( pref.Value) bool {
	,  := .Interface().(string)
	return 
}
func ( *stringConverter) ( reflect.Value) bool {
	return .IsValid() && .Type() == .goType
}
func ( *stringConverter) () pref.Value  { return .def }
func ( *stringConverter) () pref.Value { return .def }

type bytesConverter struct {
	goType reflect.Type
	def    pref.Value
}

func ( *bytesConverter) ( reflect.Value) pref.Value {
	if .Type() != .goType {
		panic(fmt.Sprintf("invalid type: got %v, want %v", .Type(), .goType))
	}
	if .goType.Kind() == reflect.String && .Len() == 0 {
		return pref.ValueOfBytes(nil) // ensure empty string is []byte(nil)
	}
	return pref.ValueOfBytes(.Convert(bytesType).Bytes())
}
func ( *bytesConverter) ( pref.Value) reflect.Value {
	return reflect.ValueOf(.Bytes()).Convert(.goType)
}
func ( *bytesConverter) ( pref.Value) bool {
	,  := .Interface().([]byte)
	return 
}
func ( *bytesConverter) ( reflect.Value) bool {
	return .IsValid() && .Type() == .goType
}
func ( *bytesConverter) () pref.Value  { return .def }
func ( *bytesConverter) () pref.Value { return .def }

type enumConverter struct {
	goType reflect.Type
	def    pref.Value
}

func ( reflect.Type,  pref.FieldDescriptor) Converter {
	var  pref.Value
	if .Cardinality() == pref.Repeated {
		 = pref.ValueOfEnum(.Enum().Values().Get(0).Number())
	} else {
		 = .Default()
	}
	return &enumConverter{, }
}

func ( *enumConverter) ( reflect.Value) pref.Value {
	if .Type() != .goType {
		panic(fmt.Sprintf("invalid type: got %v, want %v", .Type(), .goType))
	}
	return pref.ValueOfEnum(pref.EnumNumber(.Int()))
}

func ( *enumConverter) ( pref.Value) reflect.Value {
	return reflect.ValueOf(.Enum()).Convert(.goType)
}

func ( *enumConverter) ( pref.Value) bool {
	,  := .Interface().(pref.EnumNumber)
	return 
}

func ( *enumConverter) ( reflect.Value) bool {
	return .IsValid() && .Type() == .goType
}

func ( *enumConverter) () pref.Value {
	return .def
}

func ( *enumConverter) () pref.Value {
	return .def
}

type messageConverter struct {
	goType reflect.Type
}

func ( reflect.Type) Converter {
	return &messageConverter{}
}

func ( *messageConverter) ( reflect.Value) pref.Value {
	if .Type() != .goType {
		panic(fmt.Sprintf("invalid type: got %v, want %v", .Type(), .goType))
	}
	if ,  := .Interface().(pref.ProtoMessage);  {
		return pref.ValueOfMessage(.ProtoReflect())
	}
	return pref.ValueOfMessage(legacyWrapMessage())
}

func ( *messageConverter) ( pref.Value) reflect.Value {
	 := .Message()
	var  reflect.Value
	if ,  := .(unwrapper);  {
		 = reflect.ValueOf(.protoUnwrap())
	} else {
		 = reflect.ValueOf(.Interface())
	}
	if .Type() != .goType {
		panic(fmt.Sprintf("invalid type: got %v, want %v", .Type(), .goType))
	}
	return 
}

func ( *messageConverter) ( pref.Value) bool {
	 := .Message()
	var  reflect.Value
	if ,  := .(unwrapper);  {
		 = reflect.ValueOf(.protoUnwrap())
	} else {
		 = reflect.ValueOf(.Interface())
	}
	return .Type() == .goType
}

func ( *messageConverter) ( reflect.Value) bool {
	return .IsValid() && .Type() == .goType
}

func ( *messageConverter) () pref.Value {
	return .PBValueOf(reflect.New(.goType.Elem()))
}

func ( *messageConverter) () pref.Value {
	return .PBValueOf(reflect.Zero(.goType))