// 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.

// Code generated by generate-types. DO NOT EDIT.

package proto

import (
	
	

	
	
	
	
)

// unmarshalScalar decodes a value of the given kind.
//
// Message values are decoded into a []byte which aliases the input data.
func ( UnmarshalOptions) ( []byte,  protowire.Type,  protoreflect.FieldDescriptor) ( protoreflect.Value,  int,  error) {
	switch .Kind() {
	case protoreflect.BoolKind:
		if  != protowire.VarintType {
			return , 0, errUnknown
		}
		,  := protowire.ConsumeVarint()
		if  < 0 {
			return , 0, errDecode
		}
		return protoreflect.ValueOfBool(protowire.DecodeBool()), , nil
	case protoreflect.EnumKind:
		if  != protowire.VarintType {
			return , 0, errUnknown
		}
		,  := protowire.ConsumeVarint()
		if  < 0 {
			return , 0, errDecode
		}
		return protoreflect.ValueOfEnum(protoreflect.EnumNumber()), , nil
	case protoreflect.Int32Kind:
		if  != protowire.VarintType {
			return , 0, errUnknown
		}
		,  := protowire.ConsumeVarint()
		if  < 0 {
			return , 0, errDecode
		}
		return protoreflect.ValueOfInt32(int32()), , nil
	case protoreflect.Sint32Kind:
		if  != protowire.VarintType {
			return , 0, errUnknown
		}
		,  := protowire.ConsumeVarint()
		if  < 0 {
			return , 0, errDecode
		}
		return protoreflect.ValueOfInt32(int32(protowire.DecodeZigZag( & math.MaxUint32))), , nil
	case protoreflect.Uint32Kind:
		if  != protowire.VarintType {
			return , 0, errUnknown
		}
		,  := protowire.ConsumeVarint()
		if  < 0 {
			return , 0, errDecode
		}
		return protoreflect.ValueOfUint32(uint32()), , nil
	case protoreflect.Int64Kind:
		if  != protowire.VarintType {
			return , 0, errUnknown
		}
		,  := protowire.ConsumeVarint()
		if  < 0 {
			return , 0, errDecode
		}
		return protoreflect.ValueOfInt64(int64()), , nil
	case protoreflect.Sint64Kind:
		if  != protowire.VarintType {
			return , 0, errUnknown
		}
		,  := protowire.ConsumeVarint()
		if  < 0 {
			return , 0, errDecode
		}
		return protoreflect.ValueOfInt64(protowire.DecodeZigZag()), , nil
	case protoreflect.Uint64Kind:
		if  != protowire.VarintType {
			return , 0, errUnknown
		}
		,  := protowire.ConsumeVarint()
		if  < 0 {
			return , 0, errDecode
		}
		return protoreflect.ValueOfUint64(), , nil
	case protoreflect.Sfixed32Kind:
		if  != protowire.Fixed32Type {
			return , 0, errUnknown
		}
		,  := protowire.ConsumeFixed32()
		if  < 0 {
			return , 0, errDecode
		}
		return protoreflect.ValueOfInt32(int32()), , nil
	case protoreflect.Fixed32Kind:
		if  != protowire.Fixed32Type {
			return , 0, errUnknown
		}
		,  := protowire.ConsumeFixed32()
		if  < 0 {
			return , 0, errDecode
		}
		return protoreflect.ValueOfUint32(uint32()), , nil
	case protoreflect.FloatKind:
		if  != protowire.Fixed32Type {
			return , 0, errUnknown
		}
		,  := protowire.ConsumeFixed32()
		if  < 0 {
			return , 0, errDecode
		}
		return protoreflect.ValueOfFloat32(math.Float32frombits(uint32())), , nil
	case protoreflect.Sfixed64Kind:
		if  != protowire.Fixed64Type {
			return , 0, errUnknown
		}
		,  := protowire.ConsumeFixed64()
		if  < 0 {
			return , 0, errDecode
		}
		return protoreflect.ValueOfInt64(int64()), , nil
	case protoreflect.Fixed64Kind:
		if  != protowire.Fixed64Type {
			return , 0, errUnknown
		}
		,  := protowire.ConsumeFixed64()
		if  < 0 {
			return , 0, errDecode
		}
		return protoreflect.ValueOfUint64(), , nil
	case protoreflect.DoubleKind:
		if  != protowire.Fixed64Type {
			return , 0, errUnknown
		}
		,  := protowire.ConsumeFixed64()
		if  < 0 {
			return , 0, errDecode
		}
		return protoreflect.ValueOfFloat64(math.Float64frombits()), , nil
	case protoreflect.StringKind:
		if  != protowire.BytesType {
			return , 0, errUnknown
		}
		,  := protowire.ConsumeBytes()
		if  < 0 {
			return , 0, errDecode
		}
		if strs.EnforceUTF8() && !utf8.Valid() {
			return protoreflect.Value{}, 0, errors.InvalidUTF8(string(.FullName()))
		}
		return protoreflect.ValueOfString(string()), , nil
	case protoreflect.BytesKind:
		if  != protowire.BytesType {
			return , 0, errUnknown
		}
		,  := protowire.ConsumeBytes()
		if  < 0 {
			return , 0, errDecode
		}
		return protoreflect.ValueOfBytes(append(emptyBuf[:], ...)), , nil
	case protoreflect.MessageKind:
		if  != protowire.BytesType {
			return , 0, errUnknown
		}
		,  := protowire.ConsumeBytes()
		if  < 0 {
			return , 0, errDecode
		}
		return protoreflect.ValueOfBytes(), , nil
	case protoreflect.GroupKind:
		if  != protowire.StartGroupType {
			return , 0, errUnknown
		}
		,  := protowire.ConsumeGroup(.Number(), )
		if  < 0 {
			return , 0, errDecode
		}
		return protoreflect.ValueOfBytes(), , nil
	default:
		return , 0, errUnknown
	}
}

