codec

package module
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2024 License: MIT Imports: 14 Imported by: 4

Documentation

Overview

Package codec is the codec package for encoding and decoding

Package codec is the codec package for encoding and decoding

Package codec is the codec package for encoding and decoding

Index

Constants

View Source
const (
	ErrUnsupportedDecodeType = errors.String("codec: unsupported decode type")
)
View Source
const (
	ErrUnsupportedEncodeType = errors.String("codec: unsupported encode type")
)

Variables

This section is empty.

Functions

func Decode added in v0.0.5

func Decode(rd io.Reader, obj any, ext string) error

Decode Decodes the given reader with ext name into obj

func DecodeFile

func DecodeFile(name string, obj any) error

DecodeFile Decodes the given file

func DecodeJSONFile

func DecodeJSONFile(name string, obj any) error

DecodeJSONFile Decodes the given JSON file

func DecodeTOMLFile

func DecodeTOMLFile(name string, obj any) error

DecodeTOMLFile Decodes the given TOML file

func DecodeYAMLFile

func DecodeYAMLFile(name string, obj any) error

DecodeYAMLFile Decodes the given YAML file

func Encode added in v0.0.5

func Encode(w io.Writer, obj any, st Type) error

func EncodeFile

func EncodeFile(name string, obj any) error

EncodeFile Encodes the given file

func EncodeJSONFile

func EncodeJSONFile(name string, obj any) error

EncodeJSONFile Encodes the given JSON file

func EncodeTOMLFile

func EncodeTOMLFile(name string, obj any) error

EncodeTOMLFile Encodes the given TOML file

func EncodeYAMLFile

func EncodeYAMLFile(name string, obj any) error

EncodeYAMLFile Encodes the given YAML file

func MustBytes

func MustBytes(data []byte, err error) []byte

MustBytes returns bytes

func MustString

func MustString(data string, err error) string

MustString returns string

func MustToString

func MustToString(data []byte, err error) string

MustToString returns string

func NewSource added in v0.0.12

func NewSource(path string) config.Source

func SourceDecoder added in v0.0.12

func SourceDecoder(src *config.KeyValue, target map[string]interface{}) error

Types

type Decoder added in v0.0.5

type Decoder interface {
	Decode(any) error
}

Decoder interface

type Encoder added in v0.0.5

type Encoder interface {
	Encode(obj any) error
}

Encoder interface

type Type added in v0.0.5

type Type int
const (
	JSON Type = iota
	YAML
	TOML // toml
	UNKNOWN
)

func SupportTypeFromExt added in v0.0.5

func SupportTypeFromExt(ext string) Type

SupportTypeFromExt returns the codec type from the file extension.

func SupportTypeFromString added in v0.0.5

func SupportTypeFromString(s string) Type

SupportTypeFromString returns the codec type from the string.

func (Type) Exts added in v0.0.5

func (s Type) Exts() []string

func (Type) Marshal added in v0.0.12

func (s Type) Marshal(v interface{}) ([]byte, error)

func (Type) Name added in v0.0.12

func (s Type) Name() string

func (Type) NewDecoder added in v0.0.5

func (s Type) NewDecoder(r io.Reader) Decoder

func (Type) NewEncoder added in v0.0.5

func (s Type) NewEncoder(w io.Writer) Encoder

func (Type) String added in v0.0.5

func (s Type) String() string

func (Type) Unmarshal added in v0.0.12

func (s Type) Unmarshal(data []byte, v interface{}) error

Directories

Path Synopsis
Package json provides the json functions based on standard library
Package json provides the json functions based on standard library
Package toml provides the toml functions
Package toml provides the toml functions
Package yaml provides the yaml functions
Package yaml provides the yaml functions

Jump to

Keyboard shortcuts

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