// Copyright 2016 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 ptypes

import (
	
	

	
	
	

	anypb 
)

const urlPrefix = "type.googleapis.com/"

// AnyMessageName returns the message name contained in an anypb.Any message.
// Most type assertions should use the Is function instead.
//
// Deprecated: Call the any.MessageName method instead.
func ( *anypb.Any) (string, error) {
	,  := anyMessageName()
	return string(), 
}
func ( *anypb.Any) (protoreflect.FullName, error) {
	if  == nil {
		return "", fmt.Errorf("message is nil")
	}
	 := protoreflect.FullName(.TypeUrl)
	if  := strings.LastIndex(.TypeUrl, "/");  >= 0 {
		 = [+len("/"):]
	}
	if !.IsValid() {
		return "", fmt.Errorf("message type url %q is invalid", .TypeUrl)
	}
	return , nil
}

// MarshalAny marshals the given message m into an anypb.Any message.
//
// Deprecated: Call the anypb.New function instead.
func ( proto.Message) (*anypb.Any, error) {
	switch dm := .(type) {
	case DynamicAny:
		 = .Message
	case *DynamicAny:
		if  == nil {
			return nil, proto.ErrNil
		}
		 = .Message
	}
	,  := proto.Marshal()
	if  != nil {
		return nil, 
	}
	return &anypb.Any{TypeUrl: urlPrefix + proto.MessageName(), Value: }, nil
}

// Empty returns a new message of the type specified in an anypb.Any message.
// It returns protoregistry.NotFound if the corresponding message type could not
// be resolved in the global registry.
//
// Deprecated: Use protoregistry.GlobalTypes.FindMessageByName instead
// to resolve the message name and create a new instance of it.
func ( *anypb.Any) (proto.Message, error) {
	,  := anyMessageName()
	if  != nil {
		return nil, 
	}
	,  := protoregistry.GlobalTypes.FindMessageByName()
	if  != nil {
		return nil, 
	}
	return proto.MessageV1(.New().Interface()), nil
}

// UnmarshalAny unmarshals the encoded value contained in the anypb.Any message
// into the provided message m. It returns an error if the target message
// does not match the type in the Any message or if an unmarshal error occurs.
//
// The target message m may be a *DynamicAny message. If the underlying message
// type could not be resolved, then this returns protoregistry.NotFound.
//
// Deprecated: Call the any.UnmarshalTo method instead.
func ( *anypb.Any,  proto.Message) error {
	if ,  := .(*DynamicAny);  {
		if .Message == nil {
			var  error
			.Message,  = Empty()
			if  != nil {
				return 
			}
		}
		 = .Message
	}

	,  := AnyMessageName()
	if  != nil {
		return 
	}
	 := proto.MessageName()
	if  !=  {
		return fmt.Errorf("mismatched message type: got %q want %q", , )
	}
	return proto.Unmarshal(.Value, )
}

// Is reports whether the Any message contains a message of the specified type.
//
// Deprecated: Call the any.MessageIs method instead.
func ( *anypb.Any,  proto.Message) bool {
	if  == nil ||  == nil {
		return false
	}
	 := proto.MessageName()
	if !strings.HasSuffix(.TypeUrl, ) {
		return false
	}
	return len(.TypeUrl) == len() || .TypeUrl[len(.TypeUrl)-len()-1] == '/'
}

// DynamicAny is a value that can be passed to UnmarshalAny to automatically
// allocate a proto.Message for the type specified in an anypb.Any message.
// The allocated message is stored in the embedded proto.Message.
//
// Example:
//   var x ptypes.DynamicAny
//   if err := ptypes.UnmarshalAny(a, &x); err != nil { ... }
//   fmt.Printf("unmarshaled message: %v", x.Message)
//
// Deprecated: Use the any.UnmarshalNew method instead to unmarshal
// the any message contents into a new instance of the underlying message.
type DynamicAny struct{ proto.Message }

func ( DynamicAny) () string {
	if .Message == nil {
		return "<nil>"
	}
	return .Message.String()
}
func ( DynamicAny) () {
	if .Message == nil {
		return
	}
	.Message.Reset()
}
func ( DynamicAny) () {
	return
}
func ( DynamicAny) () protoreflect.Message {
	if .Message == nil {
		return nil
	}
	return dynamicAny{proto.MessageReflect(.Message)}
}

type dynamicAny struct{ protoreflect.Message }

func ( dynamicAny) () protoreflect.MessageType {
	return dynamicAnyType{.Message.Type()}
}
func ( dynamicAny) () protoreflect.Message {
	return dynamicAnyType{.Message.Type()}.New()
}
func ( dynamicAny) () protoreflect.ProtoMessage {
	return DynamicAny{proto.MessageV1(.Message.Interface())}
}

type dynamicAnyType struct{ protoreflect.MessageType }

func ( dynamicAnyType) () protoreflect.Message {
	return dynamicAny{.MessageType.New()}
}
func ( dynamicAnyType) () protoreflect.Message {
	return dynamicAny{.MessageType.Zero()}
}