func trimMessageDescriptor(in []*descriptorpb.DescriptorProto, prefix string, toKeep map[string]struct{}) ([]*descriptorpb.DescriptorProto, error) {
	i := 0
	for _, messageDescriptor := range in {
		name := prefix + messageDescriptor.GetName()
		if _, ok := toKeep[name]; ok {
			trimMessages, err := trimMessageDescriptor(messageDescriptor.NestedType, name+".", toKeep)
			if err != nil {
				return nil, err
			}
			messageDescriptor.NestedType = trimMessages
			trimEnums, err := trimEnumDescriptor(messageDescriptor.EnumType, name+".", toKeep)
			if err != nil {
				return nil, err
			}
			messageDescriptor.EnumType = trimEnums
			trimExtensions, err := trimExtensionDescriptors(messageDescriptor.Extension, name+".", toKeep)
			if err != nil {
				return nil, err
			}
			messageDescriptor.Extension = trimExtensions
			in[i] = messageDescriptor
			i++
		}
	}
	return in[:i], nil
}
// trimMessageDescriptor removes (nested) messages and nested enums from a slice
// of message descriptors if their type names are not found in the toKeep map.
trimMessageDescriptor removes (nested) messages and nested enums from a slice
of message descriptors if their type names are not found in the toKeep map.
// trimMessageDescriptor removes ( nested ) messages and nested enums from a slice // of message descriptors if their type names are not found in the toKeep map .
func trimMessageDescriptor(in []*descriptorpb.DescriptorProto, prefix string, toKeep map[string]struct{}) ([]*descriptorpb.DescriptorProto, error) {
	i := 0
	for _, messageDescriptor := range in {
		name := prefix + messageDescriptor.GetName()
		if _, ok := toKeep[name]; ok {
			trimMessages, err := trimMessageDescriptor(messageDescriptor.NestedType, name+".", toKeep)
			if err != nil {
				return nil, err
			}
			messageDescriptor.NestedType = trimMessages
			trimEnums, err := trimEnumDescriptor(messageDescriptor.EnumType, name+".", toKeep)
			if err != nil {
				return nil, err
			}
			messageDescriptor.EnumType = trimEnums
			trimExtensions, err := trimExtensionDescriptors(messageDescriptor.Extension, name+".", toKeep)
			if err != nil {
				return nil, err
			}
			messageDescriptor.Extension = trimExtensions
			in[i] = messageDescriptor
			i++
		}
	}
	return in[:i], nil
}
func trimMessageDescriptor ( in [ ] * descriptorpb . DescriptorProto , prefix string , toKeep map [ string ] struct { } ) ( [ ] * descriptorpb . DescriptorProto , error ) { i := 0 for _ , messageDescriptor := range in { name := prefix + messageDescriptor . GetName ( ) if _ , ok := toKeep [ name ] ; ok { trimMessages , err := trimMessageDescriptor ( messageDescriptor . NestedType , name + " " , toKeep ) if err != nil { return nil , err } messageDescriptor . NestedType = trimMessages trimEnums , err := trimEnumDescriptor ( messageDescriptor . EnumType , name + " " , toKeep ) if err != nil { return nil , err } messageDescriptor . EnumType = trimEnums trimExtensions , err := trimExtensionDescriptors ( messageDescriptor . Extension , name + " " , toKeep ) if err != nil { return nil , err } messageDescriptor . Extension = trimExtensions in [ i ] = messageDescriptor i ++ } } return in [ : i ] , nil }
trimMessageDescriptor removes (nested) messages and nested enums from a slice
of message descriptors if their type names are not found in the toKeep map.
trimMessageDescriptor removes ( nested ) messages and nested enums from a slice of message descriptors if their type names are not found in the toKeep map .