Help us shape the future of Go! Take the 2026 Go Developer Survey

convert

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2018 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package convert for transforming between json serialized []byte and go structs

Index

Constants

View Source
const TypeBool = true
View Source
const TypeInt = 1
View Source
const TypeString = ``

Variables

View Source
var (
	// ErrUnableToConvertNilToStruct - nil cannot be converted to struct
	ErrUnableToConvertNilToStruct = errors.New(`unable to convert nil to [struct,array,slice,ptr]`)
	// ErrUnableToConvertValueToStruct - value  cannot be converted to struct
	ErrUnableToConvertValueToStruct = errors.New(`unable to convert value to [struct,array,slice,ptr]`)
)

Functions

func ArgsToBytes

func ArgsToBytes(iargs ...interface{}) (aa [][]byte, err error)

ArgsToBytes converts func arguments to bytes

func FromBytes

func FromBytes(bb []byte, target interface{}) (result interface{}, err error)

FromBytes converts []byte to target interface

func FromBytesToStruct

func FromBytesToStruct(bb []byte, target interface{}) (result interface{}, err error)

FromBytesToStruct converts []byte to struct,array,slice depending on target type

func FromResponse

func FromResponse(response peer.Response, target interface{}) (result interface{}, err error)

FromResponse converts response.Payload to target

func TimestampToTime

func TimestampToTime(ts *timestamp.Timestamp) time.Time

TimestampToTime converts timestamp to time.Time

func ToBytes

func ToBytes(value interface{}) ([]byte, error)

ToBytes converts inteface{} (string, []byte , struct to ToByter interface to []byte for storing in state

func UnmarshallPtr

func UnmarshallPtr(bb []byte, to interface{}) (result interface{}, err error)

UnmarshallPtr unmarshalls [] byte to pointer, and returns value pointed to

Types

type FromByter

type FromByter interface {
	FromBytes([]byte) (interface{}, error)
}

FromByter interface supports FromBytes func for converting to structure

type ToByter

type ToByter interface {
	ToBytes() ([]byte, error)
}

ToByter interface supports ToBytes func, marshalling to []byte (json.Marshall)

Jump to

Keyboard shortcuts

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