tapao

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2022 License: MIT Imports: 4 Imported by: 3

README

tapao

Tapao is a simple wrapper for many serializers. First version of tapao supports MessagePack and JSON.

Usage

When using Marshal or Unmarshal, tapao set the default serializer to MessagePack. You can override it by providing With option.

in := "Hello World"

// default
out, err := tapao.Marshal(in)

// override with JSON serializer
out, err := tapao.Marshal(in, tapao.With(tapao.JSON))

Sometimes, you need to be flexible when unmarshalling. With tapao, you could set the fallback when primary serializer is failed.

var out string

// default to messagepack
err := tapao.Unmarshal(in, &out)

// try using different serializer when failed
err := tapao.Unmarshal(in, &out, tapao.With(tapao.JSON), tapao.FallbackWith(tapao.MessagePack))

Documentation

Index

Constants

View Source
const (
	// JSON :nodoc:
	JSON = SerializerType("json")
	// MessagePack :nodoc:
	MessagePack = SerializerType("msgpack")
	// Protobuf :nodoc:
	Protobuf = SerializerType("protobuf")
)

Variables

This section is empty.

Functions

func FallbackWith

func FallbackWith(s SerializerType) func(*Options)

FallbackWith define type of serializer to use when primary option failed

func Marshal

func Marshal(in interface{}, opts ...func(*Options)) (out []byte, err error)

Marshal with options

func Unmarshal

func Unmarshal(in []byte, out interface{}, opts ...func(*Options)) (err error)

Unmarshal with options

func With

func With(s SerializerType) func(*Options)

With define type of serializer to use

Types

type Options

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

Options :nodoc:

type SerializerType

type SerializerType string

SerializerType :nodoc:

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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