zeroformatter

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2018 License: MIT Imports: 10 Imported by: 0

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
Int16 int16
Int32 int32, int
Int64 int64
UInt16 uint16
UInt32 uint32, uint
UInt64 uint64
Single float32
Double float64
Boolean bool
Byte uint8
SByte int8
TimeSpan time.Duration
DateTime time.Time
String string
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
Char zeroformatter.Char(rune)
DateTimeOffset zeroformatter.DateTimeOffset(time.Time)
Array/Slice
C# Go
T[], List []T, [N]T
Map
C# Go
Dictionary<K, V> map[K]V
Object
C# Go
Struct struct

Not supported

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

License

This library is under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DelayDeserialize

func DelayDeserialize(holder interface{}, data []byte) (*delayDeserializer, error)

DelayDeserialize can delay execution processes which analayze byte data and set into holder. If you do not want to deserialize at once, please use this.

func Deserialize

func Deserialize(holder interface{}, data []byte) error

Deserialize analyzes byte data and set into holder.

func Serialize

func Serialize(holder interface{}) ([]byte, error)

Serialize analyzes holder and converts to byte datas.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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