//go:build vtprotobuf
// +build vtprotobuf

// Code generated by protoc-gen-go-vtproto. DO NOT EDIT.
// source: envoy/extensions/load_balancing_policies/subset/v3/subset.proto

package subsetv3

import (
	protohelpers "github.com/planetscale/vtprotobuf/protohelpers"
	structpb "github.com/planetscale/vtprotobuf/types/known/structpb"
	proto "google.golang.org/protobuf/proto"
	protoimpl "google.golang.org/protobuf/runtime/protoimpl"
)

const (
	// Verify that this generated code is sufficiently up-to-date.
	_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
	// Verify that runtime/protoimpl is sufficiently up-to-date.
	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)

func (m *Subset_LbSubsetSelector) MarshalVTStrict() (dAtA []byte, err error) {
	if m == nil {
		return nil, nil
	}
	size := m.SizeVT()
	dAtA = make([]byte, size)
	n, err := m.MarshalToSizedBufferVTStrict(dAtA[:size])
	if err != nil {
		return nil, err
	}
	return dAtA[:n], nil
}

func (m *Subset_LbSubsetSelector) MarshalToVTStrict(dAtA []byte) (int, error) {
	size := m.SizeVT()
	return m.MarshalToSizedBufferVTStrict(dAtA[:size])
}

func (m *Subset_LbSubsetSelector) MarshalToSizedBufferVTStrict(dAtA []byte) (int, error) {
	if m == nil {
		return 0, nil
	}
	i := len(dAtA)
	_ = i
	var l int
	_ = l
	if m.unknownFields != nil {
		i -= len(m.unknownFields)
		copy(dAtA[i:], m.unknownFields)
	}
	if m.SingleHostPerSubset {
		i--
		if m.SingleHostPerSubset {
			dAtA[i] = 1
		} else {
			dAtA[i] = 0
		}
		i--
		dAtA[i] = 0x20
	}
	if len(m.FallbackKeysSubset) > 0 {
		for iNdEx := len(m.FallbackKeysSubset) - 1; iNdEx >= 0; iNdEx-- {
			i -= len(m.FallbackKeysSubset[iNdEx])
			copy(dAtA[i:], m.FallbackKeysSubset[iNdEx])
			i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.FallbackKeysSubset[iNdEx])))
			i--
			dAtA[i] = 0x1a
		}
	}
	if m.FallbackPolicy != 0 {
		i = protohelpers.EncodeVarint(dAtA, i, uint64(m.FallbackPolicy))
		i--
		dAtA[i] = 0x10
	}
	if len(m.Keys) > 0 {
		for iNdEx := len(m.Keys) - 1; iNdEx >= 0; iNdEx-- {
			i -= len(m.Keys[iNdEx])
			copy(dAtA[i:], m.Keys[iNdEx])
			i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.Keys[iNdEx])))
			i--
			dAtA[i] = 0xa
		}
	}
	return len(dAtA) - i, nil
}

func (m *Subset) MarshalVTStrict() (dAtA []byte, err error) {
	if m == nil {
		return nil, nil
	}
	size := m.SizeVT()
	dAtA = make([]byte, size)
	n, err := m.MarshalToSizedBufferVTStrict(dAtA[:size])
	if err != nil {
		return nil, err
	}
	return dAtA[:n], nil
}

func (m *Subset) MarshalToVTStrict(dAtA []byte) (int, error) {
	size := m.SizeVT()
	return m.MarshalToSizedBufferVTStrict(dAtA[:size])
}

func (m *Subset) MarshalToSizedBufferVTStrict(dAtA []byte) (int, error) {
	if m == nil {
		return 0, nil
	}
	i := len(dAtA)
	_ = i
	var l int
	_ = l
	if m.unknownFields != nil {
		i -= len(m.unknownFields)
		copy(dAtA[i:], m.unknownFields)
	}
	if m.AllowRedundantKeys {
		i--
		if m.AllowRedundantKeys {
			dAtA[i] = 1
		} else {
			dAtA[i] = 0
		}
		i--
		dAtA[i] = 0x50
	}
	if m.SubsetLbPolicy != nil {
		if vtmsg, ok := interface{}(m.SubsetLbPolicy).(interface {
			MarshalToSizedBufferVTStrict([]byte) (int, error)
		}); ok {
			size, err := vtmsg.MarshalToSizedBufferVTStrict(dAtA[:i])
			if err != nil {
				return 0, err
			}
			i -= size
			i = protohelpers.EncodeVarint(dAtA, i, uint64(size))
		} else {
			encoded, err := proto.Marshal(m.SubsetLbPolicy)
			if err != nil {
				return 0, err
			}
			i -= len(encoded)
			copy(dAtA[i:], encoded)
			i = protohelpers.EncodeVarint(dAtA, i, uint64(len(encoded)))
		}
		i--
		dAtA[i] = 0x4a
	}
	if m.MetadataFallbackPolicy != 0 {
		i = protohelpers.EncodeVarint(dAtA, i, uint64(m.MetadataFallbackPolicy))
		i--
		dAtA[i] = 0x40
	}
	if m.ListAsAny {
		i--
		if m.ListAsAny {
			dAtA[i] = 1
		} else {
			dAtA[i] = 0
		}
		i--
		dAtA[i] = 0x38
	}
	if m.PanicModeAny {
		i--
		if m.PanicModeAny {
			dAtA[i] = 1
		} else {
			dAtA[i] = 0
		}
		i--
		dAtA[i] = 0x30
	}
	if m.ScaleLocalityWeight {
		i--
		if m.ScaleLocalityWeight {
			dAtA[i] = 1
		} else {
			dAtA[i] = 0
		}
		i--
		dAtA[i] = 0x28
	}
	if m.LocalityWeightAware {
		i--
		if m.LocalityWeightAware {
			dAtA[i] = 1
		} else {
			dAtA[i] = 0
		}
		i--
		dAtA[i] = 0x20
	}
	if len(m.SubsetSelectors) > 0 {
		for iNdEx := len(m.SubsetSelectors) - 1; iNdEx >= 0; iNdEx-- {
			size, err := m.SubsetSelectors[iNdEx].MarshalToSizedBufferVTStrict(dAtA[:i])
			if err != nil {
				return 0, err
			}
			i -= size
			i = protohelpers.EncodeVarint(dAtA, i, uint64(size))
			i--
			dAtA[i] = 0x1a
		}
	}
	if m.DefaultSubset != nil {
		size, err := (*structpb.Struct)(m.DefaultSubset).MarshalToSizedBufferVTStrict(dAtA[:i])
		if err != nil {
			return 0, err
		}
		i -= size
		i = protohelpers.EncodeVarint(dAtA, i, uint64(size))
		i--
		dAtA[i] = 0x12
	}
	if m.FallbackPolicy != 0 {
		i = protohelpers.EncodeVarint(dAtA, i, uint64(m.FallbackPolicy))
		i--
		dAtA[i] = 0x8
	}
	return len(dAtA) - i, nil
}

func (m *Subset_LbSubsetSelector) SizeVT() (n int) {
	if m == nil {
		return 0
	}
	var l int
	_ = l
	if len(m.Keys) > 0 {
		for _, s := range m.Keys {
			l = len(s)
			n += 1 + l + protohelpers.SizeOfVarint(uint64(l))
		}
	}
	if m.FallbackPolicy != 0 {
		n += 1 + protohelpers.SizeOfVarint(uint64(m.FallbackPolicy))
	}
	if len(m.FallbackKeysSubset) > 0 {
		for _, s := range m.FallbackKeysSubset {
			l = len(s)
			n += 1 + l + protohelpers.SizeOfVarint(uint64(l))
		}
	}
	if m.SingleHostPerSubset {
		n += 2
	}
	n += len(m.unknownFields)
	return n
}

func (m *Subset) SizeVT() (n int) {
	if m == nil {
		return 0
	}
	var l int
	_ = l
	if m.FallbackPolicy != 0 {
		n += 1 + protohelpers.SizeOfVarint(uint64(m.FallbackPolicy))
	}
	if m.DefaultSubset != nil {
		l = (*structpb.Struct)(m.DefaultSubset).SizeVT()
		n += 1 + l + protohelpers.SizeOfVarint(uint64(l))
	}
	if len(m.SubsetSelectors) > 0 {
		for _, e := range m.SubsetSelectors {
			l = e.SizeVT()
			n += 1 + l + protohelpers.SizeOfVarint(uint64(l))
		}
	}
	if m.LocalityWeightAware {
		n += 2
	}
	if m.ScaleLocalityWeight {
		n += 2
	}
	if m.PanicModeAny {
		n += 2
	}
	if m.ListAsAny {
		n += 2
	}
	if m.MetadataFallbackPolicy != 0 {
		n += 1 + protohelpers.SizeOfVarint(uint64(m.MetadataFallbackPolicy))
	}
	if m.SubsetLbPolicy != nil {
		if size, ok := interface{}(m.SubsetLbPolicy).(interface {
			SizeVT() int
		}); ok {
			l = size.SizeVT()
		} else {
			l = proto.Size(m.SubsetLbPolicy)
		}
		n += 1 + l + protohelpers.SizeOfVarint(uint64(l))
	}
	if m.AllowRedundantKeys {
		n += 2
	}
	n += len(m.unknownFields)
	return n
}
