Skip to content
/ go-bipf Public

Go implementation of BIPF format (Binary In-Place Format format)

License

Notifications You must be signed in to change notification settings

ssbc/go-bipf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-bipf CI Go Reference

This a Go implementation of the BIPF format (Binary In-Place Format format) based on github.com/json-iterator/go.

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]}
}

About

Go implementation of BIPF format (Binary In-Place Format format)

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages