encoding

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2019 License: MPL-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package encoding is a wrapper for the core functionality of packages like "encoding/json" and "encoding/gob".

It contains the Codec interface and multiple implementations for encoding Go values to other formats and decode from other formats to Go values. Formats can be JSON, gob etc.

Index

Constants

This section is empty.

Variables

View Source
var (
	// JSON is a JSONcodec that encodes/decodes Go values to/from JSON.
	JSON = JSONcodec{}
	// Gob is a GobCodec that encodes/decodes Go values to/from gob.
	Gob = GobCodec{}
)

Convenience variables

Functions

This section is empty.

Types

type Codec

type Codec interface {
	// Marshal encodes a Go value to a slice of bytes.
	Marshal(v interface{}) ([]byte, error)
	// Unmarshal decodes a slice of bytes into a Go value.
	Unmarshal(data []byte, v interface{}) error
}

Codec encodes/decodes Go values to/from slices of bytes.

type GobCodec

type GobCodec struct{}

GobCodec encodes/decodes Go values to/from gob. You can use encoding.Gob instead of creating an instance of this struct.

func (GobCodec) Marshal

func (c GobCodec) Marshal(v interface{}) ([]byte, error)

Marshal encodes a Go value to gob.

func (GobCodec) Unmarshal

func (c GobCodec) Unmarshal(data []byte, v interface{}) error

Unmarshal decodes a gob value into a Go value.

type JSONcodec

type JSONcodec struct{}

JSONcodec encodes/decodes Go values to/from JSON. You can use encoding.JSON instead of creating an instance of this struct.

func (JSONcodec) Marshal

func (c JSONcodec) Marshal(v interface{}) ([]byte, error)

Marshal encodes a Go value to JSON.

func (JSONcodec) Unmarshal

func (c JSONcodec) Unmarshal(data []byte, v interface{}) error

Unmarshal decodes a JSON value into a Go value.

Jump to

Keyboard shortcuts

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