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

convert

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: May 25, 2021 License: MIT Imports: 10 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`)
)

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 JSONUnmarshalPtr added in v0.6.3

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

JsonUnmarshalPtr unmarshalls []byte as json to pointer, and returns value pointed to

func ProtoUnmarshal added in v0.4.1

func ProtoUnmarshal(bb []byte, messageType proto.Message) (message proto.Message, err error)

ProtoUnmarshal r unmarshalls []byte as proto.Message to pointer, and returns value pointed to

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

Types

type FromByter

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

FromByter interface supports FromBytes func for converting from slice of bytes to target type

type ToByter

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

ToByter interface supports ToBytes func for converting to slice of bytes from source type

Jump to

Keyboard shortcuts

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