util

package
v0.0.0-...-8293206 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Console console
View Source
var ErrNeedPointer = errors.New("p must be a pointer")
View Source
var PtrSize uintptr

Functions

func BinaryToStruct

func BinaryToStruct(p interface{}, bPtr *[]byte)

p must be a pointer to a struct. set p to whatever bPtr holds. it's a little bit slower than ToStruct.

func ByteToString

func ByteToString(b byte) string

func BytesToString

func BytesToString(p interface{}) string

p is a pointer to a byte array,not a slice.

func ErrorCatch

func ErrorCatch(err error)

func Expect

func Expect(p1, p2 interface{})

func FreeAllocator

func FreeAllocator(a *Allocator)

func GetAddr

func GetAddr(p interface{}) uintptr

Get any address of received arg p.

func GetMD5

func GetMD5(b []byte) []byte

func GetMD5String

func GetMD5String(b []byte) string

func GetSize

func GetSize(p interface{}) int

GetSize uses reflect,will be a little slow,but it is safe. panic when arg p is not a pointer to a struct.

func IPV4AddrToByte

func IPV4AddrToByte(addr string, bPtr *[]byte)

func LogTrace

func LogTrace(b []byte)

func SetBytes

func SetBytes(p interface{}, offset int, new []byte)

SetBytes set data from address of p to address + len(new) to data new holds.

func SizeOf

func SizeOf(p interface{}) int

SizeOf is much faster,get underlying size. p shoule be a value of a struct to get the size of a struct instance.

func SprintfAddress

func SprintfAddress(addr string, port int) string

func StringToByte

func StringToByte(s string, b *byte)

convert only byte. 5 = 5 * 10 ^ 0 61 = 6 * 10 ^ 1 + 1 * 10 ^ 0 121 = 1 * 10 ^ 2 + 2 * 10 ^ 1 + 1 * 10 ^ 0

func StructToBinary

func StructToBinary(p interface{}) *[]byte

p must be a pointer to a struct StructToBinary() will return a pointer to byte slice p covers in the memory. return a pointer to a byte slice whose undelying pointer to point to p and size is real size of p. so it is safe. The underlying byte slice is a struct,so the data of slice field in a struct is not correct.

func ToBinary

func ToBinary(p interface{}, size int) *[]byte

p must be a pointer to a struct size could be calculated by GetSize() or SizeOf(). ToBinary is much faster,But is not safe. Only use when you can make sure arguments are safe.

func ToStruct

func ToStruct(p interface{}, bPtr *[]byte, size int)

p must be a pointer to a struct. set p to whatever bPtr holds. size to define how many bytes bPtr copys to p. much faster than BinaryToStruct

Types

type Allocator

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

func GetAlloctor

func GetAlloctor(size int) *Allocator

func NewAllocator

func NewAllocator(b []byte) *Allocator

func (*Allocator) Alloc

func (a *Allocator) Alloc(size int)

func (*Allocator) GetByteSize

func (a *Allocator) GetByteSize(size int) []byte

func (*Allocator) GetBytes

func (a *Allocator) GetBytes() []byte

func (*Allocator) GetPointer

func (a *Allocator) GetPointer() unsafe.Pointer

func (*Allocator) GetPointerN

func (a *Allocator) GetPointerN(n int) unsafe.Pointer

func (*Allocator) Shift

func (a *Allocator) Shift(length int) []byte

Jump to

Keyboard shortcuts

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