Skip to content

package klib

import "kaiju/klib"

Constants

ISO8601

"2006-01-02T15:04:05Z"

Functions

AppendUnique[T comparable]

func AppendUnique[T comparable](slice []T, values ...T) []T

BinaryRead

func BinaryRead(r io.Reader, data any) error

BinaryReadLen

func BinaryReadLen(r io.Reader) (int32, error)

BinaryReadString

func BinaryReadString(r io.Reader) (string, error)

BinaryReadVar[T any]

func BinaryReadVar[T any](r io.Reader) (T, error)

BinaryReadVarSlice[T any]

func BinaryReadVarSlice[T any](r io.Reader) ([]T, error)

BinaryWrite

func BinaryWrite(w io.Writer, data any) error

BinaryWriteMap[K comparable, V any]

func BinaryWriteMap[K comparable, V any](w io.Writer, data map[K]V) error

BinaryWriteMapLen[K comparable, V any]

func BinaryWriteMapLen[K comparable, V any](w io.Writer, data map[K]V) error

BinaryWriteSlice[T any]

func BinaryWriteSlice[T any](w io.Writer, data []T) error

BinaryWriteSliceLen[T any]

func BinaryWriteSliceLen[T any](w io.Writer, data []T) error

BinaryWriteString

func BinaryWriteString(w io.Writer, str string) error

ByteArrayToString

func ByteArrayToString(byteArray []byte) string

ByteSliceToFloat32Slice

func ByteSliceToFloat32Slice(data []byte) []float32

ByteSliceToUInt16Slice

func ByteSliceToUInt16Slice(data []byte) []uint16

Check

func Check(outError *error, newError error) bool

CheckAll

func CheckAll(res bool)

Clamp[T cmp.Ordered]

func Clamp[T cmp.Ordered](current, minimum, maximum T) T

Contains[T comparable]

func Contains[T comparable](slice []T, item T) bool

ConvertByteSliceType[T any]

func ConvertByteSliceType[T any](slice []byte) []T

Decrypt

func Decrypt(encryptedData []byte, key []byte) ([]byte, error)

DelayCall

func DelayCall(d time.Duration, f func(), ctx context.Context)

Encrypt

func Encrypt(rawData []byte, key []byte) ([]byte, error)

ExeExtension

func ExeExtension() string

FindFirstZeroInByteArray

func FindFirstZeroInByteArray(arr []byte) int

FloatEquals[T Float]

func FloatEquals[T Float](a, b T) bool

InterfaceUnderlyingPointer[T any]

func InterfaceUnderlyingPointer[T any](s T) unsafe.Pointer

JsonDecode[T any]

func JsonDecode[T any](decoder *json.Decoder, container *T) error

MM2PX[T Number]

func MM2PX[T Number](pixels, mm, targetMM T) T

MapKeys[T comparable, U any]

func MapKeys[T comparable, U any](m map[T]U) []T

MapKeysSorted[T cmp.Ordered, U any]

func MapKeysSorted[T cmp.Ordered, U any](m map[T]U) []T

MapValues[T comparable, U any]

func MapValues[T comparable, U any](m map[T]U) []U

Memcpy

func Memcpy(dst unsafe.Pointer, src unsafe.Pointer, size uint64)

Must

func Must(err error)

MustReturn[T any]

func MustReturn[T any](ret T, err error) T

MustReturn2[T, U any]

func MustReturn2[T, U any](ret1 T, ret2 U, err error) (T, U)

NotYetImplemented

func NotYetImplemented(issueId int)

OpenWebsite

func OpenWebsite(url string)

PrintStack

func PrintStack()

ReadRootFile

func ReadRootFile(fs *os.Root, filePath string) ([]byte, error)

RemakeSlice[S any]

func RemakeSlice[S any](s []S) []S

RemoveNils[S any]

func RemoveNils[S any](slice []*S) []*S

RemoveUnordered[T any]

func RemoveUnordered[T any](slice []T, idx int) []T

ReplaceStringRecursive

func ReplaceStringRecursive(s string, old string, new string) string

Should

func Should(err error) bool

ShouldReturn[T any]

func ShouldReturn[T any](ret T, err error) T

Shuffle[T any]

func Shuffle[T any](slice []T, rng *rand.Rand)

ShuffleRandom[T any]

func ShuffleRandom[T any](slice []T)

SizedStructToByteArray

func SizedStructToByteArray(s unsafe.Pointer, size int) []byte

SliceMove[S any]

func SliceMove[S any](s []S, from, to int)

SliceSetCap[S any]

func SliceSetCap[S any](s []S, amount int) []S

SliceSetLen[S any]

func SliceSetLen[S any](s []S, newLen int) []S

SlicesAreTheSame[S comparable]

func SlicesAreTheSame[S comparable](a []S, b []S) bool

SlicesRemoveElement[S comparable]

func SlicesRemoveElement[S comparable](s []S, e S) []S

StringToTypeValue

func StringToTypeValue(typeName, v string) any

StructSliceToByteArray[T any]

func StructSliceToByteArray[T any](s []T) []byte

StructToByteArray[T any]

func StructToByteArray[T any](s T) []byte

TickerWait

func TickerWait(interval, limit time.Duration, condition func() bool) bool

ToUnixPath

func ToUnixPath(path string) string

Trace

func Trace(message string)

TraceString

func TraceString(message string) string

TraceStrings

func TraceStrings(message string, skip int) []string

WipeSlice[S any]

func WipeSlice[S any](s []S) []S

WipeSlice will clear out the slice before returning [:0]. The purpose for this is that if there are pointers held within the slice, they hold their references for as long as they are within the capacity of the slice. Due to this, pointers are not collected by the GC unless actually wiped out from the slice.

WriteRootFile

func WriteRootFile(fs *os.Root, filePath string, data []byte) error

Types

Complex

interface

type Complex interface {
    ~complex64 | ~complex128
}

ErrorList

struct

type ErrorList struct {
    Errors []error
}

NewErrorList

func NewErrorList() ErrorList

ErrorList.AddAny

func (e *ErrorList) AddAny(err error)

ErrorList.Any

func (e *ErrorList) Any() bool

ErrorList.First

func (e *ErrorList) First() error

Float

interface

type Float interface {
    ~float32 | ~float64
}

Integer

interface

type Integer interface {
    Signed | Unsigned
}

Number

interface

type Number interface {
    Integer | Float
}

Ordered

interface

type Ordered interface {
    Integer | Float | ~string
}

Serializable

interface

type Serializable interface {
    Serialize(stream io.Writer)
    Deserialize(stream io.Reader)
}

Signed

interface

type Signed interface {
    ~int | ~int8 | ~int16 | ~int32 | ~int64
}

Unsigned

interface

type Unsigned interface {
    ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}