encoding

package
v0.0.0-...-0253919 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2023 License: AGPL-3.0 Imports: 6 Imported by: 0

README

encoding

Package encoding provides common Encoding and associated interfaces for Encoder and Decoder logic.

import go.pitz.tech/lib/encoding

Usage

var (
	// JSON defines a common structure for handling JSON encoding.
	JSON = &Encoding{
		Encoder: func(w io.Writer) Encoder {
			return json.NewEncoder(w)
		},
		Decoder: func(r io.Reader) Decoder {
			return json.NewDecoder(r)
		},
	}

	// MsgPack defines a common structure for handling MsgPack encoding.
	MsgPack = &Encoding{
		Encoder: func(w io.Writer) Encoder {
			return msgpack.NewEncoder(w)
		},
		Decoder: func(r io.Reader) Decoder {
			return msgpack.NewDecoder(r)
		},
	}

	// TOML defines a common structure for handling TOML encoding.
	TOML = &Encoding{
		Encoder: func(w io.Writer) Encoder {
			return toml.NewEncoder(w)
		},
		Decoder: func(r io.Reader) Decoder {
			return toml.NewDecoder(r)
		},
	}

	// YAML defines a common structure for handling YAML encoding.
	YAML = &Encoding{
		Encoder: func(w io.Writer) Encoder {
			return yaml.NewEncoder(w)
		},
		Decoder: func(r io.Reader) Decoder {
			return yaml.NewDecoder(r)
		},
	}

	// XML defines a common structure for handling XML encoding.
	XML = &Encoding{
		Encoder: func(w io.Writer) Encoder {
			return xml.NewEncoder(w)
		},
		Decoder: func(r io.Reader) Decoder {
			return xml.NewDecoder(r)
		},
	}
)
type Decoder
type Decoder interface {
	Decode(v interface{}) error
}

Decoder defines how objects are decoded.

type Encoder
type Encoder interface {
	Encode(v interface{}) error
}

Encoder defines how objects are encoded.

type Encoding
type Encoding struct {
	// Encoder produces a new marshaledEncoder that can write messages to the provided io.Writer.
	Encoder func(w io.Writer) Encoder
	// Decoder produces a new decoder that can read messages from the provided io.Reader.
	Decoder func(r io.Reader) Decoder
}

Encoding defines the encoding of a file.

Documentation

Overview

Package encoding provides common Encoding and associated interfaces for Encoder and Decoder logic.

Index

Constants

This section is empty.

Variables

View Source
var (
	// JSON defines a common structure for handling JSON encoding.
	JSON = &Encoding{
		Encoder: func(w io.Writer) Encoder {
			return json.NewEncoder(w)
		},
		Decoder: func(r io.Reader) Decoder {
			return json.NewDecoder(r)
		},
	}

	// MsgPack defines a common structure for handling MsgPack encoding.
	MsgPack = &Encoding{
		Encoder: func(w io.Writer) Encoder {
			return msgpack.NewEncoder(w)
		},
		Decoder: func(r io.Reader) Decoder {
			return msgpack.NewDecoder(r)
		},
	}

	// TOML defines a common structure for handling TOML encoding.
	TOML = &Encoding{
		Encoder: func(w io.Writer) Encoder {
			return toml.NewEncoder(w)
		},
		Decoder: func(r io.Reader) Decoder {
			return toml.NewDecoder(r)
		},
	}

	// YAML defines a common structure for handling YAML encoding.
	YAML = &Encoding{
		Encoder: func(w io.Writer) Encoder {
			return yaml.NewEncoder(w)
		},
		Decoder: func(r io.Reader) Decoder {
			return yaml.NewDecoder(r)
		},
	}

	// XML defines a common structure for handling XML encoding.
	XML = &Encoding{
		Encoder: func(w io.Writer) Encoder {
			return xml.NewEncoder(w)
		},
		Decoder: func(r io.Reader) Decoder {
			return xml.NewDecoder(r)
		},
	}
)

Functions

This section is empty.

Types

type Decoder

type Decoder interface {
	Decode(v interface{}) error
}

Decoder defines how objects are decoded.

type Encoder

type Encoder interface {
	Encode(v interface{}) error
}

Encoder defines how objects are encoded.

type Encoding

type Encoding struct {
	// Encoder produces a new marshaledEncoder that can write messages to the provided io.Writer.
	Encoder func(w io.Writer) Encoder
	// Decoder produces a new decoder that can read messages from the provided io.Reader.
	Decoder func(r io.Reader) Decoder
}

Encoding defines the encoding of a file.

Jump to

Keyboard shortcuts

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