Source File
value_unsafe.go
Belonging Package
google.golang.org/protobuf/reflect/protoreflect
// Copyright 2018 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 protoreflectimport ()type (ifaceHeader struct {_ [0]any // if interfaces have greater alignment than unsafe.Pointer, this will enforce it.Type unsafe.PointerData unsafe.Pointer})var (nilType = typeOf(nil)boolType = typeOf(*new(bool))int32Type = typeOf(*new(int32))int64Type = typeOf(*new(int64))uint32Type = typeOf(*new(uint32))uint64Type = typeOf(*new(uint64))float32Type = typeOf(*new(float32))float64Type = typeOf(*new(float64))stringType = typeOf(*new(string))bytesType = typeOf(*new([]byte))enumType = typeOf(*new(EnumNumber)))// typeOf returns a pointer to the Go type information.// The pointer is comparable and equal if and only if the types are identical.func ( any) unsafe.Pointer {return (*ifaceHeader)(unsafe.Pointer(&)).Type}// value is a union where only one type can be represented at a time.// The struct is 24B large on 64-bit systems and requires the minimum storage// necessary to represent each possible type.//// The Go GC needs to be able to scan variables containing pointers.// As such, pointers and non-pointers cannot be intermixed.type value struct {pragma.DoNotCompare // 0B// typ stores the type of the value as a pointer to the Go type.typ unsafe.Pointer // 8B// ptr stores the data pointer for a String, Bytes, or interface value.ptr unsafe.Pointer // 8B// num stores a Bool, Int32, Int64, Uint32, Uint64, Float32, Float64, or// Enum value as a raw uint64.//// It is also used to store the length of a String or Bytes value;// the capacity is ignored.num uint64 // 8B}func ( string) Value {return Value{typ: stringType, ptr: unsafe.Pointer(unsafe.StringData()), num: uint64(len())}}func ( []byte) Value {return Value{typ: bytesType, ptr: unsafe.Pointer(unsafe.SliceData()), num: uint64(len())}}func ( any) Value {:= (*ifaceHeader)(unsafe.Pointer(&))return Value{typ: .Type, ptr: .Data}}func ( Value) () string {return unsafe.String((*byte)(.ptr), .num)}func ( Value) () []byte {return unsafe.Slice((*byte)(.ptr), .num)}func ( Value) () ( any) {*(*ifaceHeader)(unsafe.Pointer(&)) = ifaceHeader{Type: .typ, Data: .ptr}return}
The pages are generated with Golds v0.7.6. (GOOS=linux GOARCH=amd64)