$68 GRAYBYTE WORDPRESS FILE MANAGER $60

SERVER : in-mum-web1330.main-hosting.eu #1 SMP Mon Feb 10 22:45:17 UTC 2025
SERVER IP : 88.222.243.38 | ADMIN IP 216.73.216.215
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/opt/go/pkg/mod/google.golang.org/protobuf@v1.30.0/internal/impl/

HOME
Current File : /opt/go/pkg/mod/google.golang.org/protobuf@v1.30.0/internal/impl//codec_extension.go
// Copyright 2019 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 (
	"sync"
	"sync/atomic"

	"google.golang.org/protobuf/encoding/protowire"
	"google.golang.org/protobuf/internal/errors"
	"google.golang.org/protobuf/reflect/protoreflect"
)

type extensionFieldInfo struct {
	wiretag             uint64
	tagsize             int
	unmarshalNeedsValue bool
	funcs               valueCoderFuncs
	validation          validationInfo
}

var legacyExtensionFieldInfoCache sync.Map // map[protoreflect.ExtensionType]*extensionFieldInfo

func getExtensionFieldInfo(xt protoreflect.ExtensionType) *extensionFieldInfo {
	if xi, ok := xt.(*ExtensionInfo); ok {
		xi.lazyInit()
		return xi.info
	}
	return legacyLoadExtensionFieldInfo(xt)
}

// legacyLoadExtensionFieldInfo dynamically loads a *ExtensionInfo for xt.
func legacyLoadExtensionFieldInfo(xt protoreflect.ExtensionType) *extensionFieldInfo {
	if xi, ok := legacyExtensionFieldInfoCache.Load(xt); ok {
		return xi.(*extensionFieldInfo)
	}
	e := makeExtensionFieldInfo(xt.TypeDescriptor())
	if e, ok := legacyMessageTypeCache.LoadOrStore(xt, e); ok {
		return e.(*extensionFieldInfo)
	}
	return e
}

func makeExtensionFieldInfo(xd protoreflect.ExtensionDescriptor) *extensionFieldInfo {
	var wiretag uint64
	if !xd.IsPacked() {
		wiretag = protowire.EncodeTag(xd.Number(), wireTypes[xd.Kind()])
	} else {
		wiretag = protowire.EncodeTag(xd.Number(), protowire.BytesType)
	}
	e := &extensionFieldInfo{
		wiretag: wiretag,
		tagsize: protowire.SizeVarint(wiretag),
		funcs:   encoderFuncsForValue(xd),
	}
	// Does the unmarshal function need a value passed to it?
	// This is true for composite types, where we pass in a message, list, or map to fill in,
	// and for enums, where we pass in a prototype value to specify the concrete enum type.
	switch xd.Kind() {
	case protoreflect.MessageKind, protoreflect.GroupKind, protoreflect.EnumKind:
		e.unmarshalNeedsValue = true
	default:
		if xd.Cardinality() == protoreflect.Repeated {
			e.unmarshalNeedsValue = true
		}
	}
	return e
}

type lazyExtensionValue struct {
	atomicOnce uint32 // atomically set if value is valid
	mu         sync.Mutex
	xi         *extensionFieldInfo
	value      protoreflect.Value
	b          []byte
	fn         func() protoreflect.Value
}

type ExtensionField struct {
	typ protoreflect.ExtensionType

	// value is either the value of GetValue,
	// or a *lazyExtensionValue that then returns the value of GetValue.
	value protoreflect.Value
	lazy  *lazyExtensionValue
}

func (f *ExtensionField) appendLazyBytes(xt protoreflect.ExtensionType, xi *extensionFieldInfo, num protowire.Number, wtyp protowire.Type, b []byte) {
	if f.lazy == nil {
		f.lazy = &lazyExtensionValue{xi: xi}
	}
	f.typ = xt
	f.lazy.xi = xi
	f.lazy.b = protowire.AppendTag(f.lazy.b, num, wtyp)
	f.lazy.b = append(f.lazy.b, b...)
}

func (f *ExtensionField) canLazy(xt protoreflect.ExtensionType) bool {
	if f.typ == nil {
		return true
	}
	if f.typ == xt && f.lazy != nil && atomic.LoadUint32(&f.lazy.atomicOnce) == 0 {
		return true
	}
	return false
}

func (f *ExtensionField) lazyInit() {
	f.lazy.mu.Lock()
	defer f.lazy.mu.Unlock()
	if atomic.LoadUint32(&f.lazy.atomicOnce) == 1 {
		return
	}
	if f.lazy.xi != nil {
		b := f.lazy.b
		val := f.typ.New()
		for len(b) > 0 {
			var tag uint64
			if b[0] < 0x80 {
				tag = uint64(b[0])
				b = b[1:]
			} else if len(b) >= 2 && b[1] < 128 {
				tag = uint64(b[0]&0x7f) + uint64(b[1])<<7
				b = b[2:]
			} else {
				var n int
				tag, n = protowire.ConsumeVarint(b)
				if n < 0 {
					panic(errors.New("bad tag in lazy extension decoding"))
				}
				b = b[n:]
			}
			num := protowire.Number(tag >> 3)
			wtyp := protowire.Type(tag & 7)
			var out unmarshalOutput
			var err error
			val, out, err = f.lazy.xi.funcs.unmarshal(b, val, num, wtyp, lazyUnmarshalOptions)
			if err != nil {
				panic(errors.New("decode failure in lazy extension decoding: %v", err))
			}
			b = b[out.n:]
		}
		f.lazy.value = val
	} else {
		f.lazy.value = f.lazy.fn()
	}
	f.lazy.xi = nil
	f.lazy.fn = nil
	f.lazy.b = nil
	atomic.StoreUint32(&f.lazy.atomicOnce, 1)
}

// Set sets the type and value of the extension field.
// This must not be called concurrently.
func (f *ExtensionField) Set(t protoreflect.ExtensionType, v protoreflect.Value) {
	f.typ = t
	f.value = v
	f.lazy = nil
}

// SetLazy sets the type and a value that is to be lazily evaluated upon first use.
// This must not be called concurrently.
func (f *ExtensionField) SetLazy(t protoreflect.ExtensionType, fn func() protoreflect.Value) {
	f.typ = t
	f.lazy = &lazyExtensionValue{fn: fn}
}

// Value returns the value of the extension field.
// This may be called concurrently.
func (f *ExtensionField) Value() protoreflect.Value {
	if f.lazy != nil {
		if atomic.LoadUint32(&f.lazy.atomicOnce) == 0 {
			f.lazyInit()
		}
		return f.lazy.value
	}
	return f.value
}

// Type returns the type of the extension field.
// This may be called concurrently.
func (f ExtensionField) Type() protoreflect.ExtensionType {
	return f.typ
}

// IsSet returns whether the extension field is set.
// This may be called concurrently.
func (f ExtensionField) IsSet() bool {
	return f.typ != nil
}

