Documentation ¶
Overview ¶
Package serialize for transforming between json serialized []byte and go structs
Index ¶
- Constants
- Variables
- func ArgsToBytes(iargs []interface{}, toBytesConverter ToBytesConverter) (aa [][]byte, err error)
- func BinaryProtoMarshal(entry proto.Message) ([]byte, error)
- func BinaryProtoUnmarshal(bb []byte, messageType proto.Message) (message proto.Message, err error)
- func FromBytesToStruct(bb []byte, target interface{}) (result interface{}, err error)
- func JSONProtoMarshal(entry proto.Message, mo *protojson.MarshalOptions) ([]byte, error)
- func JSONProtoUnmarshal(json []byte, messageType proto.Message) (message proto.Message, err error)
- func JSONUnmarshalPtr(bb []byte, to interface{}) (result interface{}, err error)
- type BinaryProtoSerializer
- type BinarySerializer
- type FromByter
- type FromBytesConverter
- type GenericSerializer
- type JSONProtoSerializer
- type JSONSerializer
- type ProtoSerializer
- type Serializable
- type Serializer
- type StringSerializer
- type SuppportedType
- type TargetType
- type ToByter
- type ToBytesConverter
Constants ¶
const TypeBool = true
const TypeInt = 1
const TypeString = ``
Variables ¶
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`) )
var ( // AnyType defines that serializer supports any supportable variable type AnyType SuppportedType = `any` // StructType defines that serializer supports struct type StructType SuppportedType = `struct` ProtoType SuppportedType = `proto` ScalarType SuppportedType = `scalar` DefaultTarget TargetType = `default` PreferJSON TargetType = `json` DefaultSerializer = &GenericSerializer{ Supports: []SuppportedType{AnyType}, Target: DefaultTarget, UseProtoNames: true, } PreferJSONSerializer = &GenericSerializer{ Supports: []SuppportedType{AnyType}, Target: PreferJSON, UseProtoNames: true, } KeySerializer = &StringSerializer{} ErrOnlyStringSupported = errors.New(`only string supported`) )
var (
ErrToBytesConverterIsNil = errors.New(`to bytes converter is nil`)
)
Functions ¶
func ArgsToBytes ¶
func ArgsToBytes(iargs []interface{}, toBytesConverter ToBytesConverter) (aa [][]byte, err error)
ArgsToBytes converts func arguments to bytes
func BinaryProtoUnmarshal ¶
BinaryProtoUnmarshal r unmarshalls []byte as proto.Message to pointer, and returns value pointed to
func FromBytesToStruct ¶
FromBytesToStruct converts []byte to struct,array,slice depending on target type
func JSONProtoMarshal ¶
func JSONProtoUnmarshal ¶
func JSONUnmarshalPtr ¶
JSONUnmarshalPtr unmarshalls []byte as json to pointer, and returns value pointed to
Types ¶
type BinaryProtoSerializer ¶
type BinaryProtoSerializer struct { }
type BinarySerializer ¶
type BinarySerializer struct { }
type FromByter ¶
FromByter interface supports FromBytes func for converting from slice of bytes to some defined target type
type FromBytesConverter ¶
type FromBytesConverter interface {
FromBytesTo(from []byte, target interface{}) (interface{}, error)
}
FromBytesConverter interface supports FromBytesConverter func for converting from slice of bytes to target type
type GenericSerializer ¶
type GenericSerializer struct { Supports []SuppportedType Target TargetType UseProtoNames bool // to use proto field name instead of lowerCamelCase name in JSON field names }
func (*GenericSerializer) FromBytesTo ¶
func (g *GenericSerializer) FromBytesTo(serialized []byte, target interface{}) (interface{}, error)
func (*GenericSerializer) ToBytesFrom ¶
func (g *GenericSerializer) ToBytesFrom(entry interface{}) ([]byte, error)
type JSONProtoSerializer ¶
type JSONProtoSerializer struct {
UseProtoNames bool // to use proto field name instead of lowerCamelCase name in JSON field names
}
type JSONSerializer ¶
type JSONSerializer struct { }
type ProtoSerializer ¶
type Serializable ¶
type Serializable interface {
ToBytes(ToBytesConverter) ([]byte, error)
}
type Serializer ¶
type Serializer interface { ToBytesConverter FromBytesConverter }
Serializer generic interface for serializing
type StringSerializer ¶
type StringSerializer struct { }
func (*StringSerializer) FromBytesTo ¶
func (g *StringSerializer) FromBytesTo(serialized []byte, target interface{}) (interface{}, error)
func (*StringSerializer) ToBytesFrom ¶
func (g *StringSerializer) ToBytesFrom(entry interface{}) ([]byte, error)
type SuppportedType ¶
type SuppportedType string
type TargetType ¶
type TargetType string
type ToByter ¶
ToByter interface supports ToBytes func for converting to slice of bytes from source type
type ToBytesConverter ¶
ToBytesConverter supports ToBytesConverter func converting from some interface to bytes