https://github.com/shamaton/zeroformatter
golang version zeroformatter
https://github.com/shamaton/zeroformatter
go golang serializer zeroformatter
Last synced: 10 months ago
JSON representation
golang version zeroformatter
- Host: GitHub
- URL: https://github.com/shamaton/zeroformatter
- Owner: shamaton
- License: mit
- Created: 2016-12-10T13:18:09.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2021-03-16T11:03:48.000Z (about 5 years ago)
- Last Synced: 2024-06-19T01:57:36.507Z (almost 2 years ago)
- Topics: go, golang, serializer, zeroformatter
- Language: Go
- Homepage:
- Size: 46.9 KB
- Stars: 30
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# zeroformatter
[](https://godoc.org/github.com/shamaton/zeroformatter)
[](https://travis-ci.org/shamaton/zeroformatter)
[](https://coveralls.io/github/shamaton/zeroformatter)
[](https://github.com/shamaton/zeroformatter/releases)
golang version [zeroformatter](https://github.com/neuecc/ZeroFormatter)
## Usage
### Installation
```sh
go get github.com/shamaton/zeroformatter
```
### How to use
#### use simply
```go
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
```go
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 | 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.