layout

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2025 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Align

func Align[T any]() int

Size returns T's alignment in bytes.

func Bits

func Bits[T any]() int

Size returns T's size in bits.

func PadSlice

func PadSlice(buf []byte, align int) []byte

PadSlice appends zeros to buf until its length is a multiple of align.

func Padding

func Padding[T Int](v, align T) T

Padding returns RoundUp(v, align) - v.

func RoundDown

func RoundDown[T Int](v, align T) T

RoundDown rounds v down to a power of two.

func RoundUp

func RoundUp[T Int](v, align T) T

RoundDown rounds v up to a power of two.

func Size

func Size[T any]() int

Size returns T's size in bytes.

Types

type Int

type Int interface {
	int | int8 | int16 | int32 | int64 |
		uint | uint8 | uint16 | uint32 | uint64 |
		uintptr
}

Int is any integer type.

type Layout

type Layout struct {
	Size, Align int
}

Layout is the layout of some type.

func Of

func Of[T any]() Layout

Of returns the size and alignment of a given type.

func (Layout) Max

func (l Layout) Max(that Layout) Layout

Max returns a layout whose size and alignment are both as large as the largest among l and that.

Jump to

Keyboard shortcuts

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