unsafekit

package
v0.0.0-...-05bc493 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const BigEndian = false // unfortunately, sys.BigEndian is inaccessible
View Source
const PtrSize = 4 << (^uintptr(0) >> 63) // unsafe.Sizeof(uintptr(0)) but an ideal const

Variables

This section is empty.

Functions

func Hash

func Hash(v longbits.ByteString, h hash.Hash) hash.Hash

func IsCompatibleMemoryModel

func IsCompatibleMemoryModel(v MemoryModelSupported) bool

func KeepAliveWhile

func KeepAliveWhile(p unsafe.Pointer, fn func(unsafe.Pointer) uintptr) uintptr

func UnwrapAs

func UnwrapAs(v longbits.ByteString, mt MMapType) interface{}

func UnwrapAsGlobalRef

func UnwrapAsGlobalRef(s longbits.ByteString) *reference.Global

WARNING! This function has different guarantees based on (s) origin:

  1. When (s) is made by wrapping another type - it satisfies Unsafe Rule (1) Conversion of a *T1 to Pointer to *T2. You are safe.
  1. When (s) is made by wrapping []byte or string - it violates Unsafe Rule (6) Conversion of SliceHeader/StringHeader And YOU MUST make sure that the origin stays alive while the result is in use.

func UnwrapAsLocalRef

func UnwrapAsLocalRef(s longbits.ByteString) *reference.Local

WARNING! This function has different guarantees based on (s) origin:

  1. When (s) is made by wrapping another type - it satisfies Unsafe Rule (1) Conversion of a *T1 to Pointer to *T2. You are safe.
  1. When (s) is made by wrapping []byte or string - it violates Unsafe Rule (6) Conversion of SliceHeader/StringHeader And YOU MUST make sure that the origin stays alive while the result is in use.

func UnwrapAsSliceOf

func UnwrapAsSliceOf(s longbits.ByteString, mt MMapSliceType) interface{}

func WrapBytes

func WrapBytes(b []byte) longbits.ByteString

WARNING! The given array MUST be immutable WARNING! This method violates unsafe pointer-conversion rules. You MUST make sure that (b) stays alive while the resulting ByteString is in use.

func WrapGlobalRef

func WrapGlobalRef(v *reference.Global) (r longbits.ByteString)

WARNING! You MUST make sure that (v) stays alive while the resulting longbits.ByteString is in use.

func WrapLocalRef

func WrapLocalRef(v *reference.Local) (r longbits.ByteString)

WARNING! You MUST make sure that (v) stays alive while the resulting longbits.ByteString is in use.

func WrapOf

func WrapOf(v interface{}, mt MMapType) longbits.ByteString

func WrapSlice

func WrapSlice(v interface{}) longbits.ByteString

WARNING! The given struct MUST be immutable. Expects struct ptr. WARNING! This method violates unsafe pointer-conversion rules. You MUST make sure that (v) stays alive while the resulting ByteString is in use.

func WrapSliceOf

func WrapSliceOf(v interface{}, mt MMapSliceType) longbits.ByteString

func WrapStruct

func WrapStruct(v interface{}) longbits.ByteString

Expects struct ptr. WARNING! This method violates unsafe pointer-conversion rules. You MUST make sure that (v) stays alive while the resulting ByteString is in use.

func WrapValueStruct

func WrapValueStruct(v interface{}) longbits.ByteString

Expects struct value. Reuses the value. WARNING! Further unwraps MUST NOT modify the content. WARNING! This method violates unsafe pointer-conversion rules. You MUST make sure that (v) stays alive while the resulting ByteString is in use.

func WriteTo

func WriteTo(v longbits.ByteString, w io.Writer) (n int64, err error)

Types

type KeepAliveList

type KeepAliveList struct {
	// contains filtered or unexported fields
}

func (*KeepAliveList) Keep

func (p *KeepAliveList) Keep(v interface{})

func (*KeepAliveList) KeepDataOf

func (p *KeepAliveList) KeepDataOf(v longbits.ByteString)

func (*KeepAliveList) KeepDataOfBytes

func (p *KeepAliveList) KeepDataOfBytes(v []byte)

func (*KeepAliveList) Reset

func (p *KeepAliveList) Reset()

type MMType

type MMType interface {
	ReflectType() reflect.Type
	MemoryModelIndependent() bool
}

type MMapSliceType

type MMapSliceType struct {
	// contains filtered or unexported fields
}

func MustMMapSliceType

func MustMMapSliceType(t reflect.Type, mustBeIndependent bool) MMapSliceType

func NewMMapSliceType

func NewMMapSliceType(t reflect.Type) (MMapSliceType, bool)

func (MMapSliceType) Elem

func (v MMapSliceType) Elem() MMapType

func (MMapSliceType) ElemReflectType

func (v MMapSliceType) ElemReflectType() reflect.Type

func (MMapSliceType) IsZero

func (v MMapSliceType) IsZero() bool

func (MMapSliceType) MemoryModelIndependent

func (v MMapSliceType) MemoryModelIndependent() bool

func (MMapSliceType) ReflectType

func (v MMapSliceType) ReflectType() reflect.Type

func (MMapSliceType) Unwrap

func (v MMapSliceType) Unwrap(s longbits.ByteString) interface{}

type MMapType

type MMapType struct {
	// contains filtered or unexported fields
}

func MustMMapType

func MustMMapType(t reflect.Type, mustBeIndependent bool) MMapType

func NewMMapType

func NewMMapType(t reflect.Type) (MMapType, bool)

func (MMapType) IsZero

func (v MMapType) IsZero() bool

func (MMapType) MemoryModelIndependent

func (v MMapType) MemoryModelIndependent() bool

func (MMapType) ReflectType

func (v MMapType) ReflectType() reflect.Type

func (MMapType) Size

func (v MMapType) Size() int

func (MMapType) SliceOf

func (v MMapType) SliceOf() MMapSliceType

func (MMapType) Unwrap

func (v MMapType) Unwrap(s longbits.ByteString) interface{}

type MemoryMapModel

type MemoryMapModel uint8
const (
	MemoryMapIncompatible MemoryMapModel = iota
	MemoryModelDepended
	MemoryModelIndependent
)

func MemoryModelDependencyOf

func MemoryModelDependencyOf(t reflect.Type) MemoryMapModel

type MemoryModelSupported

type MemoryModelSupported uint8
const (
	LittleEndianSupported MemoryModelSupported
	BigEndianSupported
	EndianIndependent // LittleEndianSupported | BigEndianSupported
)

type Unwrapper

type Unwrapper interface {
	Unwrap(longbits.ByteString) interface{}
	MemoryModelIndependent() bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL