photon

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2024 License: MIT Imports: 3 Imported by: 2 modules, 7 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

photon

Encoding data structures to byte slice in go using C union-like concept.

This is not enforced by the library, due to performance, but you should never ever try to use it with structures containing pointers, slices or strings.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromBytes added in v0.5.0

func FromBytes[T comparable](b []byte) *T

FromBytes converts byte slice to *T.

func FromPointer added in v0.6.0

func FromPointer[T comparable](p unsafe.Pointer) *T

FromPointer converts pointer to byte slice to *T.

func SliceFromBytes added in v0.5.0

func SliceFromBytes[T comparable](b []byte, n int) []T

SliceFromBytes converts byte slice to slice of type T.

func SliceFromPointer added in v0.6.0

func SliceFromPointer[T comparable](p unsafe.Pointer, n int) []T

SliceFromPointer converts pointer to byte slice to slice of type T.

Types

type Union

type Union[T any] struct {
	B []byte
	V T
}

Union represents a C-like union between bytes and structure.

func NewFromBytes

func NewFromBytes[T comparable](b []byte) Union[*T]

NewFromBytes creates union from bytes.

func NewFromReader

func NewFromReader[T comparable](r io.Reader) (Union[*T], error)

NewFromReader creates union from bytes read from the reader.

func NewFromSlice added in v0.4.0

func NewFromSlice[T comparable](v []T) Union[[]T]

NewFromSlice creates union from slice.

func NewFromValue

func NewFromValue[T comparable](v *T) Union[*T]

NewFromValue creates union from value.

func NewSliceFromBytes added in v0.4.0

func NewSliceFromBytes[T comparable](b []byte, n int) Union[[]T]

NewSliceFromBytes creates union containing slice from bytes.

func NewSliceFromReader added in v0.4.0

func NewSliceFromReader[T comparable](r io.Reader, n int) (Union[[]T], error)

NewSliceFromReader creates union containing slice from bytes read from the reader.

Jump to

Keyboard shortcuts

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