// IsLazy reports whether a field is lazily encoded.
// It is exported for testing.
func IsLazy(m protoreflect.Message, fd protoreflect.FieldDescriptor) bool {
	var mi *MessageInfo
	var p pointer
	switch m := m.(type) {
	case *messageState:
		mi = m.messageInfo()
		p = m.pointer()
	case *messageReflectWrapper:
		mi = m.messageInfo()
		p = m.pointer()
	default:
		return false
	}
	xd, ok := fd.(protoreflect.ExtensionTypeDescriptor)
	if !ok {
		return false
	}
	xt := xd.Type()
	ext := mi.extensionMap(p)
	if ext == nil {
		return false
	}
	f, ok := (*ext)[int32(fd.Number())]
	if !ok {
		return false
	}
	return f.typ == xt && f.lazy != nil && atomic.LoadUint32(&f.lazy.atomicOnce) == 0
}

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
25 Jan 2024 4.43 PM
root / root
0555
api_export.go
4.933 KB
25 Jan 2024 4.43 PM
root / root
0444
checkinit.go
3.489 KB
25 Jan 2024 4.43 PM
root / root
0444
codec_extension.go
5.841 KB
25 Jan 2024 4.43 PM
root / root
0444
codec_field.go
24.604 KB
25 Jan 2024 4.43 PM
root / root
0444
codec_gen.go
161.441 KB
25 Jan 2024 4.43 PM
root / root
0444
codec_map.go
10.179 KB
25 Jan 2024 4.43 PM
root / root
0444
codec_map_go111.go
0.722 KB
25 Jan 2024 4.43 PM
root / root
0444
codec_map_go112.go
0.293 KB
25 Jan 2024 4.43 PM
root / root
0444
codec_message.go
7.124 KB
25 Jan 2024 4.43 PM
root / root
0444
codec_messageset.go
3.152 KB
25 Jan 2024 4.43 PM
root / root
0444
codec_reflect.go
5.285 KB
25 Jan 2024 4.43 PM
root / root
0444
codec_tables.go
16.354 KB
25 Jan 2024 4.43 PM
root / root
0444
codec_unsafe.go
0.506 KB
25 Jan 2024 4.43 PM
root / root
0444
convert.go
15.511 KB
25 Jan 2024 4.43 PM
root / root
0444
convert_list.go
3.627 KB
25 Jan 2024 4.43 PM
root / root
0444
convert_map.go
3.029 KB
25 Jan 2024 4.43 PM
root / root
0444
decode.go
7.437 KB
25 Jan 2024 4.43 PM
root / root
0444
encode.go
5.079 KB
25 Jan 2024 4.43 PM
root / root
0444
enum.go
0.58 KB
25 Jan 2024 4.43 PM
root / root
0444
enum_test.go
0.632 KB
25 Jan 2024 4.43 PM
root / root
0444
extension.go
4.61 KB
25 Jan 2024 4.43 PM
root / root
0444
extension_test.go
2.692 KB
25 Jan 2024 4.43 PM
root / root
0444
lazy_test.go
1.553 KB
25 Jan 2024 4.43 PM
root / root
0444
legacy_aberrant_test.go
23.111 KB
25 Jan 2024 4.43 PM
root / root
0444
legacy_enum.go
6.729 KB
25 Jan 2024 4.43 PM
root / root
0444
legacy_export.go
3.13 KB
25 Jan 2024 4.43 PM
root / root
0444
legacy_export_test.go
0.927 KB
25 Jan 2024 4.43 PM
root / root
0444
legacy_extension.go
7.511 KB
25 Jan 2024 4.43 PM
root / root
0444
legacy_file.go
2.51 KB
25 Jan 2024 4.43 PM
root / root
0444
legacy_file_test.go
23.899 KB
25 Jan 2024 4.43 PM
root / root
0444
legacy_message.go
18.484 KB
25 Jan 2024 4.43 PM
root / root
0444
legacy_test.go
25.808 KB
25 Jan 2024 4.43 PM
root / root
0444
merge.go
4.55 KB
25 Jan 2024 4.43 PM
root / root
0444
merge_gen.go
4.531 KB
25 Jan 2024 4.43 PM
root / root
0444
message.go
8.37 KB
25 Jan 2024 4.43 PM
root / root
0444
message_reflect.go
13.597 KB
25 Jan 2024 4.43 PM
root / root
0444
message_reflect_field.go
15.082 KB
25 Jan 2024 4.43 PM
root / root
0444
message_reflect_gen.go
7.813 KB
25 Jan 2024 4.43 PM
root / root
0444
message_reflect_test.go
68.138 KB
25 Jan 2024 4.43 PM
root / root
0444
pointer_reflect.go
6.336 KB
25 Jan 2024 4.43 PM
root / root
0444
pointer_unsafe.go
6.863 KB
25 Jan 2024 4.43 PM
root / root
0444
validate.go
15.125 KB
25 Jan 2024 4.43 PM
root / root
0444
weak.go
1.986 KB
25 Jan 2024 4.43 PM
root / root
0444

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF