sysenc

package
v0.0.0-...-dbf5832 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package sysenc provides efficient conversion of Go values to system call interfaces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Unmarshal

func Unmarshal(data interface{}, buf []byte) error

Unmarshal a byte slice in the system's native endianness into data.

Returns an error if buf can't be unmarshalled according to the behaviour of binary.Read.

Types

type Buffer

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

func Marshal

func Marshal(data any, size int) (Buffer, error)

Marshal turns data into a byte slice using the system's native endianness.

If possible, avoids allocations by directly using the backing memory of data. This means that the variable must not be modified for the lifetime of the returned Buffer.

Returns an error if the data can't be turned into a byte slice according to the behaviour of binary.Write.

func SyscallOutput

func SyscallOutput(dst any, size int) Buffer

SyscallOutput prepares a Buffer for a syscall to write into.

The buffer may point at the underlying memory of dst, in which case Unmarshal becomes a no-op.

The contents of the buffer are undefined and may be non-zero.

func UnsafeBuffer

func UnsafeBuffer(ptr unsafe.Pointer) Buffer

UnsafeBuffer constructs a Buffer for zero-copy unmarshaling.

[Pointer] is the only valid method to call on such a Buffer. Use [SyscallBuffer] instead if possible.

func (Buffer) CopyTo

func (b Buffer) CopyTo(dst []byte) int

CopyTo copies the buffer into dst.

Returns the number of copied bytes.

func (Buffer) Pointer

func (b Buffer) Pointer() sys.Pointer

Pointer returns the location where a syscall should write.

func (Buffer) Unmarshal

func (b Buffer) Unmarshal(data any) error

Unmarshal the buffer into the provided value.

Jump to

Keyboard shortcuts

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