Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/go-restruct/restruct
Rich binary (de)serialization library for Golang
https://github.com/go-restruct/restruct
Last synced: 2 months ago
JSON representation
Rich binary (de)serialization library for Golang
- Host: GitHub
- URL: https://github.com/go-restruct/restruct
- Owner: go-restruct
- License: isc
- Created: 2015-08-17T12:19:04.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2022-03-31T02:39:25.000Z (almost 3 years ago)
- Last Synced: 2024-08-04T02:09:20.937Z (6 months ago)
- Language: Go
- Homepage: https://restruct.io/
- Size: 161 KB
- Stars: 351
- Watchers: 9
- Forks: 17
- Open Issues: 22
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-bytecode - Restruct: Rich binary de/serialization library for Golang
README
# restruct [![Go](https://github.com/jchv/cleansheets/actions/workflows/go.yml/badge.svg)](https://github.com/jchv/cleansheets/actions/workflows/go.yml) [![codecov.io](http://codecov.io/github/go-restruct/restruct/coverage.svg?branch=master)](http://codecov.io/github/go-restruct/restruct?branch=master) [![godoc.org](http://img.shields.io/badge/godoc-reference-5272B4.svg?style=flat-square)](https://godoc.org/github.com/go-restruct/restruct) [![Go Report Card](https://goreportcard.com/badge/github.com/go-restruct/restruct)](https://goreportcard.com/report/github.com/go-restruct/restruct)
`restruct` is a library for reading and writing binary data in Go. Similar to
lunixbochs `struc` and `encoding/binary`, this library reads data based on the
layout of structures and, like `struc`, based on what is contained in struct
tags.To install Restruct, use the following command:
```
go get github.com/go-restruct/restruct
````restruct` aims to provide a clean, flexible, robust implementation of struct
packing. In the future, through fast-path optimizations and code generation, it
also aims to be quick, but it is currently very slow.`restruct` currently requires Go 1.7+.
## Status
* As of writing, coverage is hovering around 95%, but more thorough testing
is always useful and desirable.
* Unpacking and packing are fully functional.
* More optimizations are probably possible.## Example
```go
package mainimport (
"encoding/binary"
"io/ioutil"
"os""github.com/go-restruct/restruct"
)type Record struct {
Message string `struct:"[128]byte"`
}type Container struct {
Version int `struct:"int32"`
NumRecord int `struct:"int32,sizeof=Records"`
Records []Record
}func main() {
var c Containerfile, _ := os.Open("records")
defer file.Close()
data, _ := ioutil.ReadAll(file)restruct.Unpack(data, binary.LittleEndian, &c)
}
```