reflectx

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package reflectx provides reflection-based helpers that extend the standard library reflect package, such as estimating the in-memory payload of a value.

Index

Constants

This section is empty.

Variables

View Source
var ErrFailEstimatePayload = -1

ErrFailEstimatePayload is returned by EstimatePayloadOf when the payload size cannot be determined.

Functions

func EstimatePayloadOf

func EstimatePayloadOf(arg any) int

EstimatePayloadOf returns an approximate payload size (in bytes) of the given value.

This function performs **zero allocations** and runs with **0 B/op**.

Supported types:

  • all scalar types and their pointers: int, int8, int16, int32 (rune), int64, uint, uint8 (byte), uint16, uint32, uint64, uintptr, float32, float64, complex64, complex128, bool, string, time.Time, time.Duration
  • slices of the above types and their pointers: []T, *[]T, []*T, *[]*T
  • arrays [N]T and *[N]T (via reflection)

For pointer and slice values, nil is treated as zero size. For strings and slices of strings, the sum of actual string lengths is returned.

If the type is not recognized or cannot be handled, the function returns ErrFailEstimatePayload.

Performance note:

For arrays [N]T it is highly recommended to pass a pointer (*[N]T)
instead of the array value itself. Passing an array by value causes the
entire array to be copied when calling this function, which can make
estimation dozens or even hundreds of times slower for large arrays.

Types

This section is empty.

Jump to

Keyboard shortcuts

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