reflectutil

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

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

Go to latest
Published: Oct 26, 2019 License: MIT Imports: 7 Imported by: 0

README

reflectutil

Documentation

Overview

Package reflectutil implements reflect2 utility functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncoderOf

func EncoderOf(encoder Encoder) interface{}

func ToBindingName

func ToBindingName(fieldName string, tagName string) string

func TypeOf

func TypeOf(obj interface{}) reflect2.Type

Types

type DereferenceEncoder

type DereferenceEncoder struct {
	Encoder Encoder
}

func (*DereferenceEncoder) Encode

func (r *DereferenceEncoder) Encode(ptr unsafe.Pointer, writer interface{})

type Encoder

type Encoder interface {
	Encode(ptr unsafe.Pointer, writer interface{})
}

Encoder is an internal type registered to cache as needed.

type FieldBinding

type FieldBinding struct {
	Field   reflect2.StructField
	Name    string
	Encoder Encoder
	// contains filtered or unexported fields
}

FieldBinding describe how should we encode/decode the struct field

type GetEncoder

type GetEncoder func(reflect2.Type, reflect2.StructField) Encoder

type Option

type Option struct {
	TagKey          string
	TaggedFieldOnly bool
}

Option customize how the API should behave. The API is created from Option by Froze.

func (Option) Tag

func (r Option) Tag() string

type StructDescriptor

type StructDescriptor struct {
	Type   *reflect2.UnsafeStructType
	Fields []*FieldBinding
}

StructDescriptor describe how should we encode/decode the struct

func DescribeStruct

func DescribeStruct(typ *reflect2.UnsafeStructType, getEncoder GetEncoder, opt *Option) *StructDescriptor

func (*StructDescriptor) GetFieldBinding

func (r *StructDescriptor) GetFieldBinding(fieldName string) *FieldBinding

GetFieldBinding get one field from the descriptor by its name. Can not use map here to keep field orders.

type StructFieldEncoder

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

func (*StructFieldEncoder) Encode

func (r *StructFieldEncoder) Encode(ptr unsafe.Pointer, writer interface{})

func (*StructFieldEncoder) Encoder

func (r *StructFieldEncoder) Encoder() Encoder

Directories

Path Synopsis
ext

Jump to

Keyboard shortcuts

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