codec

package module
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: MIT Imports: 12 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

This section is empty.

Variables

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

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 DecodeFromFile added in v0.0.13

func DecodeFromFile(name string, obj any) error

DecodeFromFile Decodes the given file

func DecodeINIFile added in v0.0.17

func DecodeINIFile(name string, obj any) error

DecodeINIFile Decodes the given INI 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 DecodeXMLFile added in v0.0.17

func DecodeXMLFile(name string, obj any) error

DecodeXMLFile Decodes the given XML 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

Encode Encodes the given object with ext name

func EncodeINIFile added in v0.0.17

func EncodeINIFile(name string, obj any) error

EncodeINIFile Encodes the given INI 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 EncodeToFile added in v0.0.13

func EncodeToFile(name string, obj any) error

EncodeToFile Encodes the given file

func EncodeXMLFile added in v0.0.17

func EncodeXMLFile(name string, obj any) error

EncodeXMLFile Encodes the given XML file

func EncodeYAMLFile

func EncodeYAMLFile(name string, obj any) error

EncodeYAMLFile Encodes the given YAML file

func IsSupported added in v0.3.16

func IsSupported(s string) bool

IsSupported returns true if the codec type is supported.

Types

type Codec added in v0.0.17

type Codec interface {
	Marshal(v interface{}) ([]byte, error)
	Unmarshal(data []byte, v interface{}) error
	Name() string
}

type DecodeReader added in v0.3.17

type DecodeReader interface {
	DecodeReader(io.Reader, any) error
}

func FileDecoder added in v0.3.17

func FileDecoder(name string, hooks ...Hooker) (DecodeReader, error)

type Decoder added in v0.0.5

type Decoder interface {
	Decode(any) error
}

Decoder interface

type EncodeWriter added in v0.3.17

type EncodeWriter interface {
	EncodeWriter(io.Writer, any) error
}

func FileEncoder added in v0.3.17

func FileEncoder(name string, hooks ...Hooker) (EncodeWriter, error)

type Encoder added in v0.0.5

type Encoder interface {
	Encode(obj any) error
}

Encoder interface

type Hooker added in v0.3.17

type Hooker func(data []byte) ([]byte, error)

type Type added in v0.0.5

type Type int
const (
	JSON Type = iota // json
	YAML             // yaml
	TOML             // toml
	XML
	INI
	UNKNOWN // unknown
	TypeMax = UNKNOWN
)

func TypeFromExt added in v0.0.13

func TypeFromExt(ext string) Type

TypeFromExt returns the codec type from the file extension.

func TypeFromPath added in v0.0.25

func TypeFromPath(path string) Type

TypeFromPath returns the codec type from the file path.

func TypeFromString added in v0.0.13

func TypeFromString(s string) Type

TypeFromString returns the codec type from the string.

func (Type) Exts added in v0.0.5

func (s Type) Exts() []string

func (Type) IsSupported added in v0.0.13

func (s Type) IsSupported() bool

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 (i 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