func ( UnmarshalOptions) ( []byte,  protowire.Type,  protoreflect.List,  protoreflect.FieldDescriptor) ( int,  error) {
	switch .Kind() {
	case protoreflect.BoolKind:
		if  == protowire.BytesType {
			,  := protowire.ConsumeBytes()
			if  < 0 {
				return 0, errDecode
			}
			for len() > 0 {
				,  := protowire.ConsumeVarint()
				if  < 0 {
					return 0, errDecode
				}
				 = [:]
				.Append(protoreflect.ValueOfBool(protowire.DecodeBool()))
			}
			return , nil
		}
		if  != protowire.VarintType {
			return 0, errUnknown
		}
		,  := protowire.ConsumeVarint()
		if  < 0 {
			return 0, errDecode
		}
		.Append(protoreflect.ValueOfBool(protowire.DecodeBool()))
		return , nil
	case protoreflect.EnumKind:
		if  == protowire.BytesType {
			,  := protowire.ConsumeBytes()
			if  < 0 {
				return 0, errDecode
			}
			for len() > 0 {
				,  := protowire.ConsumeVarint()
				if  < 0 {
					return 0, errDecode
				}
				 = [:]
				.Append(protoreflect.ValueOfEnum(protoreflect.EnumNumber()))
			}
			return , nil
		}
		if  != protowire.VarintType {
			return 0, errUnknown
		}
		,  := protowire.ConsumeVarint()
		if  < 0 {
			return 0, errDecode
		}
		.Append(protoreflect.ValueOfEnum(protoreflect.EnumNumber()))
		return , nil
	case protoreflect.Int32Kind:
		if  == protowire.BytesType {
			,  := protowire.ConsumeBytes()
			if  < 0 {
				return 0, errDecode
			}
			for len() > 0 {
				,  := protowire.ConsumeVarint()
				if  < 0 {
					return 0, errDecode
				}
				 = [:]
				.Append(protoreflect.ValueOfInt32(int32()))
			}
			return , nil
		}
		if  != protowire.VarintType {
			return 0, errUnknown
		}
		,  := protowire.ConsumeVarint()
		if  < 0 {
			return 0, errDecode
		}
		.Append(protoreflect.ValueOfInt32(int32()))
		return , nil
	case protoreflect.Sint32Kind:
		if  == protowire.BytesType {
			,  := protowire.ConsumeBytes()
			if  < 0 {
				return 0, errDecode
			}
			for len() > 0 {
				,  := protowire.ConsumeVarint()
				if  < 0 {
					return 0, errDecode
				}
				 = [:]
				.Append(protoreflect.ValueOfInt32(int32(protowire.DecodeZigZag( & math.MaxUint32))))
			}
			return , nil
		}
		if  != protowire.VarintType {
			return 0, errUnknown
		}
		,  := protowire.ConsumeVarint()
		if  < 0 {
			return 0, errDecode
		}
		.Append(protoreflect.ValueOfInt32(int32(protowire.DecodeZigZag( & math.MaxUint32))))
		return , nil
	case protoreflect.Uint32Kind:
		if  == protowire.BytesType {
			,  := protowire.ConsumeBytes()
			if  < 0 {
				return 0, errDecode
			}
			for len() > 0 {
				,  := protowire.ConsumeVarint()
				if  < 0 {
					return 0, errDecode
				}
				 = [:]
				.Append(protoreflect.ValueOfUint32(uint32()))
			}
			return , nil
		}
		if  != protowire.VarintType {
			return 0, errUnknown
		}
		,  := protowire.ConsumeVarint()
		if  < 0 {
			return 0, errDecode
		}
		.Append(protoreflect.ValueOfUint32(uint32()))
		return , nil
	case protoreflect.Int64Kind:
		if  == protowire.BytesType {
			,  := protowire.ConsumeBytes()
			if  < 0 {
				return 0, errDecode
			}
			for len() > 0 {
				,  := protowire.ConsumeVarint()
				if  < 0 {
					return 0, errDecode
				}
				 = [:]
				.Append(protoreflect.ValueOfInt64(int64()))
			}
			return , nil
		}
		if  != protowire.VarintType {
			return 0, errUnknown
		}
		,  := protowire.ConsumeVarint()
		if  < 0 {
			return 0, errDecode
		}
		.Append(protoreflect.ValueOfInt64(int64()))
		return , nil
	case protoreflect.Sint64Kind:
		if  == protowire.BytesType {
			,  := protowire.ConsumeBytes()
			if  < 0 {
				return 0, errDecode
			}
			for len() > 0 {
				,  := protowire.ConsumeVarint()
				if  < 0 {
					return 0, errDecode
				}
				 = [:]
				.Append(protoreflect.ValueOfInt64(protowire.DecodeZigZag()))
			}
			return , nil
		}
		if  != protowire.VarintType {
			return 0, errUnknown
		}
		,  := protowire.ConsumeVarint()
		if  < 0 {
			return 0, errDecode
		}
		.Append(protoreflect.ValueOfInt64(protowire.DecodeZigZag()))
		return , nil
	case protoreflect.Uint64Kind:
		if  == protowire.BytesType {
			,  := protowire.ConsumeBytes()
			if  < 0 {
				return 0, errDecode
			}
			for len() > 0 {
				,  := protowire.ConsumeVarint()
				if  < 0 {
					return 0, errDecode
				}
				 = [:]
				.Append(protoreflect.ValueOfUint64())
			}
			return , nil
		}
		if  != protowire.VarintType {
			return 0, errUnknown
		}
		,  := protowire.ConsumeVarint()
		if  < 0 {
			return 0, errDecode
		}
		.Append(protoreflect.ValueOfUint64())
		return , nil
	case protoreflect.Sfixed32Kind:
		if  == protowire.BytesType {
			,  := protowire.ConsumeBytes()
			if  < 0 {
				return 0, errDecode
			}
			for len() > 0 {
				,  := protowire.ConsumeFixed32()
				if  < 0 {
					return 0, errDecode
				}
				 = [:]
				.Append(protoreflect.ValueOfInt32(int32()))
			}
			return , nil
		}
		if  != protowire.Fixed32Type {
			return 0, errUnknown
		}
		,  := protowire.ConsumeFixed32()
		if  < 0 {
			return 0, errDecode
		}
		.Append(protoreflect.ValueOfInt32(int32()))
		return , nil
	case protoreflect.Fixed32Kind:
		if  == protowire.BytesType {
			,  := protowire.ConsumeBytes()
			if  < 0 {
				return 0, errDecode
			}
			for len() > 0 {
				,  := protowire.ConsumeFixed32()
				if  < 0 {
					return 0, errDecode
				}
				 = [:]
				.Append(protoreflect.ValueOfUint32(uint32()))
			}
			return , nil
		}
		if  != protowire.Fixed32Type {
			return 0, errUnknown
		}
		,  := protowire.ConsumeFixed32()
		if  < 0 {
			return 0, errDecode
		}
		.Append(protoreflect.ValueOfUint32(uint32()))
		return , nil
	case protoreflect.FloatKind:
		if  == protowire.BytesType {
			,  := protowire.ConsumeBytes()
			if  < 0 {
				return 0, errDecode
			}
			for len() > 0 {
				,  := protowire.ConsumeFixed32()
				if  < 0 {
					return 0, errDecode
				}
				 = [:]
				.Append(protoreflect.ValueOfFloat32(math.Float32frombits(uint32())))
			}
			return , nil
		}
		if  != protowire.Fixed32Type {
			return 0, errUnknown
		}
		,  := protowire.ConsumeFixed32()
		if  < 0 {
			return 0, errDecode
		}
		.Append(protoreflect.ValueOfFloat32(math.Float32frombits(uint32())))
		return , nil
	case protoreflect.Sfixed64Kind:
		if  == protowire.BytesType {
			,  := protowire.ConsumeBytes()
			if  < 0 {
				return 0, errDecode
			}
			for len() > 0 {
				,  := protowire.ConsumeFixed64()
				if  < 0 {
					return 0, errDecode
				}
				 = [:]
				.Append(protoreflect.ValueOfInt64(int64()))
			}
			return , nil
		}
		if  != protowire.Fixed64Type {
			return 0, errUnknown
		}
		,  := protowire.ConsumeFixed64()
		if  < 0 {
			return 0, errDecode
		}
		.Append(protoreflect.ValueOfInt64(int64()))
		return , nil
	case protoreflect.Fixed64Kind:
		if  == protowire.BytesType {
			,  := protowire.ConsumeBytes()
			if  < 0 {
				return 0, errDecode
			}
			for len() > 0 {
				,  := protowire.ConsumeFixed64()
				if  < 0 {
					return 0, errDecode
				}
				 = [:]
				.Append(protoreflect.ValueOfUint64())
			}
			return , nil
		}
		if  != protowire.Fixed64Type {
			return 0, errUnknown
		}
		,  := protowire.ConsumeFixed64()
		if  < 0 {
			return 0, errDecode
		}
		.Append(protoreflect.ValueOfUint64())
		return , nil
	case protoreflect.DoubleKind:
		if  == protowire.BytesType {
			,  := protowire.ConsumeBytes()
			if  < 0 {
				return 0, errDecode
			}
			for len() > 0 {
				,  := protowire.ConsumeFixed64()
				if  < 0 {
					return 0, errDecode
				}
				 = [:]
				.Append(protoreflect.ValueOfFloat64(math.Float64frombits()))
			}
			return , nil
		}
		if  != protowire.Fixed64Type {
			return 0, errUnknown
		}
		,  := protowire.ConsumeFixed64()
		if  < 0 {
			return 0, errDecode
		}
		.Append(protoreflect.ValueOfFloat64(math.Float64frombits()))
		return , nil
	case protoreflect.StringKind:
		if  != protowire.BytesType {
			return 0, errUnknown
		}
		,  := protowire.ConsumeBytes()
		if  < 0 {
			return 0, errDecode
		}
		if strs.EnforceUTF8() && !utf8.Valid() {
			return 0, errors.InvalidUTF8(string(.FullName()))
		}
		.Append(protoreflect.ValueOfString(string()))
		return , nil
	case protoreflect.BytesKind:
		if  != protowire.BytesType {
			return 0, errUnknown
		}
		,  := protowire.ConsumeBytes()
		if  < 0 {
			return 0, errDecode
		}
		.Append(protoreflect.ValueOfBytes(append(emptyBuf[:], ...)))
		return , nil
	case protoreflect.MessageKind:
		if  != protowire.BytesType {
			return 0, errUnknown
		}
		,  := protowire.ConsumeBytes()
		if  < 0 {
			return 0, errDecode
		}
		 := .NewElement()
		if  := .unmarshalMessage(, .Message());  != nil {
			return 0, 
		}
		.Append()
		return , nil
	case protoreflect.GroupKind:
		if  != protowire.StartGroupType {
			return 0, errUnknown
		}
		,  := protowire.ConsumeGroup(.Number(), )
		if  < 0 {
			return 0, errDecode
		}
		 := .NewElement()
		if  := .unmarshalMessage(, .Message());  != nil {
			return 0, 
		}
		.Append()
		return , nil
	default:
		return 0, errUnknown
	}
}

// We append to an empty array rather than a nil []byte to get non-nil zero-length byte slices.
var emptyBuf [0]byte