encoder

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2024 License: MIT Imports: 6 Imported by: 0

README

Encoder Package

A Go package for encoding and decoding messages in various formats: JSON, GOB, YAML, and TOML.

Installation

To install the package, use go get:

go get github.com/dyammarcano/encoder

Usage

To use the package, import it in your code:

import "github.com/dyammarcano/encoder"

type ExampleStruct struct {
    Name string
    Age  int
}

func main() {
    example := ExampleStruct{Name: "Alice", Age: 30}

    encoder.SetEncoderJson()
    encodedData, err := encoder.EncodeMessage(example)
    if err != nil {
        fmt.Println("Error encoding message:", err)
        return
    }

    var decodedExample ExampleStruct
    err = encoder.DecodeMessage(encodedData, &decodedExample)
    if err != nil {
        fmt.Println("Error decoding message:", err)
        return
    }

    fmt.Printf("Decoded Message: %+v\n", decodedExample)
}

Contributing

Feel free to open issues or submit pull requests with improvements.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgements

This project uses the following libraries:

Documentation

Index

Constants

View Source
const (
	ModeGob = iota
	ModeJson
	ModeYaml
	ModeToml
)

Variables

This section is empty.

Functions

func DecodeMessage

func DecodeMessage(data []byte, v any) error

func EncodeMessage

func EncodeMessage(v any) ([]byte, error)

func SetEncoderGob

func SetEncoderGob()

func SetEncoderJson

func SetEncoderJson()

func SetEncoderToml

func SetEncoderToml()

func SetEncoderYaml

func SetEncoderYaml()

Types

This section is empty.

Jump to

Keyboard shortcuts

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