codec

package module
v0.0.0-...-8640e77 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2018 License: Apache-2.0 Imports: 9 Imported by: 7

README

turbinelabs/codec

This project is no longer maintained by Turbine Labs, which has shut down.

Apache 2.0 GoDoc CircleCI Go Report Card codecov

The codec project provides a simple interface for encoding and decoding values with JSON and YAML implementations, along with a means to configure them with a flag.FlagSet.

Requirements

  • Go 1.10.3 or later (previous versions may work, but we don't build or test against them)

Dependencies

The codec project has no external dependencies; the tests depend on our test package. It should always be safe to use HEAD of all master branches of Turbine Labs open source projects together, or to vendor them with the same git tag.

A gomock-based MockCodec is provided.

Additionally, we vendor github.com/ghodss/yaml. This should be considered an opaque implementation detail, see Vendoring for more discussion.

Install

go get -u github.com/turbinelabs/codec/...

Clone/Test

mkdir -p $GOPATH/src/turbinelabs
git clone https://github.com/turbinelabs/codec.git > $GOPATH/src/turbinelabs/codec
go test github.com/turbinelabs/codec/...

Godoc

codec

Versioning

Please see Versioning of Turbine Labs Open Source Projects.

Pull Requests

Patches accepted! Please see Contributing to Turbine Labs Open Source Projects.

Code of Conduct

All Turbine Labs open-sourced projects are released with a Contributor Code of Conduct. By participating in our projects you agree to abide by its terms, which will be carefully enforced.

Documentation

Overview

Package codec provides a simple interface for encoding and decoding values with JSON and YAML implementations, along with a means to configure them with a flag.FlagSet.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeFromString

func DecodeFromString(codec Codec, src string, dest interface{}) error

DecodeFromString uses the given codec to decode the given string into the given destination.

func EncodeToString

func EncodeToString(codec Codec, obj interface{}) (string, error)

EncodeToString uses the given Codec to encode an object to a string

func JSONBytesToYAMLBytes

func JSONBytesToYAMLBytes(data []byte) ([]byte, error)

JSONBytesToYAMLBytes concerts JSON bytes to YAML bytes

func JSONToYAML

func JSONToYAML(in io.Reader, out io.Writer) error

JSONToYAML reads JSON from the given Reader, converts it to YAML, and writes it to the given writer.

func YAMLBytesToJSONBytes

func YAMLBytesToJSONBytes(data []byte) ([]byte, error)

YAMLBytesToJSONBytes concerts YAML bytes to JSON bytes

func YAMLToJSON

func YAMLToJSON(in io.Reader, out io.Writer) error

YAMLToJSON reads YAML from the given Reader, converts it to JSON, and writes it to the given writer.

Types

type Codec

type Codec interface {
	// Encode a value to a writer, based on the --format flag
	Encode(interface{}, io.Writer) error

	// Decode a value from a reader, based on the --format flag
	Decode(io.Reader, interface{}) error
}

Codec allows encoding of an interface{} to an io.Writer and decoding from an io.Reader. This is a useful alternative to the golang binary encoding interfaces--which typically go to/from byte slices--when reading to and from files or file descriptors

func NewJson

func NewJson() Codec

NewJson produces a Codec that reads and writes to JSON. The JSON produced by Encode is prettified for human consumption.

func NewJsonMin

func NewJsonMin() Codec

NewJsonMin returns a Codec that reads and writes to JSON. The JSON written is not indented.

func NewYaml

func NewYaml() Codec

NewYaml produces an Codec that reads and writes YAML

type FromFlags

type FromFlags interface {
	// Validate verifies that all necessary flags are provided
	Validate() error

	// Make produces a new Codec from the provided flags
	Make() Codec

	// Type returns the type of the codec.
	Type() string
}

FromFlags produces an Codec from a flag.FlagSet.

func NewFromFlags

func NewFromFlags(flagset tbnflag.FlagSet) FromFlags

NewFromFlags produces a FromFlags, and installs necessary configuration flags into the provided FlagSet

type MockCodec

type MockCodec struct {
	// contains filtered or unexported fields
}

MockCodec is a mock of Codec interface

func NewMockCodec

func NewMockCodec(ctrl *gomock.Controller) *MockCodec

NewMockCodec creates a new mock instance

func (*MockCodec) Decode

func (m *MockCodec) Decode(arg0 io.Reader, arg1 interface{}) error

Decode mocks base method

func (*MockCodec) EXPECT

func (m *MockCodec) EXPECT() *MockCodecMockRecorder

EXPECT returns an object that allows the caller to indicate expected use

func (*MockCodec) Encode

func (m *MockCodec) Encode(arg0 interface{}, arg1 io.Writer) error

Encode mocks base method

type MockCodecMockRecorder

type MockCodecMockRecorder struct {
	// contains filtered or unexported fields
}

MockCodecMockRecorder is the mock recorder for MockCodec

func (*MockCodecMockRecorder) Decode

func (mr *MockCodecMockRecorder) Decode(arg0, arg1 interface{}) *gomock.Call

Decode indicates an expected call of Decode

func (*MockCodecMockRecorder) Encode

func (mr *MockCodecMockRecorder) Encode(arg0, arg1 interface{}) *gomock.Call

Encode indicates an expected call of Encode

type MockFromFlags

type MockFromFlags struct {
	// contains filtered or unexported fields
}

MockFromFlags is a mock of FromFlags interface

func NewMockFromFlags

func NewMockFromFlags(ctrl *gomock.Controller) *MockFromFlags

NewMockFromFlags creates a new mock instance

func (*MockFromFlags) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockFromFlags) Make

func (m *MockFromFlags) Make() Codec

Make mocks base method

func (*MockFromFlags) Type

func (m *MockFromFlags) Type() string

Type mocks base method

func (*MockFromFlags) Validate

func (m *MockFromFlags) Validate() error

Validate mocks base method

type MockFromFlagsMockRecorder

type MockFromFlagsMockRecorder struct {
	// contains filtered or unexported fields
}

MockFromFlagsMockRecorder is the mock recorder for MockFromFlags

func (*MockFromFlagsMockRecorder) Make

Make indicates an expected call of Make

func (*MockFromFlagsMockRecorder) Type

Type indicates an expected call of Type

func (*MockFromFlagsMockRecorder) Validate

func (mr *MockFromFlagsMockRecorder) Validate() *gomock.Call

Validate indicates an expected call of Validate

Jump to

Keyboard shortcuts

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