Package memstruct

import "github.com/byte-mug/golibs/memstruct"

Overview

Implements orthogonal structures.

// total 22 bytes.
type MyStructure struct {
	Field1 *uint64 // 8 bytes
	Field2 *int16  // 2 bytes
	MyData []byte `bytes:"12"` // 12 bytes.
}

atype := memstruct.MakeAccessType(new(MyStructure))
inst := atype.New()
inst.SetBytes(make([]byte,22))
ms := inst.Value().(*MyStructure)

fmt.Println(*ms.Field1)
fmt.Println(*ms.Field2)
fmt.Println(ms.MyData)

Index

type AccessType

type AccessType interface {
	New() Instance
	Len() int
}

-

func MakeAccessType

func MakeAccessType(i interface{}) AccessType

Supported types:

struct // instance.Value() returns *struct
*int8
*int16
*int32
*int64
*uint8
*uint16
*uint32
*uint64
[]byte // only as struct-field with `bytes:"..."` tag.

type Instance

type Instance interface {
	Value() interface{}
	SetBytes([]byte)
}

-

Dependencies