Categorygithub.com/shamaton/zeroformatter
repositorypackage
1.0.1
Repository: https://github.com/shamaton/zeroformatter.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author

# README

zeroformatter

GoDoc Build Status Coverage Status Releases

golang version zeroformatter

Usage

Installation

go get github.com/shamaton/zeroformatter

How to use

use simply

package main;

import (
  "github.com/shamaton/zeroformatter"
  "log"
)

func main() {
	type Struct struct {
		String string
	}
	h := Struct{String: "zeroformatter"}

	d, err := zeroformatter.Serialize(h)
	if err != nil {
		log.Fatal(err)
	}
	r := Struct{}
	err = zeroformatter.Deserialize(&r, d)
	if err != nil {
		log.Fatal(err)
	}
}

delay

package main;

import (
  "github.com/shamaton/zeroformatter"
  "log"
)

func how_to_use(b []byte) {
	type Struct struct {
		String string
	}
	
	r := Struct{}
	dds, _ := zeroformatter.DelayDeserialize(&r, b)
	
	// by element
	if err := dds.DeserializeByElement(&r.String); err != nil {
		log.Fatal(err)
	}
	
	// or by index
	if err := dds.DeserializeByIndex(0); err != nil {
	  log.Fatal(err)
	}
}

Supported type

Primitive

C#Go
Int16int16
Int32int32, int
Int64int64
UInt16uint16
UInt32uint32, uint
UInt64uint64
Singlefloat32
Doublefloat64
Booleanbool
Byteuint8
SByteint8
TimeSpantime.Duration
DateTimetime.Time
Stringstring

Extension within golang

As these types can not convert with primitive type, I defined parent classes in golang. These are only wrapping. please see codes.

C#Go
Charzeroformatter.Char(rune)
DateTimeOffsetzeroformatter.DateTimeOffset(time.Time)

Array/Slice

C#Go
T[], List[]T, [N]T

Map

C#Go
Dictionary<K, V>map[K]V

Object

C#Go
Structstruct

Not supported

type? is not supported, because golang doen't allow null in primitve types.

License

This library is under the MIT License.