// Copyright 2024 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 (
	
	
	

	
)

func (Export) ( any,  int32) {
	UnmarshalField(.(protoreflect.ProtoMessage).ProtoReflect(), protoreflect.FieldNumber())
}

// Present checks the presence set for a certain field number (zero
// based, ordered by appearance in original proto file). part is
// a pointer to the correct element in the bitmask array, num is the
// field number unaltered.  Example (field number 70 -> part =
// &m.XXX_presence[1], num = 70)
func (Export) ( *uint32,  uint32) bool {
	// This hook will read an unprotected shadow presence set if
	// we're unning under the race detector
	raceDetectHookPresent(, )
	return atomic.LoadUint32()&(1<<(%32)) > 0
}

// SetPresent adds a field to the presence set. part is a pointer to
// the relevant element in the array and num is the field number
// unaltered.  size is the number of fields in the protocol
// buffer.
func (Export) ( *uint32,  uint32,  uint32) {
	// This hook will mutate an unprotected shadow presence set if
	// we're running under the race detector
	raceDetectHookSetPresent(, , presenceSize())
	for {
		 := atomic.LoadUint32()
		if atomic.CompareAndSwapUint32(, , |(1<<(%32))) {
			return
		}
	}
}

// SetPresentNonAtomic is like SetPresent, but operates non-atomically.
// It is meant for use by builder methods, where the message is known not
// to be accessible yet by other goroutines.
func (Export) ( *uint32,  uint32,  uint32) {
	// This hook will mutate an unprotected shadow presence set if
	// we're running under the race detector
	raceDetectHookSetPresent(, , presenceSize())
	* |= 1 << ( % 32)
}

// ClearPresence removes a field from the presence set. part is a
// pointer to the relevant element in the presence array and num is
// the field number unaltered.
func (Export) ( *uint32,  uint32) {
	// This hook will mutate an unprotected shadow presence set if
	// we're running under the race detector
	raceDetectHookClearPresent(, )
	for {
		 := atomic.LoadUint32()
		if atomic.CompareAndSwapUint32(, , &^(1<<(%32))) {
			return
		}
	}
}

// interfaceToPointer takes a pointer to an empty interface whose value is a
// pointer type, and converts it into a "pointer" that points to the same
// target
func ( *any) pointer {
	return pointer{p: (*[2]unsafe.Pointer)(unsafe.Pointer())[1]}
}

func ( pointer) () pointer {
	return pointer{p: atomic.LoadPointer((*unsafe.Pointer)(.p))}
}

func ( pointer) ( pointer) {
	atomic.StorePointer((*unsafe.Pointer)(.p), .p)
}

// AtomicCheckPointerIsNil takes an interface (which is a pointer to a
// pointer) and returns true if the pointed-to pointer is nil (using an
// atomic load).  This function is inlineable and, on x86, just becomes a
// simple load and compare.
func (Export) ( any) bool {
	return interfaceToPointer(&).atomicGetPointer().IsNil()
}

// AtomicSetPointer takes two interfaces (first is a pointer to a pointer,
// second is a pointer) and atomically sets the second pointer into location
// referenced by first pointer.  Unfortunately, atomicSetPointer() does not inline
// (even on x86), so this does not become a simple store on x86.
func (Export) (,  any) {
	interfaceToPointer(&).atomicSetPointer(interfaceToPointer(&))
}

// AtomicLoadPointer loads the pointer at the location pointed at by src,
// and stores that pointer value into the location pointed at by dst.
func (Export) ( Pointer,  Pointer) {
	*(*unsafe.Pointer)(unsafe.Pointer()) = atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer()))
}

// AtomicInitializePointer makes ptr and dst point to the same value.
//
// If *ptr is a nil pointer, it sets *ptr = *dst.
//
// If *ptr is a non-nil pointer, it sets *dst = *ptr.
func (Export) ( Pointer,  Pointer) {
	if !atomic.CompareAndSwapPointer((*unsafe.Pointer)(), unsafe.Pointer(nil), *(*unsafe.Pointer)()) {
		*(*unsafe.Pointer)(unsafe.Pointer()) = atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer()))
	}
}

// MessageFieldStringOf returns the field formatted as a string,
// either as the field name if resolvable otherwise as a decimal string.
func (Export) ( protoreflect.MessageDescriptor,  protoreflect.FieldNumber) string {
	 := .Fields().ByNumber()
	if  != nil {
		return string(.Name())
	}
	return strconv.Itoa(int())
}