fastconv

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

README

fastconv

English | 中文

最快的 map 和 struct 互转库 🚀🚀🚀

Features

  • Zero GC, Pool & Compress, reducing small objects.
  • All CPU architectures, Not for specific CPU arch.
  • 10 times Faster than json Marshal / Unmarshal.
  • Compatible with json tags.

Benchmarks

Benchmarks.png

Requirements

go 1.21+

Installation

go get github.com/lvan100/fastconv

Examples

src := map / struct / slice
dst := map / struct / slice
fastconv.Convert(src, dst)

Give a Star! ⭐

If you like this project, please give it a star. Thanks!

License

FastConv is Open Source software released under the Apache 2.0 license.

Documentation

Index

Constants

View Source
const (
	Invalid = Kind(iota)
	Nil
	Bool
	Int
	Uint
	Float
	String
	Bools
	Ints
	Int8s
	Int16s
	Int32s
	Int64s
	Uints
	Uint8s
	Uint16s
	Uint32s
	Uint64s
	Float32s
	Float64s
	Strings
	Slice
	Map
)

Variables

This section is empty.

Functions

func Convert

func Convert(src, dest any) error

Convert converts src to dest by "deep" copy.

func Decode

func Decode(l *Buffer, v interface{}) (err error)

Decode todo 补充注释

func DeepCopy

func DeepCopy[T any](v T) (T, error)

DeepCopy returns a "deep" copy of v.

func Encode

func Encode(l *Buffer, v interface{}) (err error)

Encode todo 补充注释

func EqualBuffer

func EqualBuffer(x, y *Buffer) bool

EqualBuffer reports whether x and y are the same [Value]s.

func Ptr

func Ptr[T any](t T) *T

Ptr returns the pointer to the given value.

func PutBuffer

func PutBuffer(l *Buffer)

PutBuffer returns a Buffer to the pool.

func TypeFor

func TypeFor[T any]() reflect.Type

TypeFor returns the reflect.Type that represents the type T.

Types

type Buffer

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

A Buffer is a variable-sized buffer of Value.

func GetBuffer

func GetBuffer() *Buffer

GetBuffer gets a Buffer from the pool.

func (*Buffer) Append

func (b *Buffer) Append(n int)

Append appends n [Value]s to the buffer, growing if needed.

func (*Buffer) Reset

func (b *Buffer) Reset()

Reset resets the buffer to be empty.

type InvalidDecodeError

type InvalidDecodeError struct {
	Type reflect.Type
}

An InvalidDecodeError describes an invalid argument passed to Decode. (The argument to Decode must be a non-nil pointer.)

func (*InvalidDecodeError) Error

func (e *InvalidDecodeError) Error() string

type Kind

type Kind int

A Kind represents the type of value stored in Value.

type Number

type Number interface {
	int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | float32 | float64
}

type Value

type Value struct {
	Data   uintptr
	Length int  // number of children
	First  int  // position of first
	Type   Kind // to prevent overflow
	Name   string
}

Value is used to store a value. When the Type is Bool, Int, Uint, Float, only the Data field is used. When the Type is String, the Data and Length fields are used. When the Type is [Type]s, the Data, Length, and First fields are used.

func (*Value) Bool

func (p *Value) Bool() bool

Bool returns v's underlying value.

func (*Value) Bools

func (p *Value) Bools() []bool

Bools returns v's underlying value.

func (*Value) Float

func (p *Value) Float() float64

Float returns v's underlying value.

func (*Value) Float32s

func (p *Value) Float32s() []float32

Float32s returns v's underlying value.

func (*Value) Float64s

func (p *Value) Float64s() []float64

Float64s returns v's underlying value.

func (*Value) Int

func (p *Value) Int() int64

Int returns v's underlying value.

func (*Value) Int16s

func (p *Value) Int16s() []int16

Int16s returns v's underlying value.

func (*Value) Int32s

func (p *Value) Int32s() []int32

Int32s returns v's underlying value.

func (*Value) Int64s

func (p *Value) Int64s() []int64

Int64s returns v's underlying value.

func (*Value) Int8s

func (p *Value) Int8s() []int8

Int8s returns v's underlying value.

func (*Value) Ints

func (p *Value) Ints() []int

Ints returns v's underlying value.

func (*Value) SetBool

func (p *Value) SetBool(b bool)

SetBool sets v's underlying value.

func (*Value) SetBools

func (p *Value) SetBools(s []bool)

SetBools sets v's underlying value.

func (*Value) SetFloat

func (p *Value) SetFloat(f float64)

SetFloat sets v's underlying value.

func (*Value) SetFloat32s

func (p *Value) SetFloat32s(s []float32)

SetFloat32s sets v's underlying value.

func (*Value) SetFloat64s

func (p *Value) SetFloat64s(s []float64)

SetFloat64s sets v's underlying value.

func (*Value) SetInt

func (p *Value) SetInt(i int64)

SetInt sets v's underlying value.

func (*Value) SetInt16s

func (p *Value) SetInt16s(s []int16)

SetInt16s sets v's underlying value.

func (*Value) SetInt32s

func (p *Value) SetInt32s(s []int32)

SetInt32s sets v's underlying value.

func (*Value) SetInt64s

func (p *Value) SetInt64s(s []int64)

SetInt64s sets v's underlying value.

func (*Value) SetInt8s

func (p *Value) SetInt8s(s []int8)

SetInt8s sets v's underlying value.

func (*Value) SetInts

func (p *Value) SetInts(s []int)

SetInts sets v's underlying value.

func (*Value) SetString

func (p *Value) SetString(s string)

SetString sets v's underlying value.

func (*Value) SetStrings

func (p *Value) SetStrings(s []string)

SetStrings sets v's underlying value.

func (*Value) SetUint

func (p *Value) SetUint(u uint64)

SetUint sets v's underlying value.

func (*Value) SetUint16s

func (p *Value) SetUint16s(s []uint16)

SetUint16s sets v's underlying value.

func (*Value) SetUint32s

func (p *Value) SetUint32s(s []uint32)

SetUint32s sets v's underlying value.

func (*Value) SetUint64s

func (p *Value) SetUint64s(s []uint64)

SetUint64s sets v's underlying value.

func (*Value) SetUint8s

func (p *Value) SetUint8s(s []uint8)

SetUint8s sets v's underlying value.

func (*Value) SetUints

func (p *Value) SetUints(s []uint)

SetUints sets v's underlying value.

func (*Value) String

func (p *Value) String() string

String returns v's underlying value.

func (*Value) Strings

func (p *Value) Strings() []string

Strings returns v's underlying value.

func (*Value) Uint

func (p *Value) Uint() uint64

Uint returns v's underlying value.

func (*Value) Uint16s

func (p *Value) Uint16s() []uint16

Uint16s returns v's underlying value.

func (*Value) Uint32s

func (p *Value) Uint32s() []uint32

Uint32s returns v's underlying value.

func (*Value) Uint64s

func (p *Value) Uint64s() []uint64

Uint64s returns v's underlying value.

func (*Value) Uint8s

func (p *Value) Uint8s() []uint8

Uint8s returns v's underlying value.

func (*Value) Uints

func (p *Value) Uints() []uint

Uints returns v's underlying value.

Jump to

Keyboard shortcuts

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