https://github.com/ssbc/go-bipf
Go implementation of BIPF format (Binary In-Place Format format)
https://github.com/ssbc/go-bipf
Last synced: 9 months ago
JSON representation
Go implementation of BIPF format (Binary In-Place Format format)
- Host: GitHub
- URL: https://github.com/ssbc/go-bipf
- Owner: ssbc
- License: mit
- Created: 2023-03-15T21:18:06.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-03-17T00:36:00.000Z (over 3 years ago)
- Last Synced: 2025-09-17T00:54:16.855Z (9 months ago)
- Language: Go
- Homepage: https://github.com/ssbc/bipf-spec
- Size: 65.4 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-bipf [](https://github.com/boreq/go-bipf/actions/workflows/ci.yml) [](https://pkg.go.dev/github.com/boreq/go-bipf)
This a Go implementation of the [BIPF format][spec] (Binary In-Place Format
format) based on [`github.com/json-iterator/go`][jsoniter].
## Examples
### Marshal
import (
"encoding/hex"
"fmt"
"github.com/boreq/go-bipf"
)
func ExampleMarshal() {
type ColorGroup struct {
ID int
Name string
Colors []string
}
group := ColorGroup{
ID: 1,
Name: "Reds",
Colors: []string{"Crimson", "Red", "Ruby", "Maroon"},
}
b, err := bipf.Marshal(group)
if err != nil {
fmt.Println("error:", err)
}
fmt.Println(hex.EncodeToString(b))
// Output:
// 9d031049442201000000204e616d65205265647330436f6c6f7273c401384372696d736f6e185265642052756279304d61726f6f6e
}
### Unmarshal
import (
"encoding/hex"
"fmt"
"github.com/boreq/go-bipf"
)
func ExampleUnmarshal() {
bipfBlob, err := hex.DecodeString("9d031049442201000000204e616d65205265647330436f6c6f7273c401384372696d736f6e185265642052756279304d61726f6f6e")
if err != nil {
fmt.Println("error:", err)
}
type ColorGroup struct {
ID int
Name string
Colors []string
}
var group ColorGroup
err = bipf.Unmarshal(bipfBlob, &group)
if err != nil {
fmt.Println("error:", err)
}
fmt.Printf("%+v", group)
// Output:
// {ID:1 Name:Reds Colors:[Crimson Red Ruby Maroon]}
}
[spec]: https://github.com/ssbc/bipf-spec
[jsoniter]: github.com/json-iterator/go