json

package module
v0.0.0-...-ac5b162 Latest Latest
Warning

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

Go to latest
Published: May 10, 2023 License: MIT Imports: 15 Imported by: 0

README

当前存在的问题:

  1. pointer、slice 的 cache 的 tag 的名字相同的的时候,会有冲突
  2. slice 套 slice,pointer slice

Documentation

Index

Constants

View Source
const SPoolN = 1024 // * 1024

Variables

This section is empty.

Functions

func BatchGet

func BatchGet[T any](b *Batch[T]) *T

func ErrStream

func ErrStream(stream string) string

func GrowBytes

func GrowBytes(in []byte, need int) []byte

func GrowInts

func GrowInts(in []int) []int

func GrowObjs

func GrowObjs(in []uint8, need int, goType *GoType) []uint8

func GrowPointers

func GrowPointers(in []string, need int) []string

func GrowStrings

func GrowStrings(in []string, need int) []string

func Marshal

func Marshal(in interface{}) (bs []byte, err error)

Marshal []byte

func Unmarshal

func Unmarshal(bsIn []byte, in interface{}) (err error)

Unmarshal 转成struct

func UnmarshalString

func UnmarshalString(bs string, in interface{}) (err error)

UnmarshalString Unmarshal string

Types

type Batch

type Batch[T any] struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewBatch

func NewBatch[T any]() *Batch[T]

func (*Batch[T]) Get

func (b *Batch[T]) Get() *T

func (*Batch[T]) GetN

func (b *Batch[T]) GetN(n int) *T

func (*Batch[T]) Make

func (b *Batch[T]) Make() (p *T)

func (*Batch[T]) MakeN

func (b *Batch[T]) MakeN(n int) (p *T)

type BatchObj

type BatchObj struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewBatchObj

func NewBatchObj(typ reflect.Type) *BatchObj

func (*BatchObj) Get

func (b *BatchObj) Get() unsafe.Pointer

func (*BatchObj) GetN

func (b *BatchObj) GetN(n int) unsafe.Pointer

func (*BatchObj) Make

func (b *BatchObj) Make() unsafe.Pointer

func (*BatchObj) MakeN

func (b *BatchObj) MakeN(n int) (p unsafe.Pointer)

type GoEface

type GoEface struct {
	Type  *GoType
	Value unsafe.Pointer
}

func UnpackEface

func UnpackEface(v interface{}) GoEface

type GoIface

type GoIface struct {
	Itab  *GoItab
	Value unsafe.Pointer
}

type GoItab

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

type GoPtrType

type GoPtrType struct {
	GoType
	Elem *GoType
}

type GoType

type GoType struct {
	Size       uintptr
	PtrData    uintptr
	Hash       uint32
	Flags      uint8
	Align      uint8
	FieldAlign uint8
	KindFlags  uint8
	Traits     unsafe.Pointer
	GCData     *byte
	Str        int32
	PtrToSelf  int32
}

func PtrElem

func PtrElem(t *GoType) *GoType

func UnpackNonEface

func UnpackNonEface(p unsafe.Pointer) *GoType

func UnpackType

func UnpackType(t reflect.Type) *GoType

type PoolStore

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

func (PoolStore) GetInts

func (ps PoolStore) GetInts() []int

func (PoolStore) GetNoscan

func (ps PoolStore) GetNoscan() []byte

func (PoolStore) GetObjs

func (ps PoolStore) GetObjs(goType *GoType) []uint8

func (PoolStore) GetPointers

func (ps PoolStore) GetPointers() []string

func (PoolStore) GetStrings

func (ps PoolStore) GetStrings() []string

func (PoolStore) Idx

func (ps PoolStore) Idx(idx uintptr) (p unsafe.Pointer)

func (PoolStore) SetInts

func (ps PoolStore) SetInts(strs []int)

func (PoolStore) SetNoscan

func (ps PoolStore) SetNoscan(pool []byte)

func (PoolStore) SetObjs

func (ps PoolStore) SetObjs(in []uint8) PoolStore

func (PoolStore) SetPointers

func (ps PoolStore) SetPointers(strs []string)

func (PoolStore) SetStrings

func (ps PoolStore) SetStrings(strs []string)

type RCU

type RCU[T uintptr | uint32 | string | int, V any] struct {
	// contains filtered or unexported fields
}

RCU 依据 Read Copy Update 原理实现

func NewRCU

func NewRCU[T uintptr | uint32 | string | int, V any]() (c RCU[T, V])

func (*RCU[T, V]) Get

func (c *RCU[T, V]) Get(key T) (v V, ok bool)

func (*RCU[T, V]) GetOrSet

func (c *RCU[T, V]) GetOrSet(key T, load func() (v V)) (v V)

func (*RCU[T, V]) Set

func (c *RCU[T, V]) Set(key T, v V)

type SliceHeader

type SliceHeader struct {
	Data unsafe.Pointer
	Len  int
	Cap  int
}

type Store

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

type StringHeader

type StringHeader struct {
	Data unsafe.Pointer
	Len  int
}

type TagInfo

type TagInfo struct {
	TagName      string       //
	BaseType     reflect.Type //
	BaseKind     reflect.Kind // 次成员可能是 **string,[]int 等这种复杂类型,这个 用来指示 "最里层" 的类型
	Offset       uintptr      //偏移量
	TypeSize     int          //
	StringTag    bool         // `json:"field,string"`: 此情形下,需要把struct的int转成json的string
	OmitemptyTag bool         //  `json:"some_field,omitempty"`

	/*
		ChildList: 遍历 map 性能较差,加个 list
	*/
	Children  map[string]*TagInfo
	ChildList []*TagInfo // 遍历的顺序和速度

	SPool  sync.Pool // TODO:slice pool 和 store.pool 放在一起吧,通过 id 来获取获取 pool,并把剩余的”垃圾“放回 sync.Pool 中共下次复用
	SPoolN int32
	// contains filtered or unexported fields
}

TagInfo 拥有tag的struct的成员的解析结果

func LoadTagNode

func LoadTagNode(v reflect.Value, hash uint32) (*TagInfo, error)

func LoadTagNodeSlow

func LoadTagNodeSlow(v reflect.Value, hash uint32) (*TagInfo, error)

func NewStructTagInfo

func NewStructTagInfo(typIn reflect.Type, ancestors []ancestor) (ti *TagInfo, err error)

NewStructTagInfo 解析struct的tag字段,并返回解析的结果

每个 struct 都搞一个 pointerCacheType,在使用的时候直接获取; 再搞一个 slicePool 在是 slice 时使用;
二者不会同一时刻出现,是不是可以合并为同一个值?

func (*TagInfo) AddChild

func (t *TagInfo) AddChild(c *TagInfo) (err error)

func (*TagInfo) GetChildFromMap

func (t *TagInfo) GetChildFromMap(key string) *TagInfo

type TypeBuilder

type TypeBuilder struct {
	Type reflect.Type
	// contains filtered or unexported fields
}

构造器

func NewTypeBuilder

func NewTypeBuilder() *TypeBuilder

func (*TypeBuilder) AddBool

func (b *TypeBuilder) AddBool(name string) *TypeBuilder

func (*TypeBuilder) AddField

func (b *TypeBuilder) AddField(field string, typ reflect.Type) *TypeBuilder

添加字段

func (*TypeBuilder) AddFloat64

func (b *TypeBuilder) AddFloat64(name string) *TypeBuilder

func (*TypeBuilder) AddInt64

func (b *TypeBuilder) AddInt64(name string) *TypeBuilder

func (*TypeBuilder) AddString

func (b *TypeBuilder) AddString(name string) *TypeBuilder

func (*TypeBuilder) AppendBool

func (b *TypeBuilder) AppendBool(name string, lazyOffset *uintptr) *TypeBuilder

func (*TypeBuilder) AppendField

func (b *TypeBuilder) AppendField(name string, typ reflect.Type, lazyOffset *uintptr) *TypeBuilder

func (*TypeBuilder) AppendFloat64

func (b *TypeBuilder) AppendFloat64(name string, lazyOffset *uintptr) *TypeBuilder

func (*TypeBuilder) AppendInt64

func (b *TypeBuilder) AppendInt64(name string, lazyOffset *uintptr) *TypeBuilder

func (*TypeBuilder) AppendIntSlice

func (b *TypeBuilder) AppendIntSlice(name string, lazyOffset *uintptr) *TypeBuilder

func (*TypeBuilder) AppendPointer

func (b *TypeBuilder) AppendPointer(name string, lazyOffset *uintptr) *TypeBuilder

func (*TypeBuilder) AppendString

func (b *TypeBuilder) AppendString(name string, lazyOffset *uintptr) *TypeBuilder

func (*TypeBuilder) AppendTagField

func (b *TypeBuilder) AppendTagField(typ reflect.Type, lazyOffset *uintptr) *TypeBuilder

针对 slice,要添加一个 [4]type 的空间作为预分配的资源

func (*TypeBuilder) Build

func (b *TypeBuilder) Build() reflect.Type

根据预先添加的字段构建出结构体

func (*TypeBuilder) Init

func (b *TypeBuilder) Init()

Init 调用 Build() 并初始化缓存

func (*TypeBuilder) Interface

func (b *TypeBuilder) Interface() interface{}

func (*TypeBuilder) New

func (b *TypeBuilder) New() unsafe.Pointer

根据预先添加的字段构建出结构体

func (*TypeBuilder) NewFromPool

func (b *TypeBuilder) NewFromPool() unsafe.Pointer

TODO: 此处也可以使用 NewBatch 来提高性能? 提升 10ns ?

func (*TypeBuilder) NewSlice

func (b *TypeBuilder) NewSlice() unsafe.Pointer

根据预先添加的字段构建出结构体

func (*TypeBuilder) PInterface

func (b *TypeBuilder) PInterface() (unsafe.Pointer, interface{})

type Value

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

Jump to

Keyboard shortcuts

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