encode

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package encode provides a flexible way to encode and decode Go objects.

Example
var enc Encoder
var err error
enc = GNjson{Pretty: true}
ary1 := []int{1, 2, 3}
jsonRes, err := enc.Encode(ary1)
if err != nil {
	panic(err)
}
var ary2 []int
err = enc.Decode(jsonRes, &ary2)
if err != nil {
	panic(err)
}
fmt.Println(ary1[0] == ary2[0])
Output:

true

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Encoder

type Encoder interface {
	//Encode takes a Go object and converts it into bytes
	Encode(input interface{}) ([]byte, error)
	// Decode takes an input of bytes and decodes it into Go object.
	Decode(input []byte, output interface{}) error
}

Encoder interface allows to switch between different encoding types.

type GNgob

type GNgob struct{}

func (GNgob) Decode

func (e GNgob) Decode(input []byte, output interface{}) error

func (GNgob) Encode

func (e GNgob) Encode(input interface{}) ([]byte, error)

type GNjson

type GNjson struct {
	Pretty bool
}

func (GNjson) Decode

func (e GNjson) Decode(input []byte, output interface{}) error

func (GNjson) Encode

func (e GNjson) Encode(input interface{}) ([]byte, error)

func (GNjson) Output

func (e GNjson) Output(input interface{}, f format.Format) string

Jump to

Keyboard shortcuts

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