encodingtools

package module
v0.0.0-...-82af808 Latest Latest
Warning

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

Go to latest
Published: May 10, 2021 License: MIT Imports: 9 Imported by: 2

README

Golang Encoding format tools

Coverage Status Codacy Badge Golang package providing some helpers to convert structures from/to YAML, JSON, Protocol Buffer format.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bytes2Object

func Bytes2Object(obj proto.Message, data []byte, intype EncodingType) error

Bytes2Object Convert object which has proto, json, yaml interface to data

func JSON2Yaml

func JSON2Yaml(buf []byte) ([]byte, error)

JSON2Yaml Convert any JSON formatted data-block to YAML data-block

func Load

func Load(filename string, obj proto.Message) error

Load : this function load a file and unmarshall file into obj. File can have different formats depending on its extension .json -> json file .yaml, .yml -> yaml file any -> binary protobuf encoded

func Objet2Bytes

func Objet2Bytes(obj proto.Message, outtype EncodingType) ([]byte, error)

Objet2Bytes marshal an object from type proto.Message to byte array depending on EncodingType code

func Yaml2JSON

func Yaml2JSON(buf []byte) ([]byte, error)

Yaml2JSON : Convert Yaml byte array to Json (credits : stackoverflow ;) )

Types

type EncodingType

type EncodingType int

EncodingType format code

const (
	// EncodingTypeJSON : JSON format
	EncodingTypeJSON EncodingType = iota

	// EncodingTypeYaml : Yaml format
	EncodingTypeYaml

	// EncodingTypeBinaryPB : Protocol buffer binary encoded format
	EncodingTypeBinaryPB
)

func EncodingTypeFromString

func EncodingTypeFromString(str string) EncodingType

EncodingTypeFromString Convert string JSON, Yaml, or any to EncodingType Code

Jump to

Keyboard shortcuts